From 4c235d7cc9934dc5604a8e33756c89de2fe480cc Mon Sep 17 00:00:00 2001 From: godo Date: Sat, 11 Jan 2025 15:36:33 +0800 Subject: [PATCH] chang ai --- godo/ai/server/chat.go | 9 ++++++--- godo/ai/types/response.go | 36 ++++++++---------------------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/godo/ai/server/chat.go b/godo/ai/server/chat.go index ff62c96..a8830e7 100644 --- a/godo/ai/server/chat.go +++ b/godo/ai/server/chat.go @@ -44,7 +44,8 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) { for _, s := range searchRes { res.WebSearch = append(res.WebSearch, types.WebSearchResult{Title: s.Title, Content: s.Content, Link: s.Url}) } - libs.SuccessMsg(w, res, "") + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(res) return } if req.FileContent != "" { @@ -58,7 +59,8 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) { libs.ErrorMsg(w, err.Error()) return } - libs.SuccessMsg(w, res, "") + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(res) return } if req.KnowledgeId != 0 { @@ -77,7 +79,8 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) { // s.FilePath = strings.TrimPrefix(s.FilePath, basePath) res.Documents = append(res.Documents, types.AskDocResponse{Content: s.Content, Score: s.Score, FilePath: s.FilePath, FileName: s.FileName}) } - libs.SuccessMsg(w, res, "") + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(res) return } diff --git a/godo/ai/types/response.go b/godo/ai/types/response.go index e5a247e..13a9dfa 100644 --- a/godo/ai/types/response.go +++ b/godo/ai/types/response.go @@ -12,43 +12,21 @@ type ChatRequest struct { KnowledgeId uint `json:"knowledgeId"` } -type InvokeResp struct { - RequestID string `json:"requestId"` - Content string `json:"content"` - Problems []string `json:"problems"` - DocumentSlices []struct { - Document Document `json:"document"` - SliceInfo []Slice `json:"slice_info"` - HidePositions bool `json:"hide_positions"` - Images []Image `json:"images"` - } `json:"documents"` -} type AskDocResponse struct { - Content string `json:"content"` - Score float32 `json:"score"` - FilePath string `json:"file_path"` - FileName string `json:"file_name"` -} -type Document struct { - ID string `json:"id"` - Name string `json:"name"` - URL string `json:"url"` - Dtype int `json:"dtype"` + Content string `json:"content"` + Score float32 `json:"score"` + FilePath string `json:"file_path"` + FileName string `json:"file_name"` + Position Position `json:"position,omitempty"` } -type Slice struct { - DocumentID string `json:"document_id"` - Position *Position `json:"position,omitempty"` - Line int `json:"line,omitempty"` - SheetName string `json:"sheet_name,omitempty"` - Text string `json:"text"` -} type Position struct { X0 float64 `json:"x0"` X1 float64 `json:"x1"` Top float64 `json:"top"` Bottom float64 `json:"bottom"` Page int `json:"page"` + Line int `json:"line"` Height float64 `json:"height"` Width float64 `json:"width"` } @@ -65,6 +43,8 @@ type OpenAIResponse struct { Usage Usage `json:"usage"` WebSearch []WebSearchResult `json:"web_search,omitempty"` Documents []AskDocResponse `json:"documents"` + Problems []string `json:"problems"` + Images []string `json:"images"` } type Choice struct { Index int `json:"index"`