Prechádzať zdrojové kódy

Merge branch 'feature/deepseek_rag_1.0' into debug

kobe6258 1 mesiac pred
rodič
commit
ad5c852892

+ 21 - 11
utils/llm/eta_llm/eta_llm_client.go

@@ -27,7 +27,7 @@ const (
 	DEFALUT_PROMPT_NAME            = "default"
 	CONTENT_TYPE_JSON              = "application/json"
 	KNOWLEDGE_BASE_CHAT_API        = "/chat/kb_chat"
-	DOCUMENT_CHAT_API        = "/chat/file_chat"
+	DOCUMENT_CHAT_API              = "/chat/file_chat"
 	KNOWLEDGE_BASE_SEARCH_DOCS_API = "/knowledge_base/search_docs"
 )
 
@@ -64,14 +64,19 @@ func GetInstance() llm.LLMService {
 	return etaLlmClient
 }
 
-func (ds *ETALLMClient) DocumentChat(query string, KnowledgeId string, history []string, stream bool) (llmRes *http.Response, err error) {
+func (ds *ETALLMClient) DocumentChat(query string, KnowledgeId string, history []json.RawMessage, stream bool) (llmRes *http.Response, err error) {
 	ChatHistory := make([]eta_llm_http.HistoryContent, 0)
 	for _, historyItemStr := range history {
-		str := strings.Split(historyItemStr, "-")
-		historyItem := eta_llm_http.HistoryContent{
-			Role:    str[0],
-			Content: str[1],
+		var historyItem eta_llm_http.HistoryContent
+		parseErr := json.Unmarshal(historyItemStr, &historyItem)
+		if parseErr != nil {
+			continue
 		}
+		//str := strings.Split(historyItemStr, "-")
+		//historyItem := eta_llm_http.HistoryContent{
+		//	Role:    str[0],
+		//	Content: str[1],
+		//}
 		ChatHistory = append(ChatHistory, historyItem)
 	}
 	kbReq := eta_llm_http.DocumentChatRequest{
@@ -93,13 +98,18 @@ func (ds *ETALLMClient) DocumentChat(query string, KnowledgeId string, history [
 	}
 	return ds.DoStreamPost(DOCUMENT_CHAT_API, body)
 }
-func (ds *ETALLMClient) KnowledgeBaseChat(query string, KnowledgeBaseName string, history []string) (llmRes *http.Response, err error) {
+func (ds *ETALLMClient) KnowledgeBaseChat(query string, KnowledgeBaseName string, history []json.RawMessage) (llmRes *http.Response, err error) {
 	ChatHistory := make([]eta_llm_http.HistoryContent, 0)
 	for _, historyItemStr := range history {
-		str := strings.Split(historyItemStr, "-")
-		historyItem := eta_llm_http.HistoryContent{
-			Role:    str[0],
-			Content: str[1],
+		//str := strings.Split(historyItemStr, "-")
+		//historyItem := eta_llm_http.HistoryContent{
+		//	Role:    str[0],
+		//	Content: str[1],
+		//}
+		var historyItem eta_llm_http.HistoryContent
+		parseErr := json.Unmarshal(historyItemStr, &historyItem)
+		if parseErr != nil {
+			continue
 		}
 		ChatHistory = append(ChatHistory, historyItem)
 	}

+ 2 - 2
utils/llm/eta_llm/eta_llm_http/request.go

@@ -27,8 +27,8 @@ type DocumentChatRequest struct {
 	PromptName     string           `json:"prompt_name"`
 }
 type HistoryContent struct {
-	Content string `json:"content"`
-	Role    string `json:"role"`
+	Content string `json:"Content"`
+	Role    string `json:"Role"`
 }
 
 type KbSearchDocsRequest struct {

+ 3 - 4
utils/llm/llm_client.go

@@ -1,6 +1,7 @@
 package llm
 
 import (
+	"encoding/json"
 	"net/http"
 	"time"
 )
@@ -20,9 +21,7 @@ func NewLLMClient(baseURL string, timeout time.Duration) *LLMClient {
 }
 
 type LLMService interface {
-	KnowledgeBaseChat(query string, KnowledgeBaseName string, history []string) (llmRes *http.Response, err error)
-	DocumentChat(query string, KnowledgeId string, history []string, stream bool) (llmRes *http.Response, err error)
+	KnowledgeBaseChat(query string, KnowledgeBaseName string, history []json.RawMessage) (llmRes *http.Response, err error)
+	DocumentChat(query string, KnowledgeId string, history []json.RawMessage, stream bool) (llmRes *http.Response, err error)
 	SearchKbDocs(query string, KnowledgeBaseName string) (data interface{}, err error)
-
-
 }

+ 5 - 4
utils/ws/session.go

@@ -1,6 +1,7 @@
 package ws
 
 import (
+	"encoding/json"
 	"errors"
 	"eta/eta_api/utils"
 	"fmt"
@@ -16,7 +17,7 @@ type Session struct {
 	Conn        *websocket.Conn
 	LastActive  time.Time
 	Latency     *LatencyMeasurer
-	History     []string
+	History     []json.RawMessage
 	CloseChan   chan struct{}
 	MessageChan chan string
 	mu          sync.RWMutex
@@ -24,9 +25,9 @@ type Session struct {
 }
 
 type Message struct {
-	KbName     string   `json:"KbName"`
-	Query      string   `json:"Query"`
-	LastTopics []string `json:"LastTopics"`
+	KbName     string            `json:"KbName"`
+	Query      string            `json:"Query"`
+	LastTopics []json.RawMessage `json:"LastTopics"`
 }
 
 // readPump 处理读操作

+ 0 - 1
utils/ws/session_manager.go

@@ -78,7 +78,6 @@ func (manager *ConnectionManager) HandleMessage(userID int, sessionID string, me
 	if resp == nil {
 		return errors.New("知识库问答失败: 无应答")
 	}
-
 	if err != nil {
 		err = errors.New(fmt.Sprintf("知识库问答失败: httpCode:%d,错误信息:%s", resp.StatusCode, http.StatusText(resp.StatusCode)))
 		return err