- 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
515 B
Go
23 lines
515 B
Go
package ai
|
|
|
|
import "testing"
|
|
|
|
func TestSpendStatusCostRemaining(t *testing.T) {
|
|
limit := int64(10_000_000)
|
|
status := SpendStatus{
|
|
CostUsedTodayMicroEUR: 4_000_000,
|
|
CostLimitTodayMicroEUR: &limit,
|
|
Currency: "EUR",
|
|
}
|
|
remaining := *status.CostLimitTodayMicroEUR - status.CostUsedTodayMicroEUR
|
|
if remaining != 6_000_000 {
|
|
t.Fatalf("cost remaining = %d", remaining)
|
|
}
|
|
}
|
|
|
|
func TestErrQuotaExceeded(t *testing.T) {
|
|
if ErrQuotaExceeded.Error() == "" {
|
|
t.Fatal("expected error message")
|
|
}
|
|
}
|