接入DmxApi新增国外模型
This commit is contained in:
parent
ca807080b6
commit
0a4ed9ee6b
@ -26,6 +26,7 @@
|
|||||||
<button refID="DialogDockpane_ShowButton" size="large" />
|
<button refID="DialogDockpane_ShowButton" size="large" />
|
||||||
<button refID="Version_Button" size="large" />
|
<button refID="Version_Button" size="large" />
|
||||||
<button refID="LinkToolAddin_ui_dockpane_TestDockpane_ShowButton" size="large" />
|
<button refID="LinkToolAddin_ui_dockpane_TestDockpane_ShowButton" size="large" />
|
||||||
|
<button refID="LinkToolAddin_ui_mcp_McpConfigWindow" size="large" />
|
||||||
</group>
|
</group>
|
||||||
<group id="PreferenceGroup" caption="设置项" appearsOnAddInTab="false">
|
<group id="PreferenceGroup" caption="设置项" appearsOnAddInTab="false">
|
||||||
<button refID="Preference_Button" size="large" />
|
<button refID="Preference_Button" size="large" />
|
||||||
@ -44,6 +45,9 @@
|
|||||||
<button id="LinkToolAddin_ui_dockpane_TestDockpane_ShowButton" caption="测试面板" className="LinkToolAddin.ui.dockpane.TestDockpane_ShowButton" loadOnClick="true" smallImage="GenericButtonPurple16" largeImage="GenericButtonPurple32">
|
<button id="LinkToolAddin_ui_dockpane_TestDockpane_ShowButton" caption="测试面板" className="LinkToolAddin.ui.dockpane.TestDockpane_ShowButton" loadOnClick="true" smallImage="GenericButtonPurple16" largeImage="GenericButtonPurple32">
|
||||||
<tooltip heading="测试面板">打开测试面板<disabledText /></tooltip>
|
<tooltip heading="测试面板">打开测试面板<disabledText /></tooltip>
|
||||||
</button>
|
</button>
|
||||||
|
<button id="LinkToolAddin_ui_mcp_McpConfigWindow" caption="McpConfigWindow" className="LinkToolAddin.ui.mcp.ShowMcpConfigWindow" loadOnClick="true" smallImage="GenericButtonPurple16" largeImage="GenericButtonPurple32">
|
||||||
|
<tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
|
||||||
|
</button>
|
||||||
</controls>
|
</controls>
|
||||||
<dockPanes>
|
<dockPanes>
|
||||||
<dockPane id="DialogDockpane" caption="LinkTool" className="LinkToolAddin.ui.dockpane.DialogDockpaneViewModel" dock="group" dockWith="esri_core_projectDockPane">
|
<dockPane id="DialogDockpane" caption="LinkTool" className="LinkToolAddin.ui.dockpane.DialogDockpaneViewModel" dock="group" dockWith="esri_core_projectDockPane">
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"LinkToolAddin": {
|
"LinkToolAddin": {
|
||||||
"commandName": "Executable",
|
"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",
|
"applicationUrl": "https://localhost:5001",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
|||||||
@ -238,10 +238,43 @@ public class Gateway
|
|||||||
|
|
||||||
public static async void SendMessageStream(string message, string model, string gdbPath, Action<MessageListItem> callback)
|
public static async void SendMessageStream(string message, string model, string gdbPath, Action<MessageListItem> callback)
|
||||||
{
|
{
|
||||||
Llm bailian = new Bailian
|
Llm modelObj = new Bailian();
|
||||||
|
List<string> bailianModels = [];
|
||||||
|
List<string> 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<Message> messages = new List<Message>();
|
List<Message> messages = new List<Message>();
|
||||||
string toolInfos = "";
|
string toolInfos = "";
|
||||||
try
|
try
|
||||||
@ -268,6 +301,14 @@ public class Gateway
|
|||||||
role = "system"
|
role = "system"
|
||||||
};
|
};
|
||||||
callback?.Invoke(endMessageListItem2);
|
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列表失败");
|
// MessageBox.Show(ex.Message,"获取MCP列表失败");
|
||||||
}
|
}
|
||||||
goOn = true;
|
goOn = true;
|
||||||
@ -293,6 +334,14 @@ public class Gateway
|
|||||||
role = "system"
|
role = "system"
|
||||||
};
|
};
|
||||||
callback?.Invoke(endMessageListItem2);
|
callback?.Invoke(endMessageListItem2);
|
||||||
|
MessageListItem endMessageListItem1 = new ChatMessageItem
|
||||||
|
{
|
||||||
|
type = MessageType.END_TAG,
|
||||||
|
content = "",
|
||||||
|
id = (timestamp + 3).ToString(),
|
||||||
|
role = "assistant"
|
||||||
|
};
|
||||||
|
callback?.Invoke(endMessageListItem1);
|
||||||
// MessageBox.Show("达到最大循环次数", "退出循环");
|
// MessageBox.Show("达到最大循环次数", "退出循环");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -302,7 +351,6 @@ public class Gateway
|
|||||||
Messages = messages,
|
Messages = messages,
|
||||||
Temperature = 0.3,
|
Temperature = 0.3,
|
||||||
TopP = 0.4,
|
TopP = 0.4,
|
||||||
TopK = 7,
|
|
||||||
MaxTokens = 1000,
|
MaxTokens = 1000,
|
||||||
};
|
};
|
||||||
List<McpToolRequest> mcpToolRequests = new List<McpToolRequest>();
|
List<McpToolRequest> mcpToolRequests = new List<McpToolRequest>();
|
||||||
@ -326,7 +374,7 @@ public class Gateway
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await foreach(LlmStreamChat llmStreamChat in bailian.SendChatStreamAsync(jsonContent))
|
await foreach(LlmStreamChat llmStreamChat in modelObj.SendChatStreamAsync(jsonContent))
|
||||||
{
|
{
|
||||||
if (!goOn)
|
if (!goOn)
|
||||||
{
|
{
|
||||||
@ -465,6 +513,14 @@ public class Gateway
|
|||||||
role = "system"
|
role = "system"
|
||||||
};
|
};
|
||||||
callback?.Invoke(endMessageListItem2);
|
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, "请求大模型出错");
|
// MessageBox.Show(e.Message, "请求大模型出错");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using LinkToolAddin.host.mcp;
|
using LinkToolAddin.host.mcp;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace LinkToolAddin.host;
|
namespace LinkToolAddin.host;
|
||||||
|
|
||||||
@ -85,6 +86,11 @@ public class McpServerList
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public McpServerList(string json)
|
||||||
|
{
|
||||||
|
servers = JsonConvert.DeserializeObject<Dictionary<string, McpServer>>(json);
|
||||||
|
}
|
||||||
|
|
||||||
public McpServer GetServer(string name)
|
public McpServer GetServer(string name)
|
||||||
{
|
{
|
||||||
if (servers.ContainsKey(name))
|
if (servers.ContainsKey(name))
|
||||||
|
|||||||
52
host/llm/DmxApi.cs
Normal file
52
host/llm/DmxApi.cs
Normal file
@ -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<LlmStreamChat> 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<string> SendApplicationStreamAsync(string message)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> SendChatAsync(LlmJsonContent jsonContent)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> SendApplicationAsync(CommonInput commonInput)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,7 +24,7 @@ namespace LinkToolAddin.host.llm.entity
|
|||||||
public int MaxTokens { get; set; } = 2048;
|
public int MaxTokens { get; set; } = 2048;
|
||||||
|
|
||||||
[JsonProperty("top_k")]
|
[JsonProperty("top_k")]
|
||||||
public int TopK { get; set; } = 40;
|
public int TopK { get; set; }
|
||||||
|
|
||||||
[JsonProperty("enable_thinking")]
|
[JsonProperty("enable_thinking")]
|
||||||
public bool EnableThinking { get; set; } = true;
|
public bool EnableThinking { get; set; } = true;
|
||||||
|
|||||||
@ -47,6 +47,13 @@
|
|||||||
<ComboBoxItem Content="deepseek-r1-distill-qwen-32b" />
|
<ComboBoxItem Content="deepseek-r1-distill-qwen-32b" />
|
||||||
<ComboBoxItem Content="deepseek-r1-distill-llama-70b" />
|
<ComboBoxItem Content="deepseek-r1-distill-llama-70b" />
|
||||||
<ComboBoxItem Content="deepseek-v3" />
|
<ComboBoxItem Content="deepseek-v3" />
|
||||||
|
<Separator></Separator>
|
||||||
|
<ComboBoxItem Content="gpt-4o" />
|
||||||
|
<ComboBoxItem Content="claude-sonnet-4-20250514-thinking" />
|
||||||
|
<ComboBoxItem Content="claude-sonnet-4-20250514" />
|
||||||
|
<ComboBoxItem Content="grok-3-reasoner" />
|
||||||
|
<ComboBoxItem Content="gemini-2.5-pro" />
|
||||||
|
<Separator></Separator>
|
||||||
<ComboBoxItem Content="自定义" />
|
<ComboBoxItem Content="自定义" />
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@ -234,7 +234,7 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
StatusTextBlock.Text = "出现警告信息";
|
StatusTextBlock.Text = "出现警告信息";
|
||||||
}else if (msg.type == MessageType.ERROR)
|
}else if (msg.type == MessageType.ERROR)
|
||||||
{
|
{
|
||||||
Border border = GetWarningChatBorder(msg);
|
Border border = GetErrorChatBorder(msg);
|
||||||
borderItemsDict[msgId] = border;
|
borderItemsDict[msgId] = border;
|
||||||
ChatHistoryStackPanel.Children.Add(border);
|
ChatHistoryStackPanel.Children.Add(border);
|
||||||
StatusTextBlock.Text = "出现错误信息";
|
StatusTextBlock.Text = "出现错误信息";
|
||||||
@ -588,9 +588,7 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
checkButton.Click += ToolCheckButton_OnClick;
|
checkButton.Click += ToolCheckButton_OnClick;
|
||||||
grid.Children.Add(checkButton);
|
grid.Children.Add(checkButton);
|
||||||
Grid.SetColumn(checkButton, 4);
|
Grid.SetColumn(checkButton, 4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
border.Child = grid;
|
border.Child = grid;
|
||||||
return border;
|
return border;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user