From eac2500f0f00e96c63526c51206ed2076ad8cd20 Mon Sep 17 00:00:00 2001 From: zveinn Date: Sat, 5 Jun 2021 19:23:24 +0000 Subject: [PATCH 1/3] adding best of option --- completion.go | 1 + 1 file changed, 1 insertion(+) diff --git a/completion.go b/completion.go index b01b4c06d..647bd7b9b 100644 --- a/completion.go +++ b/completion.go @@ -25,6 +25,7 @@ type CompletionRequest struct { PresencePenalty float32 `json:"presence_penalty,omitempty"` FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` + BestOf int `json:"best_of,omitempty"` } // Choice represents one of possible completions From 990da279b073ad8e3881874624c49914c1d485af Mon Sep 17 00:00:00 2001 From: zveinn Date: Sat, 5 Jun 2021 20:13:52 +0000 Subject: [PATCH 2/3] adding answers option --- answers.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 answers.go diff --git a/answers.go b/answers.go new file mode 100644 index 000000000..47cfbecdf --- /dev/null +++ b/answers.go @@ -0,0 +1,49 @@ +package gogpt + +import ( + "bytes" + "context" + "encoding/json" + "net/http" +) + +type AnswerRequest struct { + Documents []string `json:"documents"` + Question string `json:"question"` + SearchModel string `json:"search_model"` + Model string `json:"model"` + ExamplesContext string `json:"examples_context"` + Examples [][]string `json:"examples"` + MaxTokens int `json:"max_tokens"` + Stop []string `json:"stop"` +} + +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 +} From 7ae92bf9465d5bb9ce818c5bd038e45ce5a119cb Mon Sep 17 00:00:00 2001 From: zveinn Date: Sat, 5 Jun 2021 20:25:43 +0000 Subject: [PATCH 3/3] fixing small mistake --- answers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/answers.go b/answers.go index 47cfbecdf..fedfcad18 100644 --- a/answers.go +++ b/answers.go @@ -8,7 +8,7 @@ import ( ) type AnswerRequest struct { - Documents []string `json:"documents"` + Documents [][]string `json:"documents"` Question string `json:"question"` SearchModel string `json:"search_model"` Model string `json:"model"` @@ -38,7 +38,7 @@ func (c *Client) Answers(ctx context.Context, request AnswerRequest) (response A return } - req, err := http.NewRequest("POST", c.fullURL("answers"), bytes.NewBuffer(reqBytes)) + req, err := http.NewRequest("POST", c.fullURL("/answers"), bytes.NewBuffer(reqBytes)) if err != nil { return }