Go: add LLM usage (#17049)

### Summary

```
RAGFlow(api/default)> CHAT WITH 'glm-4-flash@new_test@zhipu-ai' MESSAGE '30 words describes LLM';
Answer: Hello! I'm ChatGLM, an AI assistant. Feel free to ask me any questions or request help with any tasks.
Input tokens: 5
Output tokens: 28
Time: 12.748241
```

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-17 21:28:43 +08:00
committed by GitHub
parent c420de0dc5
commit 8ebdc02cf6
7 changed files with 78 additions and 47 deletions

View File

@@ -19,6 +19,7 @@ package cli
import (
"encoding/json"
"fmt"
"ragflow/internal/entity/models"
"strings"
)
@@ -529,10 +530,11 @@ func (r *MessageResponse) PrintOut() {
}
type NonStreamResponse struct {
Code int `json:"code"`
ReasoningContent string `json:"reasoning_content"`
Answer string `json:"answer"`
Message string `json:"message"`
Code int `json:"code"`
ReasoningContent string `json:"reasoning_content"`
Answer string `json:"answer"`
Message string `json:"message"`
Usage *models.ChatUsage `json:"usage"`
Duration float64
OutputFormat OutputFormat
}
@@ -555,6 +557,10 @@ func (r *NonStreamResponse) PrintOut() {
fmt.Printf("Thinking: %s\n", r.ReasoningContent)
}
fmt.Printf("Answer: %s\n", r.Answer)
if r.Usage != nil {
fmt.Printf("Input tokens: %v\n", r.Usage.PromptTokens)
fmt.Printf("Output tokens: %v\n", r.Usage.CompletionTokens)
}
fmt.Printf("Time: %f\n", r.Duration)
} else {
fmt.Println("ERROR")