|
@@ -27,6 +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"
|
|
|
KNOWLEDGE_BASE_SEARCH_DOCS_API = "/knowledge_base/search_docs"
|
|
|
)
|
|
|
|
|
@@ -34,6 +35,7 @@ type ETALLMClient struct {
|
|
|
*llm.LLMClient
|
|
|
LlmModel string
|
|
|
}
|
|
|
+
|
|
|
type LLMConfig struct {
|
|
|
LlmAddress string `json:"llm_server"`
|
|
|
LlmModel string `json:"llm_model"`
|
|
@@ -62,6 +64,35 @@ func GetInstance() llm.LLMService {
|
|
|
return etaLlmClient
|
|
|
}
|
|
|
|
|
|
+func (ds *ETALLMClient) DocumentChat(query string, KnowledgeId string, history []string, 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],
|
|
|
+ }
|
|
|
+ ChatHistory = append(ChatHistory, historyItem)
|
|
|
+ }
|
|
|
+ kbReq := eta_llm_http.DocumentChatRequest{
|
|
|
+ Query: query,
|
|
|
+ KnowledgeId: KnowledgeId,
|
|
|
+ History: ChatHistory,
|
|
|
+ TopK: 3,
|
|
|
+ ScoreThreshold: 0.5,
|
|
|
+ Stream: stream,
|
|
|
+ ModelName: ds.LlmModel,
|
|
|
+ Temperature: 0.7,
|
|
|
+ MaxTokens: 0,
|
|
|
+ PromptName: DEFALUT_PROMPT_NAME,
|
|
|
+ }
|
|
|
+ fmt.Printf("%v", kbReq.History)
|
|
|
+ body, err := json.Marshal(kbReq)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return ds.DoStreamPost(DOCUMENT_CHAT_API, body)
|
|
|
+}
|
|
|
func (ds *ETALLMClient) KnowledgeBaseChat(query string, KnowledgeBaseName string, history []string) (llmRes *http.Response, err error) {
|
|
|
ChatHistory := make([]eta_llm_http.HistoryContent, 0)
|
|
|
for _, historyItemStr := range history {
|