fix: model_name prompt var always use default model (#7178)

* fix: model_name prompt var always use default mode

* fix: incorrect model name
This commit is contained in:
Wang Jiyuan 2025-06-14 13:35:32 +08:00 committed by GitHub
parent 2a0484ede2
commit e4e4dcbd1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 8 deletions

View File

@ -453,7 +453,7 @@ export class AnthropicAPIClient extends BaseApiClient<
}) })
if (this.useSystemPromptForTools) { if (this.useSystemPromptForTools) {
systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools) systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools, assistant)
} }
const systemMessage: TextBlockParam | undefined = systemPrompt const systemMessage: TextBlockParam | undefined = systemPrompt

View File

@ -452,7 +452,7 @@ export class GeminiAPIClient extends BaseApiClient<
}) })
if (this.useSystemPromptForTools) { if (this.useSystemPromptForTools) {
systemInstruction = await buildSystemPrompt(assistant.prompt || '', mcpTools) systemInstruction = await buildSystemPrompt(assistant.prompt || '', mcpTools, assistant)
} }
let messageContents: Content let messageContents: Content

View File

@ -420,7 +420,7 @@ export class OpenAIAPIClient extends OpenAIBaseClient<
}) })
if (this.useSystemPromptForTools) { if (this.useSystemPromptForTools) {
systemMessage.content = await buildSystemPrompt(systemMessage.content || '', mcpTools) systemMessage.content = await buildSystemPrompt(systemMessage.content || '', mcpTools, assistant)
} }
// 3. 处理用户消息 // 3. 处理用户消息

View File

@ -290,7 +290,7 @@ export class OpenAIResponseAPIClient extends OpenAIBaseClient<
}) })
if (this.useSystemPromptForTools) { if (this.useSystemPromptForTools) {
systemMessageInput.text = await buildSystemPrompt(systemMessageInput.text || '', mcpTools) systemMessageInput.text = await buildSystemPrompt(systemMessageInput.text || '', mcpTools, assistant)
} }
systemMessageContent.push(systemMessageInput) systemMessageContent.push(systemMessageInput)
systemMessage.content = systemMessageContent systemMessage.content = systemMessageContent

View File

@ -1,5 +1,6 @@
import store from '@renderer/store' import store from '@renderer/store'
import { MCPTool } from '@renderer/types' import { Assistant, MCPTool } from '@renderer/types'
export const SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \ export const SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \
You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
@ -147,7 +148,11 @@ ${availableTools}
</tools>` </tools>`
} }
export const buildSystemPrompt = async (userSystemPrompt: string, tools?: MCPTool[]): Promise<string> => { export const buildSystemPrompt = async (
userSystemPrompt: string,
tools?: MCPTool[],
assistant?: Assistant
): Promise<string> => {
if (typeof userSystemPrompt === 'string') { if (typeof userSystemPrompt === 'string') {
const now = new Date() const now = new Date()
if (userSystemPrompt.includes('{{date}}')) { if (userSystemPrompt.includes('{{date}}')) {
@ -197,8 +202,7 @@ export const buildSystemPrompt = async (userSystemPrompt: string, tools?: MCPToo
if (userSystemPrompt.includes('{{model_name}}')) { if (userSystemPrompt.includes('{{model_name}}')) {
try { try {
const modelName = store.getState().llm.defaultModel.name userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, assistant?.model?.name || 'Unknown Model')
userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, modelName)
} catch (error) { } catch (error) {
console.error('Failed to get model name:', error) console.error('Failed to get model name:', error)
userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, 'Unknown Model') userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, 'Unknown Model')