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