Browse Source

chang ai

master
godo 5 months ago
parent
commit
4c235d7cc9
  1. 9
      godo/ai/server/chat.go
  2. 36
      godo/ai/types/response.go

9
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
}

36
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"`

Loading…
Cancel
Save