fix: 修复Claude内容处理和iFlow模型验证问题
- 修复ClaudeConverter中字符串内容处理逻辑,确保字符串能正确转换为OpenAI格式 - 移除claude-kiro.js中重复的内容处理代码,避免重复计算tokens - 修复iFlow模型验证逻辑,当模型不存在时使用默认模型 - 优化插件状态提示信息,使用通用的"已启用/已禁用"翻译
This commit is contained in:
parent
f8de8aad67
commit
517120a000
4 changed files with 31 additions and 12 deletions
|
|
@ -676,7 +676,17 @@ export class ClaudeConverter extends BaseConverter {
|
|||
* 处理Claude内容到OpenAI格式
|
||||
*/
|
||||
processClaudeContentToOpenAIContent(content) {
|
||||
if (!content || !Array.isArray(content)) return [];
|
||||
if (!content) return [];
|
||||
|
||||
// 如果是字符串,直接转换为 OpenAI 的文本块格式
|
||||
if (typeof content === 'string') {
|
||||
return [{
|
||||
type: 'text',
|
||||
text: content
|
||||
}];
|
||||
}
|
||||
|
||||
if (!Array.isArray(content)) return [];
|
||||
|
||||
const contentArray = [];
|
||||
|
||||
|
|
@ -735,7 +745,11 @@ export class ClaudeConverter extends BaseConverter {
|
|||
* 处理Claude响应内容
|
||||
*/
|
||||
processClaudeResponseContent(content) {
|
||||
if (!content || !Array.isArray(content)) return '';
|
||||
if (!content) return '';
|
||||
|
||||
if (typeof content === 'string') return content;
|
||||
|
||||
if (!Array.isArray(content)) return '';
|
||||
|
||||
const contentArray = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -2806,12 +2806,6 @@ async saveCredentialsToFile(filePath, newData) {
|
|||
outputTokens += this.countTextTokens(tc.function.arguments);
|
||||
}
|
||||
stopReason = "tool_use"; // Set stop_reason to "tool_use" when toolCalls exist
|
||||
} else if (content) {
|
||||
contentArray.push({
|
||||
type: "text",
|
||||
text: content
|
||||
});
|
||||
outputTokens += this.countTextTokens(content);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -437,16 +437,25 @@ function ensureToolsArray(body) {
|
|||
* @returns {Object} - 处理后的请求体
|
||||
*/
|
||||
function preprocessRequestBody(body, model) {
|
||||
// 确保模型名称有效,如果不存在则使用默认模型
|
||||
let targetModel = model;
|
||||
if (Array.isArray(IFLOW_MODELS) && IFLOW_MODELS.length > 0) {
|
||||
if (!IFLOW_MODELS.includes(model)) {
|
||||
logger.warn(`[iFlow] Model "${model}" not found in IFLOW_MODELS, defaulting to "${IFLOW_MODELS[0]}"`);
|
||||
targetModel = IFLOW_MODELS[0];
|
||||
}
|
||||
}
|
||||
|
||||
let processedBody = { ...body };
|
||||
|
||||
// 确保模型名称正确
|
||||
processedBody.model = model;
|
||||
processedBody.model = targetModel;
|
||||
|
||||
// 应用 iFlow thinking 配置
|
||||
processedBody = applyIFlowThinkingConfig(processedBody, model);
|
||||
processedBody = applyIFlowThinkingConfig(processedBody, targetModel);
|
||||
|
||||
// 保留 reasoning_content
|
||||
processedBody = preserveReasoningContentInMessages(processedBody, model);
|
||||
processedBody = preserveReasoningContentInMessages(processedBody, targetModel);
|
||||
|
||||
// 确保 tools 数组
|
||||
processedBody = ensureToolsArray(processedBody);
|
||||
|
|
|
|||
|
|
@ -609,7 +609,7 @@ const translations = {
|
|||
'plugins.badge.middleware.title': '包含中间件',
|
||||
'plugins.badge.routes.title': '包含路由',
|
||||
'plugins.badge.hooks.title': '包含钩子',
|
||||
'plugins.toggle.success': '插件 {name} 已{status}',
|
||||
'plugins.toggle.success': '插件 {name} {status}',
|
||||
'plugins.toggle.failed': '切换插件状态失败',
|
||||
'plugins.load.failed': '加载插件列表失败',
|
||||
'plugins.restart.required': '更改已保存',
|
||||
|
|
@ -776,6 +776,8 @@ const translations = {
|
|||
'common.confirm': '确定',
|
||||
'common.cancel': '取消',
|
||||
'common.success': '成功',
|
||||
'common.enabled': '已启用',
|
||||
'common.disabled': '已禁用',
|
||||
'common.error': '错误',
|
||||
'common.warning': '警告',
|
||||
'common.info': '信息',
|
||||
|
|
|
|||
Loading…
Reference in a new issue