|
@@ -4,6 +4,7 @@ import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "eta/eta_api/services/llm/facade/bus_response"
|
|
|
"eta/eta_api/utils"
|
|
|
"eta/eta_api/utils/llm"
|
|
|
"eta/eta_api/utils/llm/eta_llm/eta_llm_http"
|
|
@@ -47,15 +48,17 @@ func (ds *ETALLMClient) KnowledgeBaseChat() string {
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
-func (ds *ETALLMClient) SearchKbDocs(query string, KnowledgeBaseName string) (content string, err error) {
|
|
|
+func (ds *ETALLMClient) SearchKbDocs(query string, KnowledgeBaseName string) (content interface{}, err error) {
|
|
|
// 类型断言
|
|
|
+
|
|
|
kbReq := eta_llm_http.KbSearchDocsRequest{
|
|
|
Query: query,
|
|
|
KnowledgeBaseName: KnowledgeBaseName,
|
|
|
- Model: ds.LlmModel,
|
|
|
- TopK: 3,
|
|
|
- ScoreThreshold: 2,
|
|
|
+ TopK: 10,
|
|
|
+ ScoreThreshold: 0.5,
|
|
|
+ Metadata: struct{}{},
|
|
|
}
|
|
|
+
|
|
|
body, err := json.Marshal(kbReq)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -65,7 +68,18 @@ func (ds *ETALLMClient) SearchKbDocs(query string, KnowledgeBaseName string) (co
|
|
|
err = errors.New(resp.Msg)
|
|
|
return
|
|
|
}
|
|
|
- return "", nil
|
|
|
+ if resp.Data != nil {
|
|
|
+ var kbSearchRes []bus_response.SearchDocsResponse
|
|
|
+ err = json.Unmarshal(resp.Data, &kbSearchRes)
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("搜索知识库失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ content = kbSearchRes
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = errors.New("搜索知识库失败")
|
|
|
+ return
|
|
|
}
|
|
|
func init() {
|
|
|
err := llm.Register(llm.ETA_LLM_CLIENT, GetInstance())
|
|
@@ -97,6 +111,7 @@ func parseResponse(response *http.Response) (baseResp eta_llm_http.BaseResponse,
|
|
|
err = fmt.Errorf("读取响应体失败: %w", err)
|
|
|
return
|
|
|
}
|
|
|
+ baseResp.Success = true
|
|
|
baseResp.Data = bodyBytes
|
|
|
return
|
|
|
}
|