|
@@ -33,6 +33,7 @@ const (
|
|
|
DEFALUT_PROMPT_NAME = "default"
|
|
|
CONTENT_TYPE_JSON = "application/json"
|
|
|
KNOWLEDGE_BASE_CHAT_API = "/chat/kb_chat"
|
|
|
+ COMPLETION_CHAT_API = "/chat/chat/completions"
|
|
|
DOCUMENT_CHAT_API = "/chat/file_chat"
|
|
|
KNOWLEDGE_BASE_SEARCH_DOCS_API = "/knowledge_base/search_docs"
|
|
|
UPLOAD_TEMP_DOCS_API = "/knowledge_base/upload_temp_docs"
|
|
@@ -109,6 +110,43 @@ func (ds *ETALLMClient) DocumentChat(query string, KnowledgeId string, history [
|
|
|
return ds.DoStreamPost(DOCUMENT_CHAT_API, body)
|
|
|
}
|
|
|
|
|
|
+func (ds *ETALLMClient) CompletionChat(query string, messages []json.RawMessage) (llmRes *http.Response, err error) {
|
|
|
+ ChatHistory := make([]eta_llm_http.HistoryContent, 0)
|
|
|
+ for _, historyItemStr := range messages {
|
|
|
+ var historyItem eta_llm_http.HistoryContentWeb
|
|
|
+ parseErr := json.Unmarshal(historyItemStr, &historyItem)
|
|
|
+ if parseErr != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ ChatHistory = append(ChatHistory, eta_llm_http.HistoryContent{
|
|
|
+ Content: historyItem.Content,
|
|
|
+ Role: historyItem.Role,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ ChatHistory = append(ChatHistory, eta_llm_http.HistoryContent{
|
|
|
+ Content: query,
|
|
|
+ Role: "user",
|
|
|
+ })
|
|
|
+ kbReq := eta_llm_http.CompletionChatRequest{
|
|
|
+ Mode: KNOWLEDEG_CHAT_MODE,
|
|
|
+ Messages: ChatHistory,
|
|
|
+ TopK: 3,
|
|
|
+ ScoreThreshold: 0.5,
|
|
|
+ Stream: true,
|
|
|
+ Model: ds.LlmModel,
|
|
|
+ Temperature: 0.7,
|
|
|
+ MaxTokens: 0,
|
|
|
+ PromptName: DEFALUT_PROMPT_NAME,
|
|
|
+ ReturnDirect: false,
|
|
|
+ }
|
|
|
+ fmt.Printf("%v", kbReq.Messages)
|
|
|
+ body, err := json.Marshal(kbReq)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return ds.DoStreamPost(COMPLETION_CHAT_API, body)
|
|
|
+}
|
|
|
+
|
|
|
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 {
|