1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package facade
- import (
- "eta/eta_api/services/llm/facade/bus_response"
- "eta/eta_api/utils/llm"
- "eta/eta_api/utils/llm/eta_llm/eta_llm_http"
- "eta/eta_api/utils/ws"
- "fmt"
- "github.com/gorilla/websocket"
- "github.com/rdlucklib/rdluck_tools/uuid"
- )
- var (
- llmService, _ = llm.GetInstance(llm.ETA_LLM_CLIENT)
- )
- func generateSessionCode() (code string) {
- return fmt.Sprintf("%s%s", "llm_session_", uuid.NewUUID().Hex32())
- }
- // AddSession 创建会话session
- func AddSession(userId int, conn *websocket.Conn) {
- sessionId := generateSessionCode()
- session := ws.NewSession(userId, sessionId, conn)
- ws.Manager().AddSession(session)
- }
- // LLMKnowledgeBaseSearchDocs 搜索知识库
- func LLMKnowledgeBaseSearchDocs(search LLMKnowledgeSearch) (resp bus_response.SearchDocsEtaResponse, err error) {
- docs, err := llmService.SearchKbDocs(search.Query, search.KnowledgeBaseName)
- if err != nil {
- return
- }
- for _, doc := range docs.([]eta_llm_http.SearchDocsResponse) {
- resp.Content = resp.Content + doc.PageContent
- }
- resp.Docs = docs.([]eta_llm_http.SearchDocsResponse)
- return
- }
- type LLMKnowledgeSearch struct {
- Query string `json:"Query"`
- KnowledgeBaseName string `json:"KnowledgeBaseName"`
- }
|