From ea16ea1ecea2519433032a3ea9be4694169456d1 Mon Sep 17 00:00:00 2001 From: xiajiadi <187861803+xiajiadi@users.noreply.github.com> Date: Fri, 4 Sep 2026 17:07:04 +0800 Subject: [PATCH] test: cover DeepSeek Vision image payload --- tests/unit/deepseek-vision.test.ts | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/unit/deepseek-vision.test.ts diff --git a/tests/unit/deepseek-vision.test.ts b/tests/unit/deepseek-vision.test.ts new file mode 100644 index 00000000..7a439bc2 --- /dev/null +++ b/tests/unit/deepseek-vision.test.ts @@ -0,0 +1,90 @@ +import { createDeepSeek } from "@ai-sdk/deepseek" +import { generateText } from "ai" +import { describe, expect, it } from "vitest" + +describe("DeepSeek V4 Vision image input", () => { + it("includes image content in the chat completion request", async () => { + let requestBody: + | { + messages: Array<{ + role: string + content: string | Array> + }> + } + | undefined + + const provider = createDeepSeek({ + apiKey: "test-key", + baseURL: "https://example.test", + fetch: async (_input, init) => { + const body = init?.body + const rawBody = + typeof body === "string" + ? body + : new TextDecoder().decode(body as Uint8Array) + requestBody = JSON.parse(rawBody) + + return new Response( + JSON.stringify({ + id: "test-response", + object: "chat.completion", + created: 1, + model: "deepseek-v4-flash-vision-exp", + choices: [ + { + index: 0, + message: { role: "assistant", content: "ok" }, + finish_reason: "stop", + }, + ], + usage: { + prompt_tokens: 1, + completion_tokens: 1, + total_tokens: 2, + }, + }), + { + status: 200, + headers: { "content-type": "application/json" }, + }, + ) + }, + }) + + await generateText({ + model: provider("deepseek-v4-flash-vision-exp"), + messages: [ + { + role: "user", + content: [ + { type: "text", text: "Describe this image." }, + { + type: "image", + image: "data:image/png;base64,aGVsbG8=", + mediaType: "image/png", + }, + ], + }, + ], + }) + + if (requestBody === undefined) { + throw new Error("DeepSeek request was not captured") + } + + const userMessage = requestBody.messages.find( + (message) => message.role === "user", + ) + expect(userMessage?.content).toEqual( + expect.arrayContaining([ + { type: "text", text: "Describe this image." }, + { + type: "image_url", + image_url: { + url: "data:image/png;base64,aGVsbG8=", + }, + }, + ]), + ) + }) +})