From 718718ef111080cc6900db5b77dfe041b3b1835b Mon Sep 17 00:00:00 2001 From: PeterZhong Date: Sat, 7 Jun 2025 23:19:06 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"1.=20=E8=A7=A3=E5=86=B3=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D=E5=8D=A1=E7=89=87=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54b78d0b5c97d18ff75eb90dfd63c53614751fd9. --- LinkToolAddin.csproj | 4 -- host/Gateway.cs | 95 ++++++------------------------ host/prompt/SystemPrompt.cs | 7 --- ui/VersionButton.cs | 2 +- ui/dockpane/DialogDockpane.xaml.cs | 15 ++--- 5 files changed, 24 insertions(+), 99 deletions(-) diff --git a/LinkToolAddin.csproj b/LinkToolAddin.csproj index 33ff34b..bece90c 100644 --- a/LinkToolAddin.csproj +++ b/LinkToolAddin.csproj @@ -6,10 +6,6 @@ true CA1416 net8.0-windows - true - false - 0.1.1 - LinkTool灵图 diff --git a/host/Gateway.cs b/host/Gateway.cs index 428ed47..78889e8 100644 --- a/host/Gateway.cs +++ b/host/Gateway.cs @@ -15,7 +15,6 @@ using System.Xml.Linq; using ArcGIS.Desktop.Internal.Mapping.Locate; using LinkToolAddin.client; using LinkToolAddin.client.prompt; -using LinkToolAddin.client.tool; using LinkToolAddin.host.llm; using LinkToolAddin.host.llm.entity; using LinkToolAddin.host.mcp; @@ -258,11 +257,10 @@ public class Gateway PromptServerList promptServerList = new PromptServerList(); int loop = 0; string messageContent = ""; //一次请求下完整的response - bool queriedKnowledge = false; while (goOn) { loop++; - if (loop > 500) + if (loop > 20) { MessageBox.Show("达到最大循环次数", "退出循环"); break; @@ -391,8 +389,8 @@ public class Gateway }); MessageListItem toolMessageListItem = new ToolMessageItem() { - content = toolName, - result = "工具运行中" + toolName, + content = "", + result = "", toolName = toolName, toolParams = toolParams, role = "user", @@ -428,7 +426,6 @@ public class Gateway Content = messageContent }); } - Thread.Sleep(100); /*统一处理本次请求中的MCP工具调用需求*/ foreach (McpToolRequest mcpToolRequest in mcpToolRequests) { @@ -495,62 +492,6 @@ public class Gateway } else if (mcpServer is InnerMcpServer) { - InnerMcpServer innerMcpServer = mcpServer as InnerMcpServer; - string mcpServerName = innerMcpServer.Name; - if (toolName == "ArcGisProTool" && queriedKnowledge == false) - { - JsonRpcResultEntity knowledgeResult = await KnowledgeBase.QueryArcgisToolDoc(toolParams["toolName"].ToString()); - if (knowledgeResult is JsonRpcSuccessEntity) - { - JsonRpcSuccessEntity knowledgeSuccessResult = knowledgeResult as JsonRpcSuccessEntity; - MessageListItem toolMessageItem = new ToolMessageItem - { - toolName = "QueryArcgisToolDoc", - toolParams = new Dictionary(){{"query",toolParams["toolName"].ToString()}}, - type = MessageType.TOOL_MESSAGE, - status = "success", - content = JsonConvert.SerializeObject(knowledgeSuccessResult.Result), - result = JsonConvert.SerializeObject(knowledgeSuccessResult.Result), - id = (timestamp + 4).ToString(), - role = "user" - }; - messages.Add(new Message - { - Role = "user", - Content = SystemPrompt.ToolContinuePrompt(JsonConvert.SerializeObject(knowledgeSuccessResult)) - }); - Application.Current.Dispatcher.Invoke(() => - { - callback?.Invoke(toolMessageItem); - }); - queriedKnowledge = true; - } - else - { - JsonRpcErrorEntity knowledgeErrorResult = knowledgeResult as JsonRpcErrorEntity; - MessageListItem toolMessageItem = new ToolMessageItem - { - toolName = "QueryArcgisToolDoc", - toolParams = new Dictionary(){{"query",toolParams["toolName"].ToString()}}, - type = MessageType.TOOL_MESSAGE, - status = "fail", - content = JsonConvert.SerializeObject(knowledgeErrorResult.Error), - result = JsonConvert.SerializeObject(knowledgeErrorResult.Error), - id = (timestamp + 4).ToString(), - role = "user" - }; - messages.Add(new Message - { - Role = "user", - Content = SystemPrompt.ErrorPrompt(JsonConvert.SerializeObject(knowledgeErrorResult)) - }); - Application.Current.Dispatcher.Invoke(() => - { - callback?.Invoke(toolMessageItem); - }); - } - continue; - } Type type = Type.GetType("LinkToolAddin.client.tool." + (mcpServer as InnerMcpServer).Name); MethodInfo method = type.GetMethod(toolName, BindingFlags.Public | BindingFlags.Static); var methodParams = toolParams.Values.ToArray(); @@ -571,7 +512,6 @@ public class Gateway var task = method.Invoke(null, args) as Task; JsonRpcResultEntity innerResult = await task; - queriedKnowledge = false; if (innerResult is JsonRpcErrorEntity) { MessageListItem toolMessageItem = new ToolMessageItem @@ -633,26 +573,25 @@ public class Gateway try { string promptContent = DynamicPrompt.GetPrompt(promptRequest.PromptName, promptRequest.PromptArgs); - MessageListItem promptMessageItem = new ToolMessageItem - { - toolName = "调用提示词", - toolParams = new Dictionary(), - type = MessageType.TOOL_MESSAGE, - status = "success", - content = "成功调用提示词:"+promptRequest.PromptName, - id = (timestamp+1).ToString(), - role = "user", - result = "成功调用提示词:"+promptRequest.PromptName - }; - Application.Current.Dispatcher.Invoke(() => - { - callback?.Invoke(promptMessageItem); - }); messages.Add(new Message { Role = "user", Content = promptContent }); + MessageListItem toolMessageItem = new ToolMessageItem + { + toolName = "调用提示词", + toolParams = null, + type = MessageType.TOOL_MESSAGE, + status = "success", + content = "成功调用提示词:"+promptRequest.PromptName, + id = (timestamp+1).ToString(), + result = "成功调用提示词:"+promptRequest.PromptName + }; + Application.Current.Dispatcher.Invoke(() => + { + callback?.Invoke(toolMessageItem); + }); } catch (Exception e) { diff --git a/host/prompt/SystemPrompt.cs b/host/prompt/SystemPrompt.cs index b6db27c..2295d68 100644 --- a/host/prompt/SystemPrompt.cs +++ b/host/prompt/SystemPrompt.cs @@ -49,11 +49,4 @@ public class SystemPrompt errPrompt = errPrompt.Replace("{{toolResult}}", toolResult); return errPrompt; } - - public static string ToolContinuePrompt(string toolResult) - { - string continuePrompt = "根据你需要调用的工具查询到如下帮助文档内容,请严格按照帮助文档中的参数和名称要求再次生成准确的工具调用请求以确保工具调用成功。\n{{toolResult}}"; - continuePrompt = continuePrompt.Replace("{{toolResult}}", toolResult); - return continuePrompt; - } } \ No newline at end of file diff --git a/ui/VersionButton.cs b/ui/VersionButton.cs index bbc7a75..bc4df57 100644 --- a/ui/VersionButton.cs +++ b/ui/VersionButton.cs @@ -22,7 +22,7 @@ namespace LinkToolAddin { internal class VersionButton : Button { - private string version = "0.1.2"; + private string version = "0.1.1"; protected override void OnClick() { MessageBox.Show($"当前LinkTool版本为{version}", "版本信息"); diff --git a/ui/dockpane/DialogDockpane.xaml.cs b/ui/dockpane/DialogDockpane.xaml.cs index 45e9cec..3e623ae 100644 --- a/ui/dockpane/DialogDockpane.xaml.cs +++ b/ui/dockpane/DialogDockpane.xaml.cs @@ -117,7 +117,6 @@ namespace LinkToolAddin.ui.dockpane QuestionTextbox.Text = ""; borderItemsDict[timestamp.ToString()] = userMsgBoder; ChatHistoryStackPanel.Children.Add(userMsgBoder); - StatusTextBlock.Text = "正在读取用户输入"; Gateway.SendMessageStream(question,"qwen3-235b-a22b",defaultGdbPath,NewMessage_Recall); } @@ -134,10 +133,6 @@ namespace LinkToolAddin.ui.dockpane //不存在该消息,需添加到ListView中 if (msg.content == "") { - if (msg.type == MessageType.END_TAG) - { - StatusTextBlock.Text = ""; - } return; } idList.Add(msgId); @@ -172,6 +167,9 @@ namespace LinkToolAddin.ui.dockpane borderItemsDict[msgId] = border; ChatHistoryStackPanel.Children.Add(border); StatusTextBlock.Text = "回答生成中"; + }else if (msg.type == MessageType.END_TAG) + { + StatusTextBlock.Text = ""; } } } @@ -185,10 +183,6 @@ namespace LinkToolAddin.ui.dockpane borderItemsDict.TryRemove(msgId, out Border border); messageDict.TryRemove(msgId, out MessageListItem tempMsg); idList.Remove(msgId); - if (msg.type == MessageType.END_TAG) - { - StatusTextBlock.Text = ""; - } } if (msg.role == "user") { @@ -224,6 +218,9 @@ namespace LinkToolAddin.ui.dockpane TextBox textBox = grid.Children[1] as TextBox; textBox.Text = msg.content; StatusTextBlock.Text = "回答生成中"; + }else if (msg.type == MessageType.END_TAG) + { + StatusTextBlock.Text = ""; } } }