Browse Source

Merge branch 'yhg_241210_dify' into debug

jimmyyem 3 months ago
parent
commit
2a8095594e

+ 1 - 0
desc/wechat/chat_records.api

@@ -92,6 +92,7 @@ type (
 	GptChatReq{
 		ConversationId *string `json:"conversationId,optional"`
 		Content *string `json:"content"`
+		AgentId *uint64 `json:"agentId"`
 	}
 	GptMessageReq {
 		ConversationId *string `json:"conversationId,optional"`

+ 12 - 2
internal/logic/chatrecords/gpts_submit_api_chat_logic.go

@@ -11,6 +11,8 @@ import (
 	"net/http"
 	"strings"
 	"time"
+	"wechat-api/ent"
+	"wechat-api/ent/employee"
 	"wechat-api/hook/dify"
 	"wechat-api/internal/utils"
 	jwtutils "wechat-api/internal/utils/jwt"
@@ -67,6 +69,14 @@ func (l *GptsSubmitApiChatLogic) GptsSubmitApiChat(tokenStr string, req *types.G
 		return
 	}
 
+	employeeItem, err := l.svcCtx.DB.Employee.Query().Where(employee.ID(*req.AgentId)).Only(l.ctx)
+	if err != nil {
+		if ent.IsNotFound(err) {
+			return
+		}
+		return
+	}
+
 	var chatReq dify.ChatReq
 	chatReq.ResponseMode = "streaming"
 	chatReq.Query = *req.Content
@@ -79,7 +89,7 @@ func (l *GptsSubmitApiChatLogic) GptsSubmitApiChat(tokenStr string, req *types.G
 	fmt.Printf("request data:%v\n", string(jsonData))
 
 	// 建立HTTP請求
-	url := dify.GetBaseUrl() + dify.GetChatUrl() // 替換為正確的FastGPT API端點
+	url := employeeItem.APIBase + dify.GetChatUrl()
 	request, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
 	if err != nil {
 		fmt.Printf("Error creating request:%v", err)
@@ -88,7 +98,7 @@ func (l *GptsSubmitApiChatLogic) GptsSubmitApiChat(tokenStr string, req *types.G
 
 	// 設置請求頭
 	request.Header.Set("Content-Type", "application/json")
-	request.Header.Set("Authorization", "Bearer "+dify.GetToken())
+	request.Header.Set("Authorization", "Bearer "+employeeItem.APIKey)
 	request.Header.Set("Transfer-Encoding", "chunked")
 
 	// 發送請求

+ 1 - 0
internal/types/types.go

@@ -2418,6 +2418,7 @@ type ChatAskResp struct {
 type GptChatReq struct {
 	ConversationId *string `json:"conversationId,optional"`
 	Content        *string `json:"content"`
+	AgentId        *uint64 `json:"agentId"`
 }
 
 // swagger:model GptMessageReq