mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 16:39:15 +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) {
|
if (this.useSystemPromptForTools) {
|
||||||
systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools)
|
systemPrompt = await buildSystemPrompt(systemPrompt, mcpTools, assistant)
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemMessage: TextBlockParam | undefined = systemPrompt
|
const systemMessage: TextBlockParam | undefined = systemPrompt
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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. 处理用户消息
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user