Documentation ¶
Overview ¶
Package completion contains a client for OpenAI's completion API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // CreateEndpoint allows overriding the default API endpoint. // Set this field before using the client. CreateEndpoint string // contains filtered or unexported fields }
Client is a client to communicate with Open AI's completions API.
func NewClient ¶
NewClient creates a new default client that uses the given session and defaults to the given model.
func (*Client) Create ¶
func (c *Client) Create(ctx context.Context, p *CreateParams) (*CreateResponse, error)
Create creates a completion for the provided parameters.
type CreateParams ¶
type CreateParams struct { Model string `json:"model,omitempty"` Prompt []string `json:"prompt,omitempty"` Stop []string `json:"stop,omitempty"` Suffix string `json:"suffix,omitempty"` Stream bool `json:"stream,omitempty"` Echo bool `json:"echo,omitempty"` MaxTokens int `json:"max_tokens,omitempty"` N int `json:"n,omitempty"` TopP float64 `json:"top_p,omitempty"` Temperature float64 `json:"temperature,omitempty"` LogProbs int `json:"logprobs,omitempty"` PresencePenalty float64 `json:"presence_penalty,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` BestOf int `json:"best_of,omitempty"` User string `json:"user,omitempty"` }
CreateParams are completion parameters. Refer to OpenAI documentation at https://platform.openai.com/docs/api-reference/completions/create for reference.
type CreateResponse ¶
type CreateResponse struct { ID string `json:"id,omitempty"` Object string `json:"object,omitempty"` CreatedAt int64 `json:"created_at,omitempty"` Choices []*Choice `json:"choices,omitempty"` Usage *openai.Usage `json:"usage,omitempty"` }
CreateResponse is a response to a completion. Refer to OpenAI documentation at https://platform.openai.com/docs/api-reference/completions/create for reference.
type StreamingClient ¶ added in v1.0.3
type StreamingClient struct { // CreateEndpoint allows overriding the default API endpoint. // Set this field before using the client. CreateEndpoint string // contains filtered or unexported fields }
StreamingClient is a client to communicate with Open AI's completions API.
func NewStreamingClient ¶ added in v1.0.3
func NewStreamingClient(session *openai.Session, model string) *StreamingClient
NewStreamingClient creates a new default streaming client that uses the given session and defaults to the given model.
func (*StreamingClient) Create ¶ added in v1.0.3
func (c *StreamingClient) Create(ctx context.Context, p *CreateParams, fn func(r *CreateResponse)) error
Create creates a completion for the provided parameters.