v0.1.4版本 #2
@ -6,10 +6,6 @@
|
|||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
<NoWarn>CA1416</NoWarn>
|
<NoWarn>CA1416</NoWarn>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
<Version>0.1.1</Version>
|
|
||||||
<Title>LinkTool灵图</Title>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="Config.daml" />
|
<None Remove="Config.daml" />
|
||||||
|
|||||||
@ -15,7 +15,6 @@ using System.Xml.Linq;
|
|||||||
using ArcGIS.Desktop.Internal.Mapping.Locate;
|
using ArcGIS.Desktop.Internal.Mapping.Locate;
|
||||||
using LinkToolAddin.client;
|
using LinkToolAddin.client;
|
||||||
using LinkToolAddin.client.prompt;
|
using LinkToolAddin.client.prompt;
|
||||||
using LinkToolAddin.client.tool;
|
|
||||||
using LinkToolAddin.host.llm;
|
using LinkToolAddin.host.llm;
|
||||||
using LinkToolAddin.host.llm.entity;
|
using LinkToolAddin.host.llm.entity;
|
||||||
using LinkToolAddin.host.mcp;
|
using LinkToolAddin.host.mcp;
|
||||||
@ -258,11 +257,10 @@ public class Gateway
|
|||||||
PromptServerList promptServerList = new PromptServerList();
|
PromptServerList promptServerList = new PromptServerList();
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
string messageContent = ""; //一次请求下完整的response
|
string messageContent = ""; //一次请求下完整的response
|
||||||
bool queriedKnowledge = false;
|
|
||||||
while (goOn)
|
while (goOn)
|
||||||
{
|
{
|
||||||
loop++;
|
loop++;
|
||||||
if (loop > 500)
|
if (loop > 20)
|
||||||
{
|
{
|
||||||
MessageBox.Show("达到最大循环次数", "退出循环");
|
MessageBox.Show("达到最大循环次数", "退出循环");
|
||||||
break;
|
break;
|
||||||
@ -391,8 +389,8 @@ public class Gateway
|
|||||||
});
|
});
|
||||||
MessageListItem toolMessageListItem = new ToolMessageItem()
|
MessageListItem toolMessageListItem = new ToolMessageItem()
|
||||||
{
|
{
|
||||||
content = toolName,
|
content = "",
|
||||||
result = "工具运行中" + toolName,
|
result = "",
|
||||||
toolName = toolName,
|
toolName = toolName,
|
||||||
toolParams = toolParams,
|
toolParams = toolParams,
|
||||||
role = "user",
|
role = "user",
|
||||||
@ -428,7 +426,6 @@ public class Gateway
|
|||||||
Content = messageContent
|
Content = messageContent
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Thread.Sleep(100);
|
|
||||||
/*统一处理本次请求中的MCP工具调用需求*/
|
/*统一处理本次请求中的MCP工具调用需求*/
|
||||||
foreach (McpToolRequest mcpToolRequest in mcpToolRequests)
|
foreach (McpToolRequest mcpToolRequest in mcpToolRequests)
|
||||||
{
|
{
|
||||||
@ -495,62 +492,6 @@ public class Gateway
|
|||||||
}
|
}
|
||||||
else if (mcpServer is InnerMcpServer)
|
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<string, object>(){{"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<string, object>(){{"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);
|
Type type = Type.GetType("LinkToolAddin.client.tool." + (mcpServer as InnerMcpServer).Name);
|
||||||
MethodInfo method = type.GetMethod(toolName, BindingFlags.Public | BindingFlags.Static);
|
MethodInfo method = type.GetMethod(toolName, BindingFlags.Public | BindingFlags.Static);
|
||||||
var methodParams = toolParams.Values.ToArray();
|
var methodParams = toolParams.Values.ToArray();
|
||||||
@ -571,7 +512,6 @@ public class Gateway
|
|||||||
|
|
||||||
var task = method.Invoke(null, args) as Task<JsonRpcResultEntity>;
|
var task = method.Invoke(null, args) as Task<JsonRpcResultEntity>;
|
||||||
JsonRpcResultEntity innerResult = await task;
|
JsonRpcResultEntity innerResult = await task;
|
||||||
queriedKnowledge = false;
|
|
||||||
if (innerResult is JsonRpcErrorEntity)
|
if (innerResult is JsonRpcErrorEntity)
|
||||||
{
|
{
|
||||||
MessageListItem toolMessageItem = new ToolMessageItem
|
MessageListItem toolMessageItem = new ToolMessageItem
|
||||||
@ -633,26 +573,25 @@ public class Gateway
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string promptContent = DynamicPrompt.GetPrompt(promptRequest.PromptName, promptRequest.PromptArgs);
|
string promptContent = DynamicPrompt.GetPrompt(promptRequest.PromptName, promptRequest.PromptArgs);
|
||||||
MessageListItem promptMessageItem = new ToolMessageItem
|
|
||||||
{
|
|
||||||
toolName = "调用提示词",
|
|
||||||
toolParams = new Dictionary<string, object>(),
|
|
||||||
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
|
messages.Add(new Message
|
||||||
{
|
{
|
||||||
Role = "user",
|
Role = "user",
|
||||||
Content = promptContent
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -49,11 +49,4 @@ public class SystemPrompt
|
|||||||
errPrompt = errPrompt.Replace("{{toolResult}}", toolResult);
|
errPrompt = errPrompt.Replace("{{toolResult}}", toolResult);
|
||||||
return errPrompt;
|
return errPrompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToolContinuePrompt(string toolResult)
|
|
||||||
{
|
|
||||||
string continuePrompt = "根据你需要调用的工具查询到如下帮助文档内容,请严格按照帮助文档中的参数和名称要求再次生成准确的工具调用请求以确保工具调用成功。\n{{toolResult}}";
|
|
||||||
continuePrompt = continuePrompt.Replace("{{toolResult}}", toolResult);
|
|
||||||
return continuePrompt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ namespace LinkToolAddin
|
|||||||
{
|
{
|
||||||
internal class VersionButton : Button
|
internal class VersionButton : Button
|
||||||
{
|
{
|
||||||
private string version = "0.1.2";
|
private string version = "0.1.1";
|
||||||
protected override void OnClick()
|
protected override void OnClick()
|
||||||
{
|
{
|
||||||
MessageBox.Show($"当前LinkTool版本为{version}", "版本信息");
|
MessageBox.Show($"当前LinkTool版本为{version}", "版本信息");
|
||||||
|
|||||||
@ -117,7 +117,6 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
QuestionTextbox.Text = "";
|
QuestionTextbox.Text = "";
|
||||||
borderItemsDict[timestamp.ToString()] = userMsgBoder;
|
borderItemsDict[timestamp.ToString()] = userMsgBoder;
|
||||||
ChatHistoryStackPanel.Children.Add(userMsgBoder);
|
ChatHistoryStackPanel.Children.Add(userMsgBoder);
|
||||||
StatusTextBlock.Text = "正在读取用户输入";
|
|
||||||
Gateway.SendMessageStream(question,"qwen3-235b-a22b",defaultGdbPath,NewMessage_Recall);
|
Gateway.SendMessageStream(question,"qwen3-235b-a22b",defaultGdbPath,NewMessage_Recall);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,10 +133,6 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
//不存在该消息,需添加到ListView中
|
//不存在该消息,需添加到ListView中
|
||||||
if (msg.content == "")
|
if (msg.content == "")
|
||||||
{
|
{
|
||||||
if (msg.type == MessageType.END_TAG)
|
|
||||||
{
|
|
||||||
StatusTextBlock.Text = "";
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
idList.Add(msgId);
|
idList.Add(msgId);
|
||||||
@ -172,6 +167,9 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
borderItemsDict[msgId] = border;
|
borderItemsDict[msgId] = border;
|
||||||
ChatHistoryStackPanel.Children.Add(border);
|
ChatHistoryStackPanel.Children.Add(border);
|
||||||
StatusTextBlock.Text = "回答生成中";
|
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);
|
borderItemsDict.TryRemove(msgId, out Border border);
|
||||||
messageDict.TryRemove(msgId, out MessageListItem tempMsg);
|
messageDict.TryRemove(msgId, out MessageListItem tempMsg);
|
||||||
idList.Remove(msgId);
|
idList.Remove(msgId);
|
||||||
if (msg.type == MessageType.END_TAG)
|
|
||||||
{
|
|
||||||
StatusTextBlock.Text = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (msg.role == "user")
|
if (msg.role == "user")
|
||||||
{
|
{
|
||||||
@ -224,6 +218,9 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
TextBox textBox = grid.Children[1] as TextBox;
|
TextBox textBox = grid.Children[1] as TextBox;
|
||||||
textBox.Text = msg.content;
|
textBox.Text = msg.content;
|
||||||
StatusTextBlock.Text = "回答生成中";
|
StatusTextBlock.Text = "回答生成中";
|
||||||
|
}else if (msg.type == MessageType.END_TAG)
|
||||||
|
{
|
||||||
|
StatusTextBlock.Text = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user