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) {
systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools)
systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools, assistant)
}
const systemMessage: TextBlockParam | undefined = systemPrompt

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
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. \
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>`
}
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') {
const now = new Date()
if (userSystemPrompt.includes('{{date}}')) {
@ -197,8 +202,7 @@ export const buildSystemPrompt = async (userSystemPrompt: string, tools?: MCPToo
if (userSystemPrompt.includes('{{model_name}}')) {
try {
const modelName = store.getState().llm.defaultModel.name
userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, modelName)
userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, assistant?.model?.name || 'Unknown Model')
} catch (error) {
console.error('Failed to get model name:', error)
userSystemPrompt = userSystemPrompt.replace(/{{model_name}}/g, 'Unknown Model')