feat(*): 模型生成链路 - 完善 Agnes 结果兼容、价格展示与请求日志追踪

This commit is contained in:
ddCat committed 2026-08-28 06:53:57 +08:00
1 parent 2c02f5ef3d
commit bd0d0fd4fd
20 files changed
+671 -108

No files matched your search

@@ -2,6 +2,7 @@ package service
import (
"encoding/json"
"strings"
"testing"
"infinite-canvas/backend/internal/model"
@@ -85,6 +86,24 @@ func TestEnrichAPICallLogReadsArkVideoUsage(t *testing.T) {
}
}
func TestEnrichAPICallLogKeepsUserFacingAndUpstreamFailureDetails(t *testing.T) {
log := &model.ApiCallLog{
Status: model.ApiCallStatusFailed,
StatusCode: 400,
Error: "上游 HTTP 400",
}
(&Service{}).EnrichAPICallLog(log, []byte(`{"error":{"code":"invalid_request","message":"invalid parameter: size"}}`))
if !strings.Contains(log.Error, "模型服务拒绝了请求,请检查模型和参数") {
t.Fatalf("EnrichAPICallLog() missing user-facing category: %q", log.Error)
}
if !strings.Contains(log.Error, "invalid parameter: size") {
t.Fatalf("EnrichAPICallLog() missing upstream detail: %q", log.Error)
}
if log.ErrorCode != "invalid_request" {
t.Fatalf("EnrichAPICallLog() error code = %q", log.ErrorCode)
}
}
func TestEnrichAPICallLogReadsChatCompletionStreamUsage(t *testing.T) {
log := &model.ApiCallLog{Capability: "text", Path: "/v1/chat/completions"}
stream := []byte("data: {\"id\":\"chatcmpl-test\",\"choices\":[{\"delta\":{\"content\":\"ok\"}}]}\n\n" +