|
@@ -163,7 +163,6 @@ func (l *CronTask) analyze() {
|
|
|
}
|
|
|
usageDetails[u.BotID][u.ReceiverID] += fmt.Sprintf("用户:%s\n机器人:%s\n", u.Request, u.Response)
|
|
|
}
|
|
|
- logx.Info("contactFieldTemplates: ", contactFieldTemplates)
|
|
|
logx.Info("usageDetails: ", usageDetails)
|
|
|
for botID, template := range contactFieldTemplates {
|
|
|
if template == nil {
|
|
@@ -190,6 +189,7 @@ func (l *CronTask) openaiRequest(messages string, template []custom_types.Contac
|
|
|
return nil, err
|
|
|
}
|
|
|
jsonStr := string(jsonBytes)
|
|
|
+ logx.Info("contactFieldTemplates: ", jsonStr)
|
|
|
req := &types.CompApiReq{
|
|
|
types.CompCtlReq{
|
|
|
"form",
|
|
@@ -218,13 +218,27 @@ func (l *CronTask) openaiRequest(messages string, template []custom_types.Contac
|
|
|
resp, err := compapi.NewClient(l.ctx, compapi.WithApiBase("http://new-api.gkscrm.com/v1/"),
|
|
|
compapi.WithApiKey("sk-wwttAtdLcTfeF7F2Eb9d3592Bd4c487f8e8fA544D6C4BbA9")).
|
|
|
Chat(req)
|
|
|
+ logx.Info("resp: ", resp)
|
|
|
if err == nil && resp != nil && len(resp.Choices) > 0 {
|
|
|
- //logx.Info("resp.Choices: ", resp.Choices[0].Message.Content)
|
|
|
+ logx.Info("resp.Choices: ", resp.Choices[0].Message.Content)
|
|
|
+ // 尝试第一层解析成 string
|
|
|
+ var inner string
|
|
|
+ if err := json.Unmarshal([]byte(resp.Choices[0].Message.Content), &inner); err == nil {
|
|
|
+ // 成功表示 data 是个被编码过的 JSON 字符串
|
|
|
+ resp.Choices[0].Message.Content = inner
|
|
|
+ }
|
|
|
+ // 解析最终目标
|
|
|
var items []ResponseItem
|
|
|
- err = json.Unmarshal([]byte(resp.Choices[0].Message.Content), &items)
|
|
|
+ err := json.Unmarshal([]byte(resp.Choices[0].Message.Content), &items)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+
|
|
|
+ //var items []ResponseItem
|
|
|
+ //err = json.Unmarshal([]byte(resp.Choices[0].Message.Content), &items)
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, err
|
|
|
+ //}
|
|
|
return items, nil
|
|
|
} else if resp != nil && len(resp.Choices) == 0 {
|
|
|
return nil, err
|