Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions answers.go
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
}
1 change: 1 addition & 0 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down