💄 Optimize function call records

This commit is contained in:
2025-10-26 18:47:42 +08:00
parent 437f49fb20
commit befde25266

View File

@@ -119,19 +119,23 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service)
{ Type = StreamingContentType.Text, Data = new() { ["text"] = textContent.Text ?? "" } }, { Type = StreamingContentType.Text, Data = new() { ["text"] = textContent.Text ?? "" } },
StreamingReasoningContent reasoningContent => new SnThinkingChunk StreamingReasoningContent reasoningContent => new SnThinkingChunk
{ {
Type = StreamingContentType.Reasoning, Data = new() { ["text"] = reasoningContent.Text ?? "" } Type = StreamingContentType.Reasoning, Data = new() { ["text"] = reasoningContent.Text }
},
StreamingFunctionCallUpdateContent functionCall => new SnThinkingChunk
{
Type = StreamingContentType.FunctionCall,
Data = JsonSerializer.Deserialize<Dictionary<string, object>>(
JsonSerializer.Serialize(functionCall)) ?? new()
}, },
StreamingFunctionCallUpdateContent functionCall => string.IsNullOrEmpty(functionCall.CallId)
? null
: new SnThinkingChunk
{
Type = StreamingContentType.FunctionCall,
Data = JsonSerializer.Deserialize<Dictionary<string, object>>(
JsonSerializer.Serialize(functionCall)) ?? new Dictionary<string, object>()
},
_ => new SnThinkingChunk _ => new SnThinkingChunk
{ {
Type = StreamingContentType.Unknown, Data = new() { ["data"] = JsonSerializer.Serialize(item) } Type = StreamingContentType.Unknown, Data = new() { ["data"] = JsonSerializer.Serialize(item) }
} }
}; };
if (streamingChunk == null) continue;
thinkingChunks.Add(streamingChunk); thinkingChunks.Add(streamingChunk);
var messageJson = item switch var messageJson = item switch
@@ -139,7 +143,7 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service)
StreamingTextContent textContent => StreamingTextContent textContent =>
JsonSerializer.Serialize(new { type = "text", data = textContent.Text ?? "" }), JsonSerializer.Serialize(new { type = "text", data = textContent.Text ?? "" }),
StreamingReasoningContent reasoningContent => StreamingReasoningContent reasoningContent =>
JsonSerializer.Serialize(new { type = "reasoning", data = reasoningContent.Text ?? "" }), JsonSerializer.Serialize(new { type = "reasoning", data = reasoningContent.Text }),
StreamingFunctionCallUpdateContent functionCall => StreamingFunctionCallUpdateContent functionCall =>
JsonSerializer.Serialize(new { type = "function_call", data = functionCall }), JsonSerializer.Serialize(new { type = "function_call", data = functionCall }),
_ => _ =>