From f14687b1d8d99c49d75c00ee6f92585871231386 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Thu, 24 Apr 2025 20:51:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=20tool=20use=20=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E8=B4=9F=E5=8F=8D=E9=A6=88=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/main-panel/chat/index.vue | 25 ++-- .../main-panel/chat/message/toolcall.vue | 118 ++++++++++------ renderer/src/views/setting/llm.ts | 2 +- service/tabs.example-servers/puppeteer.json | 129 ++++++++++++++++++ service/tabs.锦恢的 MCP Server.json | 44 ++++++ 5 files changed, 262 insertions(+), 56 deletions(-) create mode 100644 service/tabs.example-servers/puppeteer.json diff --git a/renderer/src/components/main-panel/chat/index.vue b/renderer/src/components/main-panel/chat/index.vue index ec031a8..937ac04 100644 --- a/renderer/src/components/main-panel/chat/index.vue +++ b/renderer/src/components/main-panel/chat/index.vue @@ -3,8 +3,9 @@
-
+ :class="['message-item', message.role.split('/')[0]]" + > +
@@ -131,6 +132,7 @@ interface IRenderMessage { tool_calls?: ToolCall[]; showJson?: Ref; extraInfo: IExtraInfo; + isLast: boolean; } const renderMessages = computed(() => { @@ -140,7 +142,8 @@ const renderMessages = computed(() => { messages.push({ role: 'user', content: message.content, - extraInfo: message.extraInfo + extraInfo: message.extraInfo, + isLast: false }); } else if (message.role === 'assistant') { if (message.tool_calls) { @@ -149,13 +152,15 @@ const renderMessages = computed(() => { content: message.content, tool_calls: message.tool_calls, showJson: ref(false), - extraInfo: message.extraInfo + extraInfo: message.extraInfo, + isLast: false }); } else { messages.push({ role: 'assistant/content', content: message.content, - extraInfo: message.extraInfo + extraInfo: message.extraInfo, + isLast: false }); } @@ -169,6 +174,11 @@ const renderMessages = computed(() => { } } + if (messages.length > 0) { + const lastMessage = messages[messages.length - 1]; + lastMessage.isLast = true; + } + return messages; }); @@ -375,11 +385,6 @@ onUnmounted(() => { line-height: 1.6; } -.message-text.tool_calls { - border-left: 3px solid var(--main-color); - padding-left: 10px; -} - .user .message-text { margin-top: 10px; margin-bottom: 10px; diff --git a/renderer/src/components/main-panel/chat/message/toolcall.vue b/renderer/src/components/main-panel/chat/message/toolcall.vue index cfb7483..351d04b 100644 --- a/renderer/src/components/main-panel/chat/message/toolcall.vue +++ b/renderer/src/components/main-panel/chat/message/toolcall.vue @@ -1,64 +1,72 @@ \ No newline at end of file diff --git a/renderer/src/views/setting/llm.ts b/renderer/src/views/setting/llm.ts index 4837fbf..44269ba 100644 --- a/renderer/src/views/setting/llm.ts +++ b/renderer/src/views/setting/llm.ts @@ -18,7 +18,7 @@ export function createTest(call: ToolCall) { tab.component = markRaw(debugModes[2]); tab.icon = 'icon-tool'; tab.name = t("tools"); - 1 + const storage: ToolStorage = { currentToolName: call.function.name, formData: JSON.parse(call.function.arguments) diff --git a/service/tabs.example-servers/puppeteer.json b/service/tabs.example-servers/puppeteer.json new file mode 100644 index 0000000..7635b85 --- /dev/null +++ b/service/tabs.example-servers/puppeteer.json @@ -0,0 +1,129 @@ +{ + "currentIndex": 1, + "tabs": [ + { + "name": "空白测试 2", + "icon": "icon-blank", + "type": "blank", + "componentIndex": -1, + "storage": {} + }, + { + "name": "交互测试", + "icon": "icon-robot", + "type": "blank", + "componentIndex": 3, + "storage": { + "messages": [ + { + "role": "user", + "content": "今天天气", + "extraInfo": { + "created": 1745498953049, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "call_zw5axi9gftk294vifdlfv83y", + "index": 0, + "type": "function", + "function": { + "name": "puppeteer_navigate", + "arguments": "{\"url\":\"https://www.weather.com\"}" + } + } + ], + "extraInfo": { + "created": 1745498953891, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "tool", + "tool_call_id": "call_zw5axi9gftk294vifdlfv83y", + "content": "[{\"type\":\"text\",\"text\":\"Navigated to https://www.weather.com\"}]", + "extraInfo": { + "created": 1745498965901, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "call_enwp8eh9q0rklmz1cr0lfinx", + "index": 0, + "type": "function", + "function": { + "name": "puppeteer_evaluate", + "arguments": "{\"script\":\"document.querySelector('.CurrentConditions--tempValue--3KcTQ').innerText\"}" + } + } + ], + "extraInfo": { + "created": 1745498967051, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "assistant", + "content": "错误: 工具调用失败: [object Object]", + "extraInfo": { + "created": 1745498967057, + "serverName": "Huoshan DeepSeek" + } + } + ], + "settings": { + "modelIndex": 8, + "enableTools": [ + { + "name": "puppeteer_navigate", + "description": "Navigate to a URL", + "enabled": true + }, + { + "name": "puppeteer_screenshot", + "description": "Take a screenshot of the current page or a specific element", + "enabled": true + }, + { + "name": "puppeteer_click", + "description": "Click an element on the page", + "enabled": true + }, + { + "name": "puppeteer_fill", + "description": "Fill out an input field", + "enabled": true + }, + { + "name": "puppeteer_select", + "description": "Select an element on the page with Select tag", + "enabled": true + }, + { + "name": "puppeteer_hover", + "description": "Hover an element on the page", + "enabled": true + }, + { + "name": "puppeteer_evaluate", + "description": "Execute JavaScript in the browser console", + "enabled": true + } + ], + "enableWebSearch": false, + "temperature": 0.7, + "contextLength": 10, + "systemPrompt": "" + } + } + } + ] +} \ No newline at end of file diff --git a/service/tabs.锦恢的 MCP Server.json b/service/tabs.锦恢的 MCP Server.json index bfddece..126901c 100644 --- a/service/tabs.锦恢的 MCP Server.json +++ b/service/tabs.锦恢的 MCP Server.json @@ -81,6 +81,50 @@ "prompt_cache_miss_tokens": 84 } } + }, + { + "role": "user", + "content": "再试一次", + "extraInfo": { + "created": 1745495349299, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "call_jpm4v1e92v4nq650wlqkhm56", + "index": 0, + "type": "function", + "function": { + "name": "get_weather_by_city_code", + "arguments": "{\"city_code\":101210101}" + } + } + ], + "extraInfo": { + "created": 1745495350097, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "tool", + "tool_call_id": "call_jpm4v1e92v4nq650wlqkhm56", + "content": "[{\"type\":\"text\",\"text\":\"CityWeather(city_name_en='hangzhou', city_name_cn='杭州', city_code='101210101', temp='18.3', wd='', ws='', sd='89%', aqi='57', weather='阴')\"}]", + "extraInfo": { + "created": 1745495350319, + "serverName": "Huoshan DeepSeek" + } + }, + { + "role": "assistant", + "content": "杭州的最新天气信息如下:\n\n- 城市:杭州\n- 温度:18.3°C\n- 天气状况:阴\n- 湿度:89%\n- 空气质量指数 (AQI):57(良好)\n\n天气较为凉爽,适合外出活动!", + "extraInfo": { + "created": 1745495352693, + "serverName": "Huoshan DeepSeek" + } } ], "settings": {