修复回答状态显示异常问题

This commit is contained in:
PeterZhong 2025-06-08 15:48:41 +08:00
parent d0b6671cce
commit 9b600174e8
2 changed files with 23 additions and 12 deletions

View File

@ -268,7 +268,7 @@ public class Gateway
while (goOn) while (goOn)
{ {
loop++; loop++;
if (loop > 20) if (loop > 500)
{ {
MessageBox.Show("达到最大循环次数", "退出循环"); MessageBox.Show("达到最大循环次数", "退出循环");
break; break;
@ -277,8 +277,9 @@ public class Gateway
{ {
Model = model, Model = model,
Messages = messages, Messages = messages,
Temperature = 0.7, Temperature = 0.3,
TopP = 1, TopP = 0.4,
TopK = 7,
MaxTokens = 1000, MaxTokens = 1000,
}; };
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@ -317,7 +318,6 @@ public class Gateway
callback?.Invoke(endMessageListItem2); callback?.Invoke(endMessageListItem2);
break; break;
} }
try try
{ {
string chunk = llmStreamChat.Choices[0].Delta.Content; string chunk = llmStreamChat.Choices[0].Delta.Content;
@ -529,11 +529,16 @@ 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;
string displayToolName = toolName;
if (displayToolName == "ArcGisProTool")
{
displayToolName = "【GP】"+toolParams["toolName"].ToString();
}
if (innerResult is JsonRpcErrorEntity) if (innerResult is JsonRpcErrorEntity)
{ {
MessageListItem toolMessageItem = new ToolMessageItem MessageListItem toolMessageItem = new ToolMessageItem
{ {
toolName = toolName, toolName = displayToolName,
toolParams = toolParams, toolParams = toolParams,
type = MessageType.TOOL_MESSAGE, type = MessageType.TOOL_MESSAGE,
status = "fail", status = "fail",
@ -556,7 +561,7 @@ public class Gateway
{ {
MessageListItem toolMessageItem = new ToolMessageItem MessageListItem toolMessageItem = new ToolMessageItem
{ {
toolName = toolName, toolName = displayToolName,
toolParams = toolParams, toolParams = toolParams,
type = MessageType.TOOL_MESSAGE, type = MessageType.TOOL_MESSAGE,
status = "success", status = "success",
@ -631,8 +636,10 @@ public class Gateway
private static async Task<string> GetToolInfos(McpServerList mcpServerList) private static async Task<string> GetToolInfos(McpServerList mcpServerList)
{ {
StringBuilder toolInfos = new StringBuilder(); StringBuilder toolInfos = new StringBuilder();
int i = 0;
foreach (McpServer mcpServer in mcpServerList.GetAllServers()) foreach (McpServer mcpServer in mcpServerList.GetAllServers())
{ {
i++;
try try
{ {
if (mcpServer is InnerMcpServer) if (mcpServer is InnerMcpServer)
@ -708,6 +715,7 @@ public class Gateway
}catch (Exception e) }catch (Exception e)
{ {
log.Error(e.Message); log.Error(e.Message);
MessageBox.Show(e.Message, $"第{i}MCP读取错误");
} }
} }
@ -723,6 +731,7 @@ public class Gateway
catch (Exception e) catch (Exception e)
{ {
log.Error(e.Message); log.Error(e.Message);
MessageBox.Show(e.Message, $"{userPrompt.Name}提示词读取错误");
} }
} }
return toolInfos.ToString(); return toolInfos.ToString();

View File

@ -178,6 +178,10 @@ 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);
@ -212,9 +216,6 @@ 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 = "";
} }
} }
} }
@ -224,6 +225,10 @@ namespace LinkToolAddin.ui.dockpane
messageDict[msgId] = msg; messageDict[msgId] = msg;
if (msg.content == "") if (msg.content == "")
{ {
if (msg.type == MessageType.END_TAG)
{
StatusTextBlock.Text = "";
}
ChatHistoryStackPanel.Children.Remove(borderItemsDict[msgId]); ChatHistoryStackPanel.Children.Remove(borderItemsDict[msgId]);
borderItemsDict.TryRemove(msgId, out Border border); borderItemsDict.TryRemove(msgId, out Border border);
messageDict.TryRemove(msgId, out MessageListItem tempMsg); messageDict.TryRemove(msgId, out MessageListItem tempMsg);
@ -263,9 +268,6 @@ 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 = "";
} }
} }
} }