Documentation ¶
Index ¶
- Constants
- func CheckResponseError(r *http.Response) error
- type APIKey
- type AuthMethod
- type ChatCompletionsChoice
- type ChatCompletionsRequest
- type ChatCompletionsResponse
- type ChatCompletionsUsage
- type ChatOp
- type ChatService
- type Client
- func (c *Client) CreateAndDo(method, relPath string, data, option, resource interface{}) error
- func (c *Client) Delete(path string) error
- func (c *Client) Get(path string, resource interface{}, option interface{}) error
- func (c *Client) NewRequest(method, path string, body, option interface{}) (*http.Request, error)
- func (c *Client) Patch(path string, data, resource interface{}) error
- func (c *Client) Post(path string, data, resource interface{}) error
- func (c *Client) Put(path string, data, resource interface{}) error
- type Message
- type Option
Examples ¶
Constants ¶
const (
GPT3dot5Turbo = "gpt-3.5-turbo"
)
Variables ¶
This section is empty.
Functions ¶
func CheckResponseError ¶
CheckResponseError checks the response, and in case of error, maps it to the error structure.
Types ¶
type AuthMethod ¶
type AuthMethod func(c *Client)
func SetAPIKey ¶
func SetAPIKey(key string) AuthMethod
type ChatCompletionsChoice ¶
type ChatCompletionsRequest ¶
type ChatCompletionsResponse ¶
type ChatCompletionsResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Usage *ChatCompletionsUsage `json:"usage"` Choices []*ChatCompletionsChoice `json:"choices"` }
type ChatCompletionsUsage ¶
type ChatOp ¶
type ChatOp struct {
// contains filtered or unexported fields
}
func (*ChatOp) Completions ¶
func (c *ChatOp) Completions(req *ChatCompletionsRequest) (*ChatCompletionsResponse, error)
Example ¶
cli, _ := chatgpt.NewClient(chatgpt.SetAPIKey(os.Getenv("OPENAI_API_KEY"))) req := &chatgpt.ChatCompletionsRequest{ Model: chatgpt.GPT3dot5Turbo, Messages: []*chatgpt.Message{ {Role: "user", Content: "Hello!"}, }, } res, err := cli.Chat.Completions(req) if err != nil { log.Fatal(err) } fmt.Println(res.Choices[0].Message)
Output:
type ChatService ¶
type ChatService interface {
Completions(req *ChatCompletionsRequest) (*ChatCompletionsResponse, error)
}
type Client ¶
type Client struct { HTTPClient *http.Client Chat ChatService // contains filtered or unexported fields }
func (*Client) CreateAndDo ¶
CreateAndDo performs a web request to OpenAI. The `data`, `options` and `resource` arguments are optional and only relevant in certain situations. If the data argument is non-nil, it will be used as the body of the request for POST and PUT requests. The options argument is used for specifying request options such as search parameters. The resource argument is marshalled data returned from OpenAI. If the resource contains a pointer to data, the data will be overwritten with the content of the response.
func (*Client) Get ¶
Get performs a GET request for the given path and saves the result in the given resource.
func (*Client) NewRequest ¶
NewRequest creates an API request. After creating a request, add the authentication information according to the method specified in NewClient().
func (*Client) Patch ¶
Patch performs a PATCH request for the given path and saves the result in the given resource.
type Option ¶
type Option func(c *Client)