diff --git a/Config.daml b/Config.daml index 18a04f2..3d96906 100644 --- a/Config.daml +++ b/Config.daml @@ -26,6 +26,7 @@ + diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 165b000..d7b4b9f 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "LinkToolAddin": { "commandName": "Executable", - "executablePath": "C:\\Users\\86158\\AppData\\Local\\Programs\\ArcGIS\\Pro\\bin\\ArcGISPro.exe", + "executablePath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\ArcGISPro.exe", "applicationUrl": "https://localhost:5001", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/host/Gateway.cs b/host/Gateway.cs index 07423a5..da3d05f 100644 --- a/host/Gateway.cs +++ b/host/Gateway.cs @@ -238,10 +238,43 @@ public class Gateway public static async void SendMessageStream(string message, string model, string gdbPath, Action callback) { - Llm bailian = new Bailian + Llm modelObj = new Bailian(); + List bailianModels = []; + List dmxModels = ["gpt-4o","claude-sonnet-4-20250514-thinking","claude-sonnet-4-20250514","grok-3-reasoner","gemini-2.5-pro"]; + if (bailianModels.Contains(model)) { - api_key = "sk-db177155677e438f832860e7f4da6afc" - }; + modelObj = new Bailian + { + api_key = "sk-db177155677e438f832860e7f4da6afc" + }; + }else if (dmxModels.Contains(model)) + { + modelObj = new DmxApi + { + api_key = "sk-VQeuLUmhO1LL8H97tFj5kuWOqGFD4CFRmAsdqhxkmkYxUUlP" + }; + } + else + { + MessageListItem endMessageListItem2 = new ChatMessageItem + { + type = MessageType.ERROR, + content = $"目前暂未支持{model}模型,请选择其他模型。", + id = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(), + role = "system" + }; + callback?.Invoke(endMessageListItem2); + MessageListItem endMessageListItem1 = new ChatMessageItem + { + type = MessageType.END_TAG, + content = "", + id = (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + 3).ToString(), + role = "assistant" + }; + callback?.Invoke(endMessageListItem1); + return; + } + List messages = new List(); string toolInfos = ""; try @@ -268,6 +301,14 @@ public class Gateway role = "system" }; callback?.Invoke(endMessageListItem2); + MessageListItem endMessageListItem1 = new ChatMessageItem + { + type = MessageType.END_TAG, + content = "", + id = (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + 3).ToString(), + role = "assistant" + }; + callback?.Invoke(endMessageListItem1); // MessageBox.Show(ex.Message,"获取MCP列表失败"); } goOn = true; @@ -293,6 +334,14 @@ public class Gateway role = "system" }; callback?.Invoke(endMessageListItem2); + MessageListItem endMessageListItem1 = new ChatMessageItem + { + type = MessageType.END_TAG, + content = "", + id = (timestamp + 3).ToString(), + role = "assistant" + }; + callback?.Invoke(endMessageListItem1); // MessageBox.Show("达到最大循环次数", "退出循环"); break; } @@ -302,7 +351,6 @@ public class Gateway Messages = messages, Temperature = 0.3, TopP = 0.4, - TopK = 7, MaxTokens = 1000, }; List mcpToolRequests = new List(); @@ -326,7 +374,7 @@ public class Gateway try { - await foreach(LlmStreamChat llmStreamChat in bailian.SendChatStreamAsync(jsonContent)) + await foreach(LlmStreamChat llmStreamChat in modelObj.SendChatStreamAsync(jsonContent)) { if (!goOn) { @@ -465,6 +513,14 @@ public class Gateway role = "system" }; callback?.Invoke(endMessageListItem2); + MessageListItem endMessageListItem1 = new ChatMessageItem + { + type = MessageType.END_TAG, + content = "", + id = (timestamp + 3).ToString(), + role = "assistant" + }; + callback?.Invoke(endMessageListItem1); // MessageBox.Show(e.Message, "请求大模型出错"); break; } diff --git a/host/McpServerList.cs b/host/McpServerList.cs index 8a7ceb7..497f502 100644 --- a/host/McpServerList.cs +++ b/host/McpServerList.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using LinkToolAddin.host.mcp; +using Newtonsoft.Json; namespace LinkToolAddin.host; @@ -84,6 +85,11 @@ public class McpServerList } }); } + + public McpServerList(string json) + { + servers = JsonConvert.DeserializeObject>(json); + } public McpServer GetServer(string name) { diff --git a/host/llm/DmxApi.cs b/host/llm/DmxApi.cs new file mode 100644 index 0000000..3caaed6 --- /dev/null +++ b/host/llm/DmxApi.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using LinkToolAddin.common; +using LinkToolAddin.host.llm.entity; +using LinkToolAddin.host.llm.entity.stream; +using Newtonsoft.Json; + +namespace LinkToolAddin.host.llm; + +public class DmxApi : Llm +{ + public string model { get; set; } = "gpt-4o"; + public string temperature { get; set; } + public string top_p { get; set; } + public string max_tokens { get; set; } + public string app_id { get; set; } + public string api_key { get; set; } + public async IAsyncEnumerable SendChatStreamAsync(LlmJsonContent jsonContent) + { + jsonContent.Stream = true; + StringBuilder contentBuilder = new StringBuilder(); + StringBuilder reasonBuilder = new StringBuilder(); + await foreach (LlmStreamChat chunk in HttpRequest.PostWithStreamingResponseAsync( + "https://www.dmxapi.cn/v1/chat/completions", + JsonConvert.SerializeObject(jsonContent), + api_key)) + { + contentBuilder.Append(chunk.Choices[0].Delta.Content); + reasonBuilder.Append(chunk.Choices[0].Delta.ResoningContent); + LlmStreamChat fullChunk = chunk; + fullChunk.Choices[0].Delta.Content = contentBuilder.ToString(); + fullChunk.Choices[0].Delta.ResoningContent = reasonBuilder.ToString(); + yield return fullChunk; + } + } + + public IAsyncEnumerable SendApplicationStreamAsync(string message) + { + throw new System.NotImplementedException(); + } + + public Task SendChatAsync(LlmJsonContent jsonContent) + { + throw new System.NotImplementedException(); + } + + public Task SendApplicationAsync(CommonInput commonInput) + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/host/llm/entity/LlmJsonContent.cs b/host/llm/entity/LlmJsonContent.cs index c38382f..bc53c30 100644 --- a/host/llm/entity/LlmJsonContent.cs +++ b/host/llm/entity/LlmJsonContent.cs @@ -24,7 +24,7 @@ namespace LinkToolAddin.host.llm.entity public int MaxTokens { get; set; } = 2048; [JsonProperty("top_k")] - public int TopK { get; set; } = 40; + public int TopK { get; set; } [JsonProperty("enable_thinking")] public bool EnableThinking { get; set; } = true; diff --git a/ui/dockpane/DialogDockpane.xaml b/ui/dockpane/DialogDockpane.xaml index fd7b7fc..08c5c6c 100644 --- a/ui/dockpane/DialogDockpane.xaml +++ b/ui/dockpane/DialogDockpane.xaml @@ -47,6 +47,13 @@ + + + + + + + diff --git a/ui/dockpane/DialogDockpane.xaml.cs b/ui/dockpane/DialogDockpane.xaml.cs index c969bf7..2777168 100644 --- a/ui/dockpane/DialogDockpane.xaml.cs +++ b/ui/dockpane/DialogDockpane.xaml.cs @@ -234,7 +234,7 @@ namespace LinkToolAddin.ui.dockpane StatusTextBlock.Text = "出现警告信息"; }else if (msg.type == MessageType.ERROR) { - Border border = GetWarningChatBorder(msg); + Border border = GetErrorChatBorder(msg); borderItemsDict[msgId] = border; ChatHistoryStackPanel.Children.Add(border); StatusTextBlock.Text = "出现错误信息"; @@ -588,9 +588,7 @@ namespace LinkToolAddin.ui.dockpane checkButton.Click += ToolCheckButton_OnClick; grid.Children.Add(checkButton); Grid.SetColumn(checkButton, 4); - } - border.Child = grid; return border; }