Spaces:
Paused
Paused
Download internal/runtime/executor/usage_helpers_test.go from shimen/shinmenapi: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/shimen/shinmenapi/resolve/main/internal/runtime/executor/usage_helpers_test.go
- Command line
-
hf download hf://spaces/shimen/shinmenapi/internal/runtime/executor/usage_helpers_test.go
-
curl -L -o usage_helpers_test.go https://huggingface.co/spaces/shimen/shinmenapi/resolve/main/internal/runtime/executor/usage_helpers_test.go
1.59 kB
| package executor | |
| import "testing" | |
| func TestParseOpenAIUsageChatCompletions(t *testing.T) { | |
| data := []byte(`{"usage":{"prompt_tokens":1,"completion_tokens":2,"total_tokens":3,"prompt_tokens_details":{"cached_tokens":4},"completion_tokens_details":{"reasoning_tokens":5}}}`) | |
| detail := parseOpenAIUsage(data) | |
| if detail.InputTokens != 1 { | |
| t.Fatalf("input tokens = %d, want %d", detail.InputTokens, 1) | |
| } | |
| if detail.OutputTokens != 2 { | |
| t.Fatalf("output tokens = %d, want %d", detail.OutputTokens, 2) | |
| } | |
| if detail.TotalTokens != 3 { | |
| t.Fatalf("total tokens = %d, want %d", detail.TotalTokens, 3) | |
| } | |
| if detail.CachedTokens != 4 { | |
| t.Fatalf("cached tokens = %d, want %d", detail.CachedTokens, 4) | |
| } | |
| if detail.ReasoningTokens != 5 { | |
| t.Fatalf("reasoning tokens = %d, want %d", detail.ReasoningTokens, 5) | |
| } | |
| } | |
| func TestParseOpenAIUsageResponses(t *testing.T) { | |
| data := []byte(`{"usage":{"input_tokens":10,"output_tokens":20,"total_tokens":30,"input_tokens_details":{"cached_tokens":7},"output_tokens_details":{"reasoning_tokens":9}}}`) | |
| detail := parseOpenAIUsage(data) | |
| if detail.InputTokens != 10 { | |
| t.Fatalf("input tokens = %d, want %d", detail.InputTokens, 10) | |
| } | |
| if detail.OutputTokens != 20 { | |
| t.Fatalf("output tokens = %d, want %d", detail.OutputTokens, 20) | |
| } | |
| if detail.TotalTokens != 30 { | |
| t.Fatalf("total tokens = %d, want %d", detail.TotalTokens, 30) | |
| } | |
| if detail.CachedTokens != 7 { | |
| t.Fatalf("cached tokens = %d, want %d", detail.CachedTokens, 7) | |
| } | |
| if detail.ReasoningTokens != 9 { | |
| t.Fatalf("reasoning tokens = %d, want %d", detail.ReasoningTokens, 9) | |
| } | |
| } | |