Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix (about mcpPrompt) and add deepseek-reasoner #6087

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ You are an AI assistant with access to system tools. Your role is to help users

export const SUMMARIZE_MODEL = "gpt-4o-mini";
export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
export const DEEPSEEK_SUMMARIZE_MODEL = "deepseek-chat";

export const KnowledgeCutOffDate: Record<string, string> = {
default: "2021-09",
Expand Down Expand Up @@ -561,7 +562,7 @@ const iflytekModels = [
"4.0Ultra",
];

const deepseekModels = ["deepseek-chat", "deepseek-coder"];
const deepseekModels = ["deepseek-chat", "deepseek-coder", "deepseek-reasoner"];

const xAIModes = ["grok-beta"];

Expand Down
51 changes: 31 additions & 20 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
DEFAULT_MODELS,
DEFAULT_SYSTEM_TEMPLATE,
GEMINI_SUMMARIZE_MODEL,
DEEPSEEK_SUMMARIZE_MODEL,
KnowledgeCutOffDate,
MCP_SYSTEM_TEMPLATE,
MCP_TOOLS_TEMPLATE,
Expand All @@ -35,7 +36,7 @@ import { ModelConfig, ModelType, useAppConfig } from "./config";
import { useAccessStore } from "./access";
import { collectModelsWithDefaultModel } from "../utils/model";
import { createEmptyMask, Mask } from "./mask";
import { executeMcpAction, getAllTools } from "../mcp/actions";
import { executeMcpAction, getAllTools, isMcpEnabled } from "../mcp/actions";
import { extractMcpJson, isMcpJson } from "../mcp/utils";

const localStorage = safeLocalStorage();
Expand Down Expand Up @@ -143,7 +144,10 @@ function getSummarizeModel(
}
if (currentModel.startsWith("gemini")) {
return [GEMINI_SUMMARIZE_MODEL, ServiceProvider.Google];
} else if (currentModel.startsWith("deepseek-")) {
return [DEEPSEEK_SUMMARIZE_MODEL, ServiceProvider.DeepSeek];
}

return [currentModel, providerName];
}

Expand Down Expand Up @@ -245,7 +249,7 @@ export const useChatStore = createPersistStore(

newSession.topic = currentSession.topic;
// 深拷贝消息
newSession.messages = currentSession.messages.map(msg => ({
newSession.messages = currentSession.messages.map((msg) => ({
...msg,
id: nanoid(), // 生成新的消息 ID
}));
Expand Down Expand Up @@ -551,27 +555,32 @@ export const useChatStore = createPersistStore(
(session.mask.modelConfig.model.startsWith("gpt-") ||
session.mask.modelConfig.model.startsWith("chatgpt-"));

const mcpSystemPrompt = await getMcpSystemPrompt();
const mcpEnabled = await isMcpEnabled();
const mcpSystemPrompt = mcpEnabled ? await getMcpSystemPrompt() : "";

var systemPrompts: ChatMessage[] = [];
systemPrompts = shouldInjectSystemPrompts
? [
createMessage({
role: "system",
content:
fillTemplateWith("", {
...modelConfig,
template: DEFAULT_SYSTEM_TEMPLATE,
}) + mcpSystemPrompt,
}),
]
: [
createMessage({
role: "system",
content: mcpSystemPrompt,
}),
];

if (shouldInjectSystemPrompts) {
systemPrompts = [
createMessage({
role: "system",
content:
fillTemplateWith("", {
...modelConfig,
template: DEFAULT_SYSTEM_TEMPLATE,
}) + mcpSystemPrompt,
}),
];
} else if (mcpEnabled) {
systemPrompts = [
createMessage({
role: "system",
content: mcpSystemPrompt,
}),
];
}

if (shouldInjectSystemPrompts || mcpEnabled) {
console.log(
"[Global System Prompt] ",
systemPrompts.at(0)?.content ?? "empty",
Expand Down Expand Up @@ -816,6 +825,8 @@ export const useChatStore = createPersistStore(

/** check if the message contains MCP JSON and execute the MCP action */
checkMcpJson(message: ChatMessage) {
const mcpEnabled = isMcpEnabled();
if (!mcpEnabled) return;
const content = getMessageTextContent(message);
if (isMcpJson(content)) {
try {
Expand Down
Loading