fix: aggregate WeChat multi-image batches
This commit is contained in:
@@ -83,6 +83,42 @@ test('buildVisionPayload marks one billable image analysis when vision succeeds'
|
||||
);
|
||||
});
|
||||
|
||||
test('buildVisionPayload sends all current-turn images to Qwen in order', async () => {
|
||||
const imageUrls = [
|
||||
'https://m.tkmind.cn/MindSpace/user-1/public/wechat-mp/first.jpg',
|
||||
'https://m.tkmind.cn/MindSpace/user-1/public/wechat-mp/second.jpg',
|
||||
];
|
||||
let analyzedImages = [];
|
||||
const result = await buildVisionPayload({
|
||||
userId: 'user-1',
|
||||
publishLayout: { publicUrl: 'https://m.tkmind.cn/MindSpace/user-1' },
|
||||
userMessage: {
|
||||
content: [{ type: 'text', text: '请结合两张图片生成页面' }],
|
||||
metadata: { imageUrls },
|
||||
},
|
||||
fetchImpl: async () =>
|
||||
new Response(Buffer.from('fake-image'), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'image/jpeg' },
|
||||
}),
|
||||
llmProviderService: {
|
||||
analyzeImagesWithVision: async (images) => {
|
||||
analyzedImages = images;
|
||||
return '第一张是宝塔,第二张是晚霞。';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(analyzedImages.length, 2);
|
||||
assert.deepEqual(analyzedImages.map((item) => item.rawUrl), imageUrls);
|
||||
assert.deepEqual(result?.userMessage?.metadata?.imageUrls, [
|
||||
'/MindSpace/user-1/public/wechat-mp/first.jpg',
|
||||
'/MindSpace/user-1/public/wechat-mp/second.jpg',
|
||||
]);
|
||||
assert.match(result?.userMessage?.content?.[0]?.text ?? '', /本轮用户仅上传 2 张图片/);
|
||||
assert.match(result?.userMessage?.content?.[0]?.text ?? '', /图片2/);
|
||||
});
|
||||
|
||||
test('buildVisionPayload does not mark billable usage when vision analysis fails', async () => {
|
||||
const result = await buildVisionPayload({
|
||||
userId: 'user-1',
|
||||
|
||||
Reference in New Issue
Block a user