forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
answers.go
51 lines (45 loc) · 1.46 KB
/
answers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gogpt
import (
"bytes"
"context"
"encoding/json"
"net/http"
)
type AnswerRequest struct {
Documents []string `json:"documents,omitempty"`
File string `json:"file,omitempty"`
Question string `json:"question"`
SearchModel string `json:"search_model,omitempty"`
Model string `json:"model"`
ExamplesContext string `json:"examples_context"`
Examples [][]string `json:"examples"`
MaxTokens int `json:"max_tokens,omitempty"`
Stop []string `json:"stop,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
}
type AnswerResponse struct {
Answers []string `json:"answers"`
Completion string `json:"completion"`
Model string `json:"model"`
Object string `json:"object"`
SearchModel string `json:"search_model"`
SelectedDocuments []struct {
Document int `json:"document"`
Text string `json:"text"`
} `json:"selected_documents"`
}
// Search — perform a semantic search api call over a list of documents.
func (c *Client) Answers(ctx context.Context, request AnswerRequest) (response AnswerResponse, err error) {
var reqBytes []byte
reqBytes, err = json.Marshal(request)
if err != nil {
return
}
req, err := http.NewRequest("POST", c.fullURL("/answers"), bytes.NewBuffer(reqBytes))
if err != nil {
return
}
req = req.WithContext(ctx)
err = c.sendRequest(req, &response)
return
}