@@ -884,6 +884,59 @@ describe("describeImageWithModel", () => {
|
884 | 884 | ]); |
885 | 885 | }); |
886 | 886 | |
| 887 | +it("places DashScope image prompts in user content before images", async () => { |
| 888 | +discoverModelsMock.mockReturnValue({ |
| 889 | +find: vi.fn(() => ({ |
| 890 | +api: "openai-completions", |
| 891 | +provider: "qwen", |
| 892 | +id: "qwen-vl-max-latest", |
| 893 | +input: ["text", "image"], |
| 894 | +baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1", |
| 895 | +})), |
| 896 | +}); |
| 897 | +completeMock.mockResolvedValue({ |
| 898 | +role: "assistant", |
| 899 | +api: "openai-completions", |
| 900 | +provider: "qwen", |
| 901 | +model: "qwen-vl-max-latest", |
| 902 | +stopReason: "stop", |
| 903 | +timestamp: Date.now(), |
| 904 | +content: [{ type: "text", text: "dashscope ok" }], |
| 905 | +}); |
| 906 | + |
| 907 | +const result = await describeImageWithModel({ |
| 908 | +cfg: {}, |
| 909 | +agentDir: "/tmp/openclaw-agent", |
| 910 | +provider: "qwen", |
| 911 | +model: "qwen-vl-max-latest", |
| 912 | +buffer: Buffer.from("png-bytes"), |
| 913 | +fileName: "image.png", |
| 914 | +mime: "image/png", |
| 915 | +prompt: "Describe the image.", |
| 916 | +timeoutMs: 1000, |
| 917 | +}); |
| 918 | + |
| 919 | +expect(result).toEqual({ |
| 920 | +text: "dashscope ok", |
| 921 | +model: "qwen-vl-max-latest", |
| 922 | +}); |
| 923 | +const firstCall = requireFirstMockCall(completeMock, "DashScope image completion"); |
| 924 | +const [, context] = firstCall; |
| 925 | +expect(context.systemPrompt).toBeUndefined(); |
| 926 | +const userMessage = context.messages[0]; |
| 927 | +if (!userMessage) { |
| 928 | +throw new Error("expected DashScope image completion user message"); |
| 929 | +} |
| 930 | +expect(userMessage.content).toEqual([ |
| 931 | +{ type: "text", text: "Describe the image." }, |
| 932 | +{ |
| 933 | +type: "image", |
| 934 | +data: Buffer.from("png-bytes").toString("base64"), |
| 935 | +mimeType: "image/png", |
| 936 | +}, |
| 937 | +]); |
| 938 | +}); |
| 939 | + |
887 | 940 | it.each([ |
888 | 941 | { |
889 | 942 | name: "direct OpenAI Responses baseUrl", |
|