Selaa lähdekoodia

Merge branch 'master' into fixbug/20250322

jimmyyem 1 kuukausi sitten
vanhempi
commit
6c6c06f071

+ 3 - 1
desc/openapi/chat.api

@@ -53,7 +53,7 @@ type (
 	
 	StdCompMessage {
         Role string `json:"role"`
-        Content string `json:"content"`
+        Content interface{} `json:"content"`
     }
 
     //以下是API响应类型
@@ -125,6 +125,8 @@ type (
 	    Message ChatCompletionMessage  `json:"message,omitempty"`
         // A chat completion message generated by the model stream mode.
 	    Delta ChatCompletionMessage  `json:"delta,omitempty"`
+		//
+		Logprobs string `json:"logprobs"`
     }
 
     CompletionUsageCompletionTokensDetails {

+ 36 - 2
internal/handler/chat/chat_completions_handler.go

@@ -1,6 +1,10 @@
 package chat
 
 import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"io"
 	"net/http"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
@@ -8,6 +12,8 @@ import (
 	"wechat-api/internal/logic/chat"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 // swagger:route post /v1/chat/completions chat ChatCompletions
@@ -27,12 +33,40 @@ import (
 
 func ChatCompletionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
-		var req types.CompApiReq
-		if err := httpx.Parse(r, &req, true); err != nil {
+		/*
+			var req types.CompApiReq
+			if err := httpx.Parse(r, &req, true); err != nil {
+				httpx.ErrorCtx(r.Context(), w, err)
+				return
+			}
+
+			l := chat.NewChatCompletionsLogic(r.Context(), svcCtx)
+			resp, err := l.ChatCompletions(&req)
+			if err != nil {
+				httpx.ErrorCtx(r.Context(), w, err)
+			} else {
+				httpx.OkJsonCtx(r.Context(), w, resp)
+			}
+		*/
+		// 读取请求体
+		body, err := io.ReadAll(r.Body)
+		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 			return
 		}
+		// 将请求体还原,以便后续处理
+		r.Body = io.NopCloser(bytes.NewBuffer(body))
 
+		// 打印请求体
+		logx.Info(string(body))
+		var req types.CompApiReq
+		err = json.Unmarshal([]byte(string(body)), &req)
+		if err != nil {
+			fmt.Println("Error:", err)
+			return
+		}
+		// 打印请求体
+		logx.Info(req)
 		l := chat.NewChatCompletionsLogic(r.Context(), svcCtx)
 		resp, err := l.ChatCompletions(&req)
 		if err != nil {

+ 16 - 1
internal/logic/chat/chat_completions_logic.go

@@ -163,13 +163,28 @@ func (l *ChatCompletionsLogic) appendUsageDetailLog(authToken string, req *types
 	completionToken := uint64(resp.Usage.CompletionTokens)
 	totalTokens := promptTokens + completionToken
 
+	msgContent := ""
+	switch val := req.Messages[0].Content.(type) {
+	case string:
+		msgContent = val
+	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).
 		SetNotNilBotID(&authToken).
 		SetNotNilReceiverID(&req.EventType).
 		SetNotNilSessionID(&sessionId).
 		SetNillableApp(&workIdx).
-		SetNillableRequest(&req.Messages[0].Content).
+		//SetNillableRequest(&req.Messages[0].Content).
+		SetNillableRequest(&msgContent).
 		SetNillableResponse(&resp.Choices[0].Message.Content).
 		SetNillableOrganizationID(&orgId).
 		SetOriginalData(rawReqResp).

+ 4 - 1
internal/logic/contact/get_contact_list_logic.go

@@ -51,8 +51,11 @@ func convertLabelToLabelInfo(label *ent.Label) types.LabelInfo {
 
 func (l *GetContactListLogic) GetContactList(req *types.ContactListReq) (*types.ContactListResp, error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
+	isAdmin := l.ctx.Value("isAdmin").(bool)
 	var predicates []predicate.Contact
-	predicates = append(predicates, contact.OrganizationIDEQ(organizationId))
+	if req.WxWxid == nil || (req.WxWxid != nil && !isAdmin) {
+		predicates = append(predicates, contact.OrganizationIDEQ(organizationId))
+	}
 
 	var ctype uint64 = 1
 	if req.Ctype != nil {

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2 - 1
internal/logic/fastgpt/create_app_logic.go


+ 3 - 1
internal/service/MessageHandlers/chatroom_push_notice.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"github.com/zeromicro/go-zero/core/logx"
 	"wechat-api/ent/wx"
+	"wechat-api/hook"
 	"wechat-api/internal/pkg/wechat_ws"
 	"wechat-api/internal/svc"
 	"wechat-api/workphone"
@@ -33,7 +34,7 @@ func (f *ChatroomPushNoticeHandler) Handler(msg *wechat_ws.MsgJsonObject) error
 				wx.WxidEQ(message.WeChatId), // Additional filter by organizationId
 			).
 			Only(context.TODO())
-		//hookClient := hook.NewHook("", "", "")
+		hookClient := hook.NewHook("", "", "")
 		for _, friend := range message.ChatRooms {
 			friendType := 2
 			//if friend.Type == 1 {
@@ -42,6 +43,7 @@ func (f *ChatroomPushNoticeHandler) Handler(msg *wechat_ws.MsgJsonObject) error
 			//} else {
 			//	friendType = 1
 			//}
+			_ = hookClient.RequestChatRoomInfo(friend.UserName, message.WeChatId)
 			_, err = f.svcCtx.DB.Contact.Create().
 				SetWxWxid(message.WeChatId).
 				SetType(friendType).

+ 8 - 8
internal/service/MessageHandlers/friend_push_notice.go

@@ -5,7 +5,6 @@ import (
 	"encoding/json"
 	"github.com/zeromicro/go-zero/core/logx"
 	"wechat-api/ent/wx"
-	"wechat-api/hook"
 	"wechat-api/internal/pkg/wechat_ws"
 	"wechat-api/internal/svc"
 	"wechat-api/workphone"
@@ -34,15 +33,15 @@ func (f *FriendPushNoticeHandler) Handler(msg *wechat_ws.MsgJsonObject) error {
 				wx.WxidEQ(message.WeChatId), // Additional filter by organizationId
 			).
 			Only(context.TODO())
-		hookClient := hook.NewHook("", "", "")
+		//hookClient := hook.NewHook("", "", "")
 		for _, friend := range message.Friends {
 			friendType := 1
-			if friend.Type == 1 {
-				friendType = 2
-				_ = hookClient.RequestChatRoomInfo(friend.FriendId, message.WeChatId)
-			} else {
-				friendType = 1
-			}
+			//if friend.Type == 1 {
+			//	friendType = 2
+			//	_ = hookClient.RequestChatRoomInfo(friend.FriendId, message.WeChatId)
+			//} else {
+			//	friendType = 1
+			//}
 			_, err = f.svcCtx.DB.Contact.Create().
 				SetWxWxid(message.WeChatId).
 				SetType(friendType).
@@ -55,6 +54,7 @@ func (f *FriendPushNoticeHandler) Handler(msg *wechat_ws.MsgJsonObject) error {
 				SetOrganizationID(wx_info.OrganizationID).
 				OnConflict().
 				UpdateNewValues().
+				SetType(friendType).
 				SetOrganizationID(wx_info.OrganizationID).
 				ID(context.TODO())
 

+ 4 - 2
internal/types/types.go

@@ -1970,8 +1970,8 @@ type FastGptSpecReq struct {
 }
 
 type StdCompMessage struct {
-	Role    string `json:"role"`
-	Content string `json:"content"`
+	Role    string      `json:"role"`
+	Content interface{} `json:"content"`
 }
 
 // 以下是API响应类型
@@ -2045,6 +2045,8 @@ type ChatCompletionChoice struct {
 	Message ChatCompletionMessage `json:"message,omitempty"`
 	// A chat completion message generated by the model stream mode.
 	Delta ChatCompletionMessage `json:"delta,omitempty"`
+	//
+	Logprobs string `json:"logprobs"`
 }
 
 type CompletionUsageCompletionTokensDetails struct {

+ 1 - 0
internal/utils/compapi/config.go

@@ -20,4 +20,5 @@ var fastgptWorkIdMap = map[string]workIdInfo{
 	"default":              {"fastgpt-jcDATa9aH4vtUsjDpCU773BxmLU50IxKUX9nUT0mCTLQkEoo1hPxPEdNQeOEWGTn", 0},
 	"OPTIMIZE_CALL_SCRIPT": {"fastgpt-bcQ9cWKd6y9a2LfizweeWEnukkQi1Oq46yoiRg9yDNLm8NPTWXsyFwcB", 1},
 	"TEST_DOUYIN":          {"fastgpt-bwt6oSGcjwJ1qBgT276oeFD34IAhfjEQBCZWJfJR1oj3WqJl7751ljSrc", 2},
+	"GENERALIZED_KEYWORDS": {"fastgpt-yefNCWpNtzY2Qn0xtJvKuvepOP9DR7BiXQwv5BiVP5JseP2IS92gE", 3},
 }

+ 2 - 2
internal/utils/compapi/func.go

@@ -91,11 +91,11 @@ func DoChatCompletionsStream(ctx context.Context, client *openai.Client, chatInf
 	defer chatStream.Close()
 	for chatStream.Next() {
 		chunk := chatStream.Current()
-		fmt.Fprintf(hw, "event:%s\ndata:%s\n\n", chunk.Event, chunk.Data.RAW)
+		fmt.Fprintf(hw, "data:%s\n\n", chunk.Data.RAW)
 		flusher.Flush()
 		//time.Sleep(1 * time.Millisecond)
 	}
-	fmt.Fprintf(hw, "event:%s\ndata:%s\n\n", "answer", "[DONE]")
+	fmt.Fprintf(hw, "data:%s\n\n", "[DONE]")
 	flusher.Flush()
 	httpx.Ok(hw)
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä