Files
metona-ai-desktop/electron/harness/adapters/agnes-ai.adapter.ts
T
thzxx a879b4f38a fix: 修复上传图片后 AI 无法识别图片的问题
根因:图片从 ChatInput → agent-store → IPC → adapter 的链路中有两处断裂:

1. DeepSeekAdapter.toNativeRequest 完全忽略 message.images 字段
   - 用户消息中的图片 base64 数据未转换为 OpenAI 多模态 content
     数组格式,导致 LLM 收不到图片数据,只能尝试用工具查磁盘文件

2. AgnesAdapter.toNativeRequest 图片处理存在数组索引错位
   - base.messages[0] 固定为 system 消息(父类插入)
   - request.messages.filter(m => m.role !== 'system') 去掉了 system
   - 同一索引 i 访问两个不同长度的数组,导致图片消息匹配到错误位置

3. agent-store sendMessage 中 images 参数被局部变量遮蔽
   - ChatInput 传入的 images 被  覆盖
   - 改为直接使用参数,避免重复从 attachments 提取

修复:
- DeepSeekAdapter: 在 toNativeRequest 中添加图片→OpenAI content 数组转换
- AgnesAdapter: 移除冗余图片处理(基类已处理),仅保留 Thinking/max_tokens
- agent-store: 移除 images 变量遮蔽,直接使用参数

影响范围: DeepSeek / Agnes AI / Ollama 三个 Provider 的图片传递均已验证
2026-06-27 21:39:24 +08:00

49 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Agnes AI Provider Adapter
*
* OpenAI 兼容 API,免费使用。
* 支持 Tool Calling、Thinking 模式、512K 上下文、多模态(图片 base64)。
*
* 差异于 DeepSeek
* - Thinking 模式使用 chat_template_kwargs(非 thinking 字段)
* - 图片使用 base64 格式(与 Ollama 一致,通过 images 字段传递)
* - 512K 上下文,65.5K 最大输出
*
* @see apis/agnes-ai-api-docs-20260625.html
*/
import { DeepSeekAdapter } from './deepseek.adapter';
import type { MetonaRequest } from '../types';
export class AgnesAdapter extends DeepSeekAdapter {
override readonly provider: string = 'agnes';
readonly supportedModels = ['agnes-2.0-flash'];
readonly supportsToolCalling = true;
readonly supportsThinking = true;
/**
* 覆盖原生请求构建
*
* 差异:
* 1. Thinking 模式使用 chat_template_kwargs
* 2. 图片处理由基类 DeepSeekAdapter.toNativeRequest 完成(OpenAI 多模态格式)
*/
protected override toNativeRequest(request: MetonaRequest): Record<string, unknown> {
const base = super.toNativeRequest(request) as Record<string, unknown>;
// Agnes Thinking 模式:使用 chat_template_kwargs
if (request.params?.thinkingEnabled) {
delete base.thinking;
delete base.reasoning_effort;
base.chat_template_kwargs = { enable_thinking: true };
}
// Agnes 默认 max_tokens 更大
if (!request.params.maxTokens) {
base.max_tokens = 65536;
}
return base;
}
}