mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-19 22:21:04 +08:00
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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user