瀏覽代碼

合并冲突

kobe6258 1 月之前
父節點
當前提交
a427bc194d
共有 3 個文件被更改,包括 29 次插入19 次删除
  1. 21 11
      utils/llm/eta_llm/eta_llm_client.go
  2. 3 4
      utils/llm/llm_client.go
  3. 5 4
      utils/ws/session.go

+ 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)
 	}

+ 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 处理读操作