fix: 图片附件时llmContent多余换行 + AgnesAdapter加图片诊断日志
This commit is contained in:
@@ -18,6 +18,7 @@ import type { MetonaRequest, MetonaResponse, MetonaStreamEvent } from '../types'
|
||||
import { MetonaFinishReason } from '../types';
|
||||
import { buildOpenAICompatibleMessages, buildOpenAICompatibleTools } from './shared/openai-format';
|
||||
import { parseSSEStream, parseOpenAICompatibleResponse } from './shared/sse-stream';
|
||||
import log from 'electron-log';
|
||||
|
||||
export class AgnesAdapter extends BaseAdapter {
|
||||
override readonly provider: string = 'agnes';
|
||||
@@ -109,17 +110,21 @@ export class AgnesAdapter extends BaseAdapter {
|
||||
// === Agnes 多模态:将 images 转为 OpenAI content 数组 ===
|
||||
// buildOpenAICompatibleMessages 不处理图片(各 Provider 自行处理)
|
||||
const nonSystemMsgs = request.messages.filter((m) => m.role !== 'system');
|
||||
let imageCount = 0;
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
// messages[0] 是 system,非 system 消息从 messages[1] 开始
|
||||
if (i === 0) continue;
|
||||
const origMsg = nonSystemMsgs[i - 1];
|
||||
if (!origMsg?.images?.length) continue;
|
||||
|
||||
imageCount += origMsg.images.length;
|
||||
|
||||
const contentParts: Array<Record<string, unknown>> = [];
|
||||
if (origMsg.content) {
|
||||
contentParts.push({ type: 'text', text: origMsg.content });
|
||||
}
|
||||
for (const img of origMsg.images) {
|
||||
const isDataUrl = img.url.startsWith('data:');
|
||||
contentParts.push({
|
||||
type: 'image_url',
|
||||
image_url: { url: img.url },
|
||||
@@ -128,6 +133,11 @@ export class AgnesAdapter extends BaseAdapter {
|
||||
messages[i].content = contentParts;
|
||||
}
|
||||
|
||||
if (imageCount > 0) {
|
||||
const firstUrl = request.messages.find(m => m.images?.length)?.images?.[0]?.url ?? '';
|
||||
log.info(`[Agnes] Processing ${imageCount} image(s), first URL prefix: ${firstUrl.slice(0, 50)}`);
|
||||
}
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
model: this.config.defaultModel,
|
||||
messages,
|
||||
|
||||
@@ -250,7 +250,9 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
context: base64Content,
|
||||
}));
|
||||
}
|
||||
llmContent = parts.join('\n') + (content ? '\n\n' + content : '');
|
||||
llmContent = parts.length > 0
|
||||
? parts.join('\n') + (content ? '\n\n' + content : '')
|
||||
: content;
|
||||
}
|
||||
|
||||
const messageWithImages = {
|
||||
|
||||
Reference in New Issue
Block a user