implemented /clear and Ctrl+D and thinking

This commit is contained in:
Luxferre
2026-03-22 17:16:58 +02:00
parent 10fa5def68
commit 359afa64f4
5 changed files with 43 additions and 14 deletions
+17 -3
View File
@@ -148,6 +148,7 @@ func (s *standardLLMClient) handleStream(body io.ReadCloser, streamCallback,
reasoningCallback func(string)) (Message, error) {
defer body.Close()
var fullContent strings.Builder
var fullReasoning strings.Builder
var finalMsg Message
finalMsg.Role = MessageRoleAssistant
@@ -178,14 +179,26 @@ func (s *standardLLMClient) handleStream(body io.ReadCloser, streamCallback,
var chunk struct {
Choices []struct {
Delta struct {
Content string `json:"content"`
ToolCalls []deltaToolCall `json:"tool_calls"`
Content string `json:"content"`
ReasoningContent string `json:"reasoning_content"`
Reasoning string `json:"reasoning"`
ToolCalls []deltaToolCall `json:"tool_calls"`
} `json:"delta"`
} `json:"choices"`
}
if err := json.Unmarshal([]byte(data), &chunk); err == nil && len(chunk.Choices) > 0 {
delta := chunk.Choices[0].Delta
if delta.Content != "" {
rContent := delta.ReasoningContent
if rContent == "" {
rContent = delta.Reasoning
}
if rContent != "" && reasoningCallback != nil {
fullReasoning.WriteString(rContent)
reasoningCallback(rContent)
}
if delta.Content != "" && streamCallback != nil {
fullContent.WriteString(delta.Content)
streamCallback(delta.Content)
}
@@ -206,6 +219,7 @@ func (s *standardLLMClient) handleStream(body io.ReadCloser, streamCallback,
}
finalMsg.Content = fullContent.String()
finalMsg.Reasoning = fullReasoning.String()
if maxIndex >= 0 {
for i := 0; i <= maxIndex; i++ {
if tc, ok := toolCallsMap[i]; ok {