Add debug stats

This commit is contained in:
dwrz
2026-06-27 00:13:16 +00:00
parent bcdbd9092a
commit f2edd39160
8 changed files with 553 additions and 28 deletions

View File

@@ -59,11 +59,41 @@ type ChatRequest struct {
ServiceTier string `json:"service_tier,omitempty"`
}
// Usage represents token usage from the API response.
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
PromptTokensDetails *TokenDetails `json:"prompt_tokens_details,omitempty"`
CompletionTokensDetails *TokenDetails `json:"completion_tokens_details,omitempty"`
}
// TokenDetails breaks down token usage by category.
type TokenDetails struct {
ReasoningTokens int `json:"reasoning_tokens,omitempty"`
CachedTokens int `json:"cached_tokens,omitempty"`
}
// Timings is a llama.cpp-specific extension to the chat completion
// response. It is not part of the OpenAI API spec.
type Timings struct {
PromptN int `json:"prompt_n"`
PromptMS float64 `json:"prompt_ms"`
PromptPerTokenMS float64 `json:"prompt_per_token_ms"`
PromptPerSecond float64 `json:"prompt_per_second"`
PredictedN int `json:"predicted_n"`
PredictedMS float64 `json:"predicted_ms"`
PredictedPerTokenMS float64 `json:"predicted_per_token_ms"`
PredictedPerSecond float64 `json:"predicted_per_second"`
}
// ChatResponse is the non-streaming response from the API.
type ChatResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
Timings *Timings `json:"timings,omitempty"`
}
// Choice is a single choice in a ChatResponse.
@@ -246,6 +276,8 @@ type StreamChunk struct {
Delta Delta `json:"delta"`
FinishReason string `json:"finish_reason,omitempty"`
} `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
Timings *Timings `json:"timings,omitempty"`
}
// StreamOptions controls streaming behavior.