Răsfoiți Sursa

Merge branch 'master' into debug

* master:
  fixbug
  修改了一处歧义的错误提示
  修改了一个DS返回值差异的问题

# Conflicts:
#	crontask/contact_form.go
#	wechat.go
boweniac 4 zile în urmă
părinte
comite
257d0d18de

+ 2 - 2
cli/asynctask/asynctask.go

@@ -244,7 +244,7 @@ func (me *AsyncTask) requestCallback(taskData *ent.CompapiAsynctask) (int, error
 		return 0, errors.New("callback url empty")
 	}
 	if len(taskData.ResponseRaw) == 0 {
-		return 0, errors.New("call api response empty")
+		return 0, errors.New("previous status call api response empty")
 	}
 
 	/*
@@ -588,7 +588,7 @@ func (me *AsyncTask) batchWork() (int64, int64) {
 		//tasks, err := me.getAsyncReqTaskList()
 		tasks, err := me.getAsyncReqTaskFairList()
 		if err != nil {
-			logx.Errorf("getAsyncReqTaskList err:%s", err)
+			logx.Errorf("getAsyncReqTaskFairList err:%s", err)
 			return
 		}
 

+ 0 - 21
cli/asynctask/etc/asynctask.yaml

@@ -1,21 +0,0 @@
-BatchLoadTask: 200 #每批次取任务数
-MaxWorker: 10       #最大消费者数量
-MaxChannel: 2      #最大消费通道数量
-Debug: false
-
-DatabaseConf: #数据库配置
-  Type: mysql
-  Host: 127.0.0.1
-  Port: 3306
-  DBName: wechat
-  Username: root
-  Password: simple-admin.
-  MaxOpenConn: 100
-  SSLMode: disable
-  CacheTime: 5
-
-RedisConf: #redis配置
-  Host: 127.0.0.1:6379
-
-
-

+ 5 - 1
crontask/contact_form.go

@@ -131,6 +131,10 @@ func (l *CronTask) analyze() {
 	predicates = append(predicates, usagedetail.AppIn(1, 3, 4, 5))
 	//yesterdayStart := time.Now().AddDate(0, 0, -1).Truncate(24 * time.Hour)
 	//yesterdayEnd := yesterdayStart.Add(24 * time.Hour)
+	yesterdayEnd := time.Now().Truncate(24 * time.Hour)
+	yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
+	predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
+	predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
 
 	//yesterdayEnd := time.Now().Truncate(24 * time.Hour)
 	//yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
@@ -169,7 +173,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 {
@@ -196,6 +199,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",

+ 1 - 1
desc/wechat/dashboard.api

@@ -26,7 +26,7 @@ type (
         SopRun *ChartsUint `json:"sop_run"`
         TotalFriend *ChartsUint `json:"total_friend"`
         TotalGroup *ChartsUint `json:"total_group"`
-        AccountBalance *ChartsUint `json:"account_balance"`
+        AccountBalance *ChartsInt `json:"account_balance"`
         ConsumeToken *ChartsUint `json:"consume_token"`
         ActiveUser *ChartsUint `json:"active_user"`
         NewUser *ChartsInt `json:"new_user"`

+ 6 - 2
internal/logic/dashboard/get_charts_logic.go

@@ -114,7 +114,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 	totalFriend.Tip = &totalFriendTip
 	totalGroup := types.ChartsUint{}
 	totalGroup.Tip = &totalGroupTip
-	accountBalance := types.ChartsUint{}
+	accountBalance := types.ChartsInt{}
 	accountBalance.LabelText = "积分"
 	consumeToken := types.ChartsUint{}
 	consumeCoin := types.ChartsFloat{}
@@ -491,7 +491,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			if creditBalance.Balance == 0 {
 				accountBalance.Count = 0
 			} else {
-				accountBalance.Count = uint64(math.Floor(creditBalance.Balance))
+				if creditBalance.Balance >= 0 {
+					accountBalance.Count = int64(math.Ceil(creditBalance.Balance))
+				} else {
+					accountBalance.Count = int64(-math.Ceil(-creditBalance.Balance))
+				}
 			}
 		}
 	}

+ 1 - 1
internal/types/types.go

@@ -3587,7 +3587,7 @@ type ChartsData struct {
 	SopRun         *ChartsUint  `json:"sop_run"`
 	TotalFriend    *ChartsUint  `json:"total_friend"`
 	TotalGroup     *ChartsUint  `json:"total_group"`
-	AccountBalance *ChartsUint  `json:"account_balance"`
+	AccountBalance *ChartsInt   `json:"account_balance"`
 	ConsumeToken   *ChartsUint  `json:"consume_token"`
 	ActiveUser     *ChartsUint  `json:"active_user"`
 	NewUser        *ChartsInt   `json:"new_user"`

+ 11 - 15
internal/utils/compapi/result.go

@@ -52,13 +52,11 @@ func (r *ChatResult) GetContentJsonStr() (string, error) {
 		err = errors.New("choices empty")
 	}
 	if !IsOpenaiModel(r.Model) { //不支持Response Schema的要特殊处理一下
-		var isJsonContent bool
-		content, isJsonContent = ExtractJSONContent(content)
-		if !isJsonContent {
-			return "", errors.New("invalid json content")
+		content, _, err = ExtractJSONContent(content)
+		if err != nil {
+			return "", fmt.Errorf("GCJS ExtractJSONContent err:'%s'", err)
 		}
 	}
-
 	return content, err
 }
 
@@ -71,12 +69,10 @@ func (r *ChatResult) ParseContentAs(target any) error {
 	} else if content == "" {
 		return errors.New("parseContent err: content is empty or unavailable")
 	}
-
 	if !IsOpenaiModel(r.Model) { //不支持Response Schema的要特殊处理一下
-		var isJsonContent bool
-		content, isJsonContent = ExtractJSONContent(content)
-		if !isJsonContent {
-			return errors.New("invalid json content")
+		content, _, err = ExtractJSONContent(content)
+		if err != nil {
+			return fmt.Errorf("PCA ExtractJSONContent err:'%s'", err)
 		}
 	}
 	return ParseContentAs(content, target, false)
@@ -192,20 +188,20 @@ func ParseContentAs(content string, target any, removeJsonBlock bool) error {
 	return nil
 }
 
-func ExtractJSONContent(s string) (string, bool) {
+func ExtractJSONContent(s string) (string, bool, error) {
 	startMarker := "```json"
 	endMarker := "```"
 
 	// 寻找起始标记
 	startIdx := strings.Index(s, startMarker)
 	if startIdx == -1 {
-		return "", false // 没有起始标记
+		return s, false, nil // 没有起始标记就不进行之后步骤
 	}
 
 	// 寻找结束标记(需在起始标记之后查找)
 	endIdx := strings.LastIndex(s, endMarker)
 	if endIdx == -1 || endIdx <= startIdx {
-		return "", false // 没有结束标记或标记顺序错误
+		return s, false, errors.New("lost endMarker") // 没有结束标记或标记顺序错误
 	}
 
 	// 计算内容范围
@@ -217,8 +213,8 @@ func ExtractJSONContent(s string) (string, bool) {
 
 	// 若内容为空视为无效
 	if content == "" {
-		return "", false
+		return s, false, errors.New("empty content")
 	}
 
-	return content, true
+	return content, true, nil
 }