forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Answer request AND adding best_of option to Completion. (sasha…
…baranov#5) * adding best of option * adding answers option * fixing small mistake
- Loading branch information
Sveinn Óttar Lárusson
committed
Jun 6, 2021
1 parent
c12d250
commit 2be4a26
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters