28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { createMistral } from "@ai-sdk/mistral"
|
|
import { expect, test } from "bun:test"
|
|
|
|
test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
|
|
let body: Record<string, unknown> | undefined
|
|
const mockFetch = Object.assign(
|
|
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
body = JSON.parse(String(init?.body))
|
|
return Response.json({
|
|
id: "response-1",
|
|
created: 0,
|
|
model: "mistral-large-latest",
|
|
object: "chat.completion",
|
|
choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }],
|
|
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
|
})
|
|
},
|
|
{ preconnect: fetch.preconnect },
|
|
)
|
|
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest")
|
|
|
|
await model.doGenerate({
|
|
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
|
|
providerOptions: { mistral: { promptCacheKey: "session-123" } },
|
|
})
|
|
|
|
expect(body?.prompt_cache_key).toBe("session-123")
|
|
})
|