v0.1.4版本 #2
@ -20,7 +20,9 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="240"/>
|
||||
<RowDefinition Height="480"/>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="24"/>
|
||||
<RowDefinition Height="24"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Button Grid.Row="0" Content="Test Workflow" Name="TestServer" Click="TestWorkflow_OnClick"></Button>
|
||||
@ -31,9 +33,11 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Row="0" Grid.Column="0" ToolTip="输入测试提示词" Name="PromptTestTextBox"></TextBox>
|
||||
<Button Grid.Row="0" Grid.Column="1" Content="测试" Name="PromptTestButton" Click="PromptTestButton_OnClick"></Button>
|
||||
<Button Grid.Row="0" Grid.Column="1" Content="发送" Name="PromptTestButton" Click="PromptTestButton_OnClick"></Button>
|
||||
</Grid>
|
||||
<TextBox Grid.Row="2" ToolTip="大模型回复" Name="ReplyTextBox" TextWrapping="Wrap"></TextBox>
|
||||
<Button Grid.Row="3" Content="Test Stream" Name="TestStream" Click="TestStream_OnClick"></Button>
|
||||
<Button Grid.Row="3" Content="停止回答" Name="StopConversation" Click="StopConversation_OnClick"></Button>
|
||||
<Button Grid.Row="4" Content="Test Stream" Name="TestStream" Click="TestStream_OnClick"></Button>
|
||||
<Button Grid.Row="5" Content="Test Arcgis Tool" Name="TestArcGisTool" Click="TestArcGisTool_OnClick"></Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -1,12 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Xml.Linq;
|
||||
using LinkToolAddin.client;
|
||||
using LinkToolAddin.host;
|
||||
using LinkToolAddin.host.llm;
|
||||
using LinkToolAddin.host.llm.entity;
|
||||
using LinkToolAddin.host.mcp;
|
||||
using LinkToolAddin.host.prompt;
|
||||
using LinkToolAddin.message;
|
||||
using LinkToolAddin.resource;
|
||||
using LinkToolAddin.server;
|
||||
@ -231,5 +237,42 @@ namespace LinkToolAddin.ui.dockpane
|
||||
{
|
||||
Request_Bailian_Stream_Test();
|
||||
}
|
||||
|
||||
private void StopConversation_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Gateway.StopConversation();
|
||||
}
|
||||
|
||||
private async void TestArcGisTool_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string xmlStr =
|
||||
"<tool_use>\n<name>ArcGisPro:ArcGisProTool</name>\n<arguments>{\"toolName\": \"Buffer\", \"toolParams\": [\"D:\\\\01_Project\\\\20250305_LinkTool\\\\20250420_AiDemoProject\\\\20250420_AiDemoProject.gdb\\\\LandUse_2005_Copy\", \"D:\\\\01_Project\\\\20250305_LinkTool\\\\20250420_AiDemoProject\\\\20250420_AiDemoProject.gdb\\\\LandUse_2005_Buffer30m\", \"30 Meters\", \"NONE\", \"ROUND\", \"ALL\"]}</arguments>\n</tool_use>";
|
||||
XElement toolUse = XElement.Parse(xmlStr);
|
||||
string fullToolName = toolUse.Element("name")?.Value;
|
||||
string toolArgs = toolUse.Element("arguments")?.Value;
|
||||
Dictionary<string, object> toolParams = JsonConvert.DeserializeObject<Dictionary<string, object>>(toolArgs);
|
||||
string serverName = fullToolName.Contains(":") ? fullToolName.Split(':')[0] : fullToolName;
|
||||
string toolName = fullToolName.Contains(":") ? fullToolName.Split(':')[1] : fullToolName;
|
||||
McpServerList mcpServerList = new McpServerList();
|
||||
McpServer mcpServer = mcpServerList.GetServer(serverName);
|
||||
if (mcpServer is InnerMcpServer)
|
||||
{
|
||||
Type type = Type.GetType("LinkToolAddin.client.tool." + serverName);
|
||||
var toolParamsValues = toolParams.Values.ToArray();
|
||||
MethodInfo method = type.GetMethod(toolName, BindingFlags.Public | BindingFlags.Static);
|
||||
var task = method.Invoke(null, toolParams.Values.ToArray()) as Task<JsonRpcResultEntity>;
|
||||
JsonRpcResultEntity innerResult = await task;
|
||||
MessageListItem toolMessageItem = new ToolMessageItem
|
||||
{
|
||||
toolName = toolName,
|
||||
toolParams = toolParams,
|
||||
type = MessageType.TOOL_MESSAGE,
|
||||
status = "fail",
|
||||
content = JsonConvert.SerializeObject(innerResult),
|
||||
id = "1test"
|
||||
};
|
||||
AddReply(toolMessageItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user