|
@@ -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")
|
|
|
|
|
|
// 發送請求
|