- Refactored AI gateway to utilize new cost management structures for usage tracking. - Replaced deprecated token extraction methods with a unified cost parsing approach. - Enhanced usage fallback mechanisms and introduced detailed usage metrics in responses. - Added new metering functionality to record AI usage and costs effectively. - Updated tests to reflect changes in usage parsing and cost calculations. - Introduced new API endpoints for retrieving AI usage summaries and pricing information.
23 lines
518 B
Go
23 lines
518 B
Go
package ai
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/ai/cost"
|
|
)
|
|
|
|
func TestParseUsageViaCost(t *testing.T) {
|
|
payload := []byte(`{"usage":{"total_tokens":42,"completion_tokens":10}}`)
|
|
u := cost.ParseUsage(payload)
|
|
if u.TotalTokens != 42 {
|
|
t.Fatalf("ParseUsage() = %d, want 42", u.TotalTokens)
|
|
}
|
|
}
|
|
|
|
func TestParseUsageFallback(t *testing.T) {
|
|
u := cost.ParseUsage([]byte(`{"choices":[]}`))
|
|
if u.TotalTokens != 1 {
|
|
t.Fatalf("expected fallback token count 1, got %d", u.TotalTokens)
|
|
}
|
|
}
|