mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
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:
parent
2a0484ede2
commit
e4e4dcbd1e
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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. 处理用户消息
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user