feat: comprehensive token usage tracking for V2
Add provider-specific usage details, fix streaming usage, and return usage from all high-level APIs (Chat.Send, Generate[T], Agent.Run). Breaking changes: - Chat.Send/SendMessage/SendWithImages now return (string, *Usage, error) - Generate[T]/GenerateWith[T] now return (T, *Usage, error) - Agent.Run/RunMessages now return (string, *Usage, error) New features: - Usage.Details map for provider-specific token breakdowns (reasoning, cached, audio, thoughts tokens) - OpenAI streaming now captures usage via StreamOptions.IncludeUsage - Google streaming now captures UsageMetadata from final chunk - UsageTracker.Details() for accumulated detail totals - ModelPricing and PricingRegistry for cost computation Closes #2 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@ func Example_researcher() {
|
||||
agent.WithRequestOptions(llm.WithTemperature(0.3)),
|
||||
)
|
||||
|
||||
result, err := researcher.Run(context.Background(), "What are the latest developments in Go generics?")
|
||||
result, _, err := researcher.Run(context.Background(), "What are the latest developments in Go generics?")
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
@@ -50,7 +50,7 @@ func Example_coder() {
|
||||
)),
|
||||
)
|
||||
|
||||
result, err := coder.Run(context.Background(),
|
||||
result, _, err := coder.Run(context.Background(),
|
||||
"Create a Go program that prints the first 10 Fibonacci numbers. Save it and run it.")
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
@@ -97,7 +97,7 @@ func Example_orchestrator() {
|
||||
)),
|
||||
)
|
||||
|
||||
result, err := orchestrator.Run(context.Background(),
|
||||
result, _, err := orchestrator.Run(context.Background(),
|
||||
"Research how to implement a binary search tree in Go, then create one with insert and search operations.")
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
|
||||
Reference in New Issue
Block a user