|
@@ -3,7 +3,6 @@ package chat
|
|
|
import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
- "fmt"
|
|
|
"strconv"
|
|
|
|
|
|
"wechat-api/ent"
|
|
@@ -164,7 +163,21 @@ func (l *ChatCompletionsLogic) appendUsageDetailLog(authToken string, req *types
|
|
|
completionToken := uint64(resp.Usage.CompletionTokens)
|
|
|
totalTokens := promptTokens + completionToken
|
|
|
|
|
|
- fmt.Printf("====>n appendUsageDetailLog:%v|||%T\n", req.Messages[0].Content, req.Messages[0].Content)
|
|
|
+ msgContent := ""
|
|
|
+ switch val := req.Messages[0].Content.(type) {
|
|
|
+ case string:
|
|
|
+ msgContent = val
|
|
|
+ case []map[string]string:
|
|
|
+ msgContent = val[0]["type"]
|
|
|
+ case []interface{}:
|
|
|
+ if len(val) > 0 {
|
|
|
+ if valc, ok := val[0].(map[string]interface{}); ok {
|
|
|
+ if valcc, ok := valc["text"]; ok {
|
|
|
+ msgContent, _ = valcc.(string)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
res, err := l.svcCtx.DB.UsageDetail.Create().
|
|
|
SetNotNilType(&logType).
|
|
@@ -173,6 +186,7 @@ func (l *ChatCompletionsLogic) appendUsageDetailLog(authToken string, req *types
|
|
|
SetNotNilSessionID(&sessionId).
|
|
|
SetNillableApp(&workIdx).
|
|
|
//SetNillableRequest(&req.Messages[0].Content).
|
|
|
+ SetNillableRequest(&msgContent).
|
|
|
SetNillableResponse(&resp.Choices[0].Message.Content).
|
|
|
SetNillableOrganizationID(&orgId).
|
|
|
SetOriginalData(rawReqResp).
|