update
This commit is contained in:
parent
50990688be
commit
94935e6b9c
@ -1,10 +1,47 @@
|
|||||||
import type { InputSchema } from "@/hook/type";
|
import type { ToolItem } from "@/hook/type";
|
||||||
|
|
||||||
export function toolSchemaToPromptDescription(tool: InputSchema) {
|
|
||||||
|
|
||||||
|
export function toolSchemaToPromptDescription(tools: ToolItem[]) {
|
||||||
|
let prompt = '';
|
||||||
|
|
||||||
|
// 无参数的工具
|
||||||
|
const noParamTools = tools.filter(tool =>
|
||||||
|
!tool.inputSchema.required || tool.inputSchema.required.length === 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (noParamTools.length > 0) {
|
||||||
|
noParamTools.forEach(tool => {
|
||||||
|
prompt += `- ${tool.name}\n`;
|
||||||
|
prompt += `**Description**: ${tool.description}\n\n`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 有参数的工具
|
||||||
|
const paramTools = tools.filter(tool =>
|
||||||
|
tool.inputSchema.required && tool.inputSchema.required.length > 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (paramTools.length > 0) {
|
||||||
|
paramTools.forEach(tool => {
|
||||||
|
prompt += `- ${tool.name}\n`;
|
||||||
|
prompt += `**Description**: ${tool.description}\n`;
|
||||||
|
prompt += `**Parameters**:\n`;
|
||||||
|
|
||||||
|
Object.entries(tool.inputSchema.properties).forEach(([name, prop]) => {
|
||||||
|
const required = tool.inputSchema.required?.includes(name) || false;
|
||||||
|
prompt += `- \`${name}\`: ${prop.description || '无描述'} (${prop.type}) ${required ? '(required)' : ''}\n`;
|
||||||
|
});
|
||||||
|
|
||||||
|
prompt += '\n';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getXmlWrapperPrompt(tools: any) {
|
export function getXmlWrapperPrompt(tools: ToolItem[]) {
|
||||||
|
|
||||||
|
const toolPrompt = toolSchemaToPromptDescription(tools);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
[Start Fresh Session from here]
|
[Start Fresh Session from here]
|
||||||
|
|
||||||
@ -94,21 +131,7 @@ Answer the user's request using the relevant tool(s), if they are available. Che
|
|||||||
Do not use <Start HERE> and <End HERE> in your output, that is just output format reference to where to start and end your output.
|
Do not use <Start HERE> and <End HERE> in your output, that is just output format reference to where to start and end your output.
|
||||||
## AVAILABLE TOOLS FOR SUPERASSISTANT
|
## AVAILABLE TOOLS FOR SUPERASSISTANT
|
||||||
|
|
||||||
- neo4j-mcp.executeReadOnlyCypherQuery
|
${toolPrompt}
|
||||||
**Description**: [neo4j-mcp] 执行只读的 Cypher 查询
|
|
||||||
**Parameters**:
|
|
||||||
- \`cypher\`: Cypher 查询语句,必须是只读的 (string) (required)
|
|
||||||
|
|
||||||
- neo4j-mcp.getAllNodeTypes
|
|
||||||
**Description**: [neo4j-mcp] 获取所有的节点类型
|
|
||||||
|
|
||||||
- neo4j-mcp.getAllRelationTypes
|
|
||||||
**Description**: [neo4j-mcp] 获取所有的关系类型
|
|
||||||
|
|
||||||
- neo4j-mcp.getNodeField
|
|
||||||
**Description**: [neo4j-mcp] 获取节点的字段
|
|
||||||
**Parameters**:
|
|
||||||
- \`nodeLabel\`: 节点的标签 (string) (required)
|
|
||||||
|
|
||||||
- list_servers
|
- list_servers
|
||||||
**Description**: List all connected MCP servers and their capabilities
|
**Description**: List all connected MCP servers and their capabilities
|
||||||
|
@ -15,7 +15,12 @@ import type { ToolItem } from "@/hook/type";
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
export type ChatCompletionChunk = OpenAI.Chat.Completions.ChatCompletionChunk;
|
export type ChatCompletionChunk = OpenAI.Chat.Completions.ChatCompletionChunk;
|
||||||
export type ChatCompletionCreateParamsBase = OpenAI.Chat.Completions.ChatCompletionCreateParams & { id?: string, proxyServer?: string };
|
export interface TaskLoopChatOption {
|
||||||
|
id?: string
|
||||||
|
proxyServer?: string
|
||||||
|
enableXmlWrapper?: boolean
|
||||||
|
}
|
||||||
|
export type ChatCompletionCreateParamsBase = OpenAI.Chat.Completions.ChatCompletionCreateParams & TaskLoopChatOption;
|
||||||
export interface TaskLoopOptions {
|
export interface TaskLoopOptions {
|
||||||
maxEpochs?: number;
|
maxEpochs?: number;
|
||||||
maxJsonParseRetry?: number;
|
maxJsonParseRetry?: number;
|
||||||
@ -148,9 +153,15 @@ export class TaskLoop {
|
|||||||
const { chunk } = data.msg as { chunk: ChatCompletionChunk };
|
const { chunk } = data.msg as { chunk: ChatCompletionChunk };
|
||||||
|
|
||||||
// 处理增量的 content 和 tool_calls
|
// 处理增量的 content 和 tool_calls
|
||||||
this.handleChunkDeltaContent(chunk);
|
if (chatData.enableXmlWrapper) {
|
||||||
this.handleChunkDeltaToolCalls(chunk, toolcallIndexAdapter);
|
this.handleChunkDeltaContent(chunk);
|
||||||
this.handleChunkUsage(chunk);
|
// no tool call in enableXmlWrapper
|
||||||
|
this.handleChunkUsage(chunk);
|
||||||
|
} else {
|
||||||
|
this.handleChunkDeltaContent(chunk);
|
||||||
|
this.handleChunkDeltaToolCalls(chunk, toolcallIndexAdapter);
|
||||||
|
this.handleChunkUsage(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
this.consumeChunks(chunk);
|
this.consumeChunks(chunk);
|
||||||
}, { once: false });
|
}, { once: false });
|
||||||
@ -210,6 +221,7 @@ export class TaskLoop {
|
|||||||
const tools = getToolSchema(tabStorage.settings.enableTools);
|
const tools = getToolSchema(tabStorage.settings.enableTools);
|
||||||
const parallelToolCalls = tabStorage.settings.parallelToolCalls;
|
const parallelToolCalls = tabStorage.settings.parallelToolCalls;
|
||||||
const proxyServer = mcpSetting.proxyServer || '';
|
const proxyServer = mcpSetting.proxyServer || '';
|
||||||
|
const enableXmlWrapper = tabStorage.settings.enableXmlWrapper;
|
||||||
|
|
||||||
const userMessages = [];
|
const userMessages = [];
|
||||||
|
|
||||||
@ -240,7 +252,8 @@ export class TaskLoop {
|
|||||||
tools,
|
tools,
|
||||||
parallelToolCalls,
|
parallelToolCalls,
|
||||||
messages: userMessages,
|
messages: userMessages,
|
||||||
proxyServer
|
proxyServer,
|
||||||
|
enableXmlWrapper
|
||||||
} as ChatCompletionCreateParamsBase;
|
} as ChatCompletionCreateParamsBase;
|
||||||
|
|
||||||
return chatData;
|
return chatData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user