Просмотр исходного кода

Merge branch 'master' into debug

* master:
  去掉多余变量
  fixbug
  调整定时任务
  调整定时任务时间
  适配新的规范

# Conflicts:
#	crontask/contact_form.go
#	internal/utils/compapi/form.go
boweniac 15 часов назад
Родитель
Сommit
057b1a457d

+ 6 - 2
crontask/send_wx.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"github.com/zeromicro/go-zero/core/logx"
 	"regexp"
 	"strconv"
 	"strings"
@@ -149,9 +150,12 @@ func (l *CronTask) sendWx() {
 				l.svcCtx.Rds.Set(l.ctx, fmt.Sprintf("MsgId_FriendId:%d", msgId), v.ContactWxid, 10*time.Minute)
 				err = hookClient.SendTextMsg(v.ContactWxid, content, v.BotWxid, msgId)
 			} else {
+				content := v.Content
 				re := regexp.MustCompile(`[^/]+$`)
-				fileName := re.FindString(v.Content)
-				err = hookClient.SendPicMsg(v.ContactWxid, v.Content, fileName, v.BotWxid)
+				fileName := re.FindString(content)
+				logx.Info("SendPicMsg content: ", content)
+				logx.Info("SendPicMsg fileName: ", fileName)
+				err = hookClient.SendPicMsg(v.ContactWxid, content, fileName, v.BotWxid)
 			}
 
 			if err != nil {

+ 1 - 1
hook/message.go

@@ -132,7 +132,7 @@ func (h *Hook) SendTextMsg(wxid, msg, wxWxid string, msgId int64) error {
 
 // SendPicMsg 发送微信图片
 func (h *Hook) SendPicMsg(wxid, picpath, diyfilename, wxWxid string) (err error) {
-	if h.ServerIp == "" {
+	if h.ServerIp == "" || h.ServerIp == "0" {
 		conn, err := h.connWorkPhone()
 		if err != nil {
 			err = fmt.Errorf("SendPicMsg failed")

+ 2 - 58
internal/logic/sop_task/get_sop_message_var_logic.go

@@ -31,75 +31,19 @@ func (l *GetSopMessageVarLogic) GetSopMessageVar() (resp *types.MessageVarResp,
 			Value: "nickname",
 		},
 		{
-			Label: "姓名",
-			Value: "cname",
-		},
-		{
-			Label: "称呼",
-			Value: "ctitle",
-		},
-		{
-			Label: "身份证号",
-			Value: "cidcard_no",
-		},
-		{
-			Label: "地区",
-			Value: "carea",
-		},
-		{
-			Label: "籍贯",
-			Value: "cbirtharea",
-		},
-		{
-			Label: "出生日期",
-			Value: "cbirthday",
-		},
-		{
 			Label: "性别",
 			Value: "sex",
 		},
-		{
-			Label: "年龄",
-			Value: "cage",
-		},
 	}
 	resp.Data.ForwardVar = []types.MessageVarInfo{
 		{
-			Label: "昵称",
+			Label: "联系人昵称",
 			Value: "nickname",
 		},
 		{
-			Label: "姓名",
-			Value: "cname",
-		},
-		{
-			Label: "称呼",
-			Value: "ctitle",
-		},
-		{
-			Label: "身份证号",
-			Value: "cidcard_no",
-		},
-		{
-			Label: "地区",
-			Value: "carea",
-		},
-		{
-			Label: "籍贯",
-			Value: "cbirtharea",
-		},
-		{
-			Label: "出生日期",
-			Value: "cbirthday",
-		},
-		{
-			Label: "性别",
+			Label: "联系人性别",
 			Value: "sex",
 		},
-		{
-			Label: "年龄",
-			Value: "cage",
-		},
 	}
 
 	return resp, nil

+ 46 - 61
internal/utils/compapi/form.go

@@ -3,55 +3,23 @@ package compapi
 import (
 	"time"
 	"wechat-api/internal/types"
-
-	"github.com/openai/openai-go"
 )
 
 type FormClient struct {
-	StdClient
-}
-
-// Generate the JSON schema at initialization time
-var FormResponseSchema = GenerateSchema[FormList]()
-
-type FormResponse struct {
-	DataIndex string   `json:"dataIndex" jsonschema_description:"表单 id"`
-	Value     []string `json:"value" jsonschema_description:" 值列表"`
-}
-
-type FormList struct {
-	Values []FormResponse `json:"values" jsonschema_description:"表单列表"`
+	MismatchClient
 }
 
-/*
-
-"response_format":{"type":"json_object"}}
-
-{"type":"json_schema",
-	"json_schema":{
-		"description":"从通话记录中提取表单","name":"keyword_schema","schema":{
-			"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{
-			"keywords":{
-				"description":"关键词库","items":{"type":"string"},"type":"array"},"regular":{"description":"正则表达式","items":{"type":"string"},"type":"array"},"similar_reply":{"description":"类似回复","items":{"type":"string"},"type":"array"},"swear_words":{"description":"脏话列表","items":{"type":"string"},"type":"array"},"user_intent":{"description":"用户意图","type":"string"},"user_mood":{"description":"用户情绪","type":"string"}},"required":["user_intent","similar_reply","keywords","regular","user_mood","swear_words"],"type":"object"},"strict":true}}
-*/
-
-func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
+func (me *FormClient) ResponseFormatSetting(req *types.CompApiReq) ResponseFormatConfig {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	weekday := time.Now().Weekday().String()
-	//bytes, err := json.Marshal(req.Variables["form_data"])
-	//if err != nil {
-	//	return err
-	//}
-	//form_data := string(bytes)
-
-	//先重构message
-	newMessSlice := make([]types.StdCompMessage, 2)
-	newMessSlice[0] = types.StdCompMessage{Role: "system", Content: `# 任务
-请根据提供的 表单模板,从聊天记录中提取出 用户 的相关信息,并将结果以 json 形式返回。
+	//Message重构的配置
+	me.ResformatConfig.SysmesArgs = []any{nowTime, weekday}
+	me.ResformatConfig.SysmesTmpl = `# 任务
+请帮助user从聊天记录中提取表单值,并返回一个JSON格式的表单值。
 
 # 背景信息
-当前时间是:` + nowTime + `
-当前星期是:` + weekday + `
+当前时间是:%s
+当前星期是:%s
 
 # 返回值示例
 * 如表单类型为 input、autoComplete、textarea,返回示例:["表单值"]
@@ -59,34 +27,51 @@ func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
 * 如表单类型为 checkbox,返回示例:["值1", "值2"]
 * 如表单类型为 cascader,返回示例:["一级值1", "二级值3"]
 * 如表单类型为 date,返回示例:["2025-01-01"]
-* 如没有找到某个表单相关的值,请不要返回该表单`}
+* 如没有找到某个表单相关的值,请不要返回该表单`
 
-	newMessSlice[1] = types.StdCompMessage{Role: "user", Content: `# 表单模板
-` + req.Variables["form_data"] + `
+	me.ResformatConfig.UsermesArgs = []any{req.Variables["form_data"], req.Variables["chat_history"]}
+	me.ResformatConfig.UsermesTmpl = `# 待提取表单
+%s
 
 # 聊天记录
-` + req.Variables["chat_history"]}
+%s`
 
-	//再构造ResponseFormat
-	if !IsOpenaiModel(req.Model) {
-		newMessSlice[1].Content = newMessSlice[1].Content.(string) + `
-# 请以下方的json结构输出
-[{
+	//ResponseFormat设置的配置
+	me.ResformatConfig.ResformatDesc = "从通话记录中提取表单"
+	me.ResformatConfig.ResformatTxt = `[{
     "dataIndex": str, # 表单ID
     "value": list[str] # 表单值列表
 }]`
-		req.ResponseFormat = openai.ResponseFormatJSONObjectParam{Type: "json_object"}
-	} else {
-		schemaParam := openai.ResponseFormatJSONSchemaJSONSchemaParam{
-			Name:        "keyword_schema",
-			Description: openai.String("从通话记录中提取表单"),
-			Schema:      FormResponseSchema,
-			Strict:      openai.Bool(true),
-		}
-		req.ResponseFormat = openai.ResponseFormatJSONSchemaParam{JSONSchema: schemaParam}
+
+	type formStruct struct {
+		DataIndex string   `json:"dataIndex" jsonschema_description:"表单ID"`
+		Value     []string `json:"value" jsonschema_description:"值列表"`
 	}
-	//req.Model = oldModel
-	req.Messages = newMessSlice
+	me.ResformatConfig.ResformatStruct = struct {
+		Values []formStruct `json:"values" jsonschema_description:"表单列表"`
+	}{}
+	me.ResformatConfig.HaveSet = true
+
+	return me.ResformatConfig
+}
 
-	return nil
+func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
+
+	//设置相关个性化ResponseFormat配置信息
+	if !me.ResformatConfig.HaveSet {
+		me.ResponseFormatSetting(req)
+	}
+
+	return me.MismatchClient.BuildRequest(req)
+}
+
+// 向Client.getClientActFace工厂方法注册
+func init() {
+	builder := func(c *Client) (clientActionFace, error) {
+		return &FormClient{MismatchClient{StdClient: StdClient{Client: c}}}, nil
+	}
+	err := RegisterClient("form", builder)
+	if err != nil {
+		//panic(fmt.Sprintf("Failed to register client type 'mismatch': %v", err))
+	}
 }

+ 93 - 0
internal/utils/compapi/form_back.go

@@ -0,0 +1,93 @@
+package compapi
+
+//
+//import (
+//	"time"
+//	"wechat-api/internal/types"
+//
+//	"github.com/openai/openai-go"
+//)
+//
+//type FormClient struct {
+//	StdClient
+//}
+//
+//// Generate the JSON schema at initialization time
+//var FormResponseSchema = GenerateSchema[FormList]()
+//
+//type FormResponse struct {
+//	DataIndex string   `json:"dataIndex" jsonschema_description:"表单 id"`
+//	Value     []string `json:"value" jsonschema_description:" 值列表"`
+//}
+//
+//type FormList struct {
+//	Values []FormResponse `json:"values" jsonschema_description:"表单列表"`
+//}
+//
+///*
+//
+//"response_format":{"type":"json_object"}}
+//
+//{"type":"json_schema",
+//	"json_schema":{
+//		"description":"从通话记录中提取表单","name":"keyword_schema","schema":{
+//			"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{
+//			"keywords":{
+//				"description":"关键词库","items":{"type":"string"},"type":"array"},"regular":{"description":"正则表达式","items":{"type":"string"},"type":"array"},"similar_reply":{"description":"类似回复","items":{"type":"string"},"type":"array"},"swear_words":{"description":"脏话列表","items":{"type":"string"},"type":"array"},"user_intent":{"description":"用户意图","type":"string"},"user_mood":{"description":"用户情绪","type":"string"}},"required":["user_intent","similar_reply","keywords","regular","user_mood","swear_words"],"type":"object"},"strict":true}}
+//*/
+//
+//func (me *FormClient) BuildRequest(req *types.CompApiReq) error {
+//	nowTime := time.Now().Format("2006-01-02 15:04:05")
+//	weekday := time.Now().Weekday().String()
+//	//bytes, err := json.Marshal(req.Variables["form_data"])
+//	//if err != nil {
+//	//	return err
+//	//}
+//	//form_data := string(bytes)
+//
+//	//先重构message
+//	newMessSlice := make([]types.StdCompMessage, 2)
+//	newMessSlice[0] = types.StdCompMessage{Role: "system", Content: `# 任务
+//请帮助user从聊天记录中提取表单值,并返回一个JSON格式的表单值。
+//
+//# 背景信息
+//当前时间是:` + nowTime + `
+//当前星期是:` + weekday + `
+//
+//# 返回值示例
+//* 如表单类型为 input、autoComplete、textarea,返回示例:["表单值"]
+//* 如表单类型为 radio、select,返回示例:["值1"]
+//* 如表单类型为 checkbox,返回示例:["值1", "值2"]
+//* 如表单类型为 cascader,返回示例:["一级值1", "二级值3"]
+//* 如表单类型为 date,返回示例:["2025-01-01"]
+//* 如没有找到某个表单相关的值,请不要返回该表单`}
+//
+//	newMessSlice[1] = types.StdCompMessage{Role: "user", Content: `# 待提取表单
+//` + req.Variables["form_data"] + `
+//
+//# 聊天记录
+//` + req.Variables["chat_history"]}
+//
+//	//再构造ResponseFormat
+//	if !IsOpenaiModel(req.Model) {
+//		newMessSlice[1].Content = newMessSlice[1].Content.(string) + `
+//# 请以下方的json结构输出
+//[{
+//    "dataIndex": str, # 表单ID
+//    "value": list[str] # 表单值列表
+//}]`
+//		req.ResponseFormat = openai.ResponseFormatJSONObjectParam{Type: "json_object"}
+//	} else {
+//		schemaParam := openai.ResponseFormatJSONSchemaJSONSchemaParam{
+//			Name:        "keyword_schema",
+//			Description: openai.String("从通话记录中提取表单"),
+//			Schema:      FormResponseSchema,
+//			Strict:      openai.Bool(true),
+//		}
+//		req.ResponseFormat = openai.ResponseFormatJSONSchemaParam{JSONSchema: schemaParam}
+//	}
+//	//req.Model = oldModel
+//	req.Messages = newMessSlice
+//
+//	return nil
+//}