Added support for Edits endpoint & other minor changes (#22)
* Added support for Moderations API * gofmt moderation.go * support for edits endpoint & other improvements
This commit is contained in:
57
edits.go
Normal file
57
edits.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package gogpt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// EditsRequest represents a request structure for Edits API
|
||||
type EditsRequest struct {
|
||||
Model *string `json:"model,omitempty"`
|
||||
Input string `json:"input,omitempty"`
|
||||
Instruction string `json:"instruction,omitempty"`
|
||||
N int `json:"n,omitempty"`
|
||||
Temperature float32 `json:"temperature,omitempty"`
|
||||
TopP float32 `json:"top_p,omitempty"`
|
||||
}
|
||||
|
||||
// EditsUsage represents Usage of EditsResponse
|
||||
type EditsUsage struct {
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
}
|
||||
|
||||
// Choice represents one of possible edits
|
||||
type Choice struct {
|
||||
Text string `json:"text"`
|
||||
Index int `json:"index"`
|
||||
}
|
||||
|
||||
// EditsResponse represents a response structure for Edits API
|
||||
type EditsResponse struct {
|
||||
Object string `json:"object"`
|
||||
Created uint64 `json:"created"`
|
||||
Usage EditsUsage `json:"usage"`
|
||||
Choices []Choice `json:"choices"`
|
||||
}
|
||||
|
||||
// Perform an API call to the Edits endpoint.
|
||||
func (c *Client) Edits(ctx context.Context, request EditsRequest) (response EditsResponse, err error) {
|
||||
var reqBytes []byte
|
||||
reqBytes, err = json.Marshal(request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", c.fullURL("/edits"), bytes.NewBuffer(reqBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
err = c.sendRequest(req, &response)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user