openai

package
v0.0.0-...-09cb31e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelTextDavinciEdit001 = "text-davinci-edit-001"
	ModelGpt0305Turbo       = "gpt-3.5-turbo"
	ModelGpt0305Turbo_0301  = "gpt-3.5-turbo-0301"
	ModelGpt04              = "gpt-4"
	ModelGpt04_0314         = "gpt-4-0314"
)
View Source
const ChatAPIPath = "/v1/chat/completions"

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Role    ChatRole `json:"role"`
	Content string   `json:"content"`
}

type ChatRequest

type ChatRequest struct {
	Model            string             `json:"model"`
	Messages         []ChatMessage      `json:"messages"`
	Temperature      *float64           `json:"temperature,omitempty"` // What sampling temperature to use, between 0 and 2.
	TopP             *float64           `json:"top_p,omitempty"`       // Nucleus sampling. Specify this or temperature but not both.
	N                int                `json:"n,omitempty"`           // How many chat completion choices to generate for each input message.
	Stream           bool               `json:"stream,omitempty"`      // If set, partial message deltas will be sent as data-only server-sent events as they become available.
	Stop             []string           `json:"stop,omitempty"`        // Up to 4 sequences where the API will stop generating further tokens.
	MaxTokens        int                `json:"max_tokens,omitempty"`
	PresencePenalty  *float64           `json:"presence_penalty,omitempty"`  // Number between -2.0 and 2.0.
	FrequencyPenalty *float64           `json:"frequency_penalty,omitempty"` // Number between -2.0 and 2.0.
	LogitBias        map[string]float64 `json:"logit_bias,omitempty"`        // Modify the likelihood of specified tokens appearing in the completion.
	User             string             `json:"user,omitempty"`              // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
}

type ChatResponse

type ChatResponse struct {
	ID      string               `json:"id"`
	Object  string               `json:"object"`
	Created int                  `json:"created"`
	Model   string               `json:"model"`
	Usage   map[string]int       `json:"usage"`
	Choices []ChatResponseChoice `json:"choices"`
}

type ChatResponseChoice

type ChatResponseChoice struct {
	Message      ChatMessage `json:"message"`
	FinishReason string      `json:"finish_reason"`
	Index        int         `json:"index"`
}

type ChatResponseStream

type ChatResponseStream struct {
	ID      string
	Object  string
	Created int
	Model   string
	Stream  chan string
	Done    chan struct{}
	Err     error
}

type ChatResponseStreamChoice

type ChatResponseStreamChoice struct {
	Index        int    `json:"index"`
	FinishReason string `json:"finish_reason"`
	Delta        struct {
		Content string `json:"content"`
	} `json:"delta"`
}

type ChatResponseStreamChunk

type ChatResponseStreamChunk struct {
	ID      string
	Object  string
	Created int
	Model   string
	Choices []ChatResponseStreamChoice
}

type ChatRole

type ChatRole string
const (
	ChatRoleSystem    ChatRole = "system"
	ChatRoleAssistant ChatRole = "assistant"
	ChatRoleUser      ChatRole = "user"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string) *Client

func (*Client) ChatCompletion

func (c *Client) ChatCompletion(request ChatRequest) (*ChatResponse, error)

func (*Client) ChatCompletionStream

func (c *Client) ChatCompletionStream(request ChatRequest) (*ChatResponseStream, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL