openai

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatURL  = "https://api.openai.com/v1/chat/completions"
	PhotoURL = "https://api.openai.com/v1/images/generations"
)

Variables

This section is empty.

Functions

func NewPhotoQuerier

func NewPhotoQuerier(pConf photo.Configurations) (models.Querier, error)

func NewTextQuerier

func NewTextQuerier(conf text.Configurations) (models.ChatQuerier, error)

NewTextQuerier returns a new ChatGPT querier using the textconfigurations to load the correct model. API key is fetched via environment variable

Types

type ChatCompletion

type ChatCompletion struct {
	ID                string   `json:"id"`
	Object            string   `json:"object"`
	Created           int64    `json:"created"`
	Model             string   `json:"model"`
	Choices           []Choice `json:"choices"`
	Usage             Usage    `json:"usage"`
	SystemFingerprint string   `json:"system_fingerprint"`
}

type ChatGPT

type ChatGPT struct {
	Model            string  `json:"model"`
	FrequencyPenalty float32 `json:"frequency_penalty"`
	MaxTokens        *int    `json:"max_tokens"` // Use a pointer to allow null value
	PresencePenalty  float32 `json:"presence_penalty"`
	Temperature      float32 `json:"temperature"`
	TopP             float32 `json:"top_p"`
	Url              string  `json:"url"`
	Raw              bool    `json:"raw"`
	// contains filtered or unexported fields
}

func (*ChatGPT) Query

func (q *ChatGPT) Query(ctx context.Context) error

Query performs a streamCompletion and appends the returned message to it's internal chat. Then it stores the internal chat as prevQuery.json, so that it may be used n upcoming queries

func (*ChatGPT) TextQuery

func (q *ChatGPT) TextQuery(ctx context.Context, chat models.Chat) (models.Chat, error)

TextQuery performs a streamCompletion and appends the returned message to it's internal chat. It therefore does not store it to prevQuery.json, and assumes that the calee will deal with storing the chat.

type Choice

type Choice struct {
	Index        int            `json:"index"`
	Message      models.Message `json:"message"`
	Logprobs     interface{}    `json:"logprobs"` // null or complex object, hence interface{}
	FinishReason string         `json:"finish_reason"`
}

type DallE

type DallE struct {
	Model   string       `json:"model"`
	N       int          `json:"n"`
	Size    string       `json:"size"`
	Quality string       `json:"quality"`
	Style   string       `json:"style"`
	Output  photo.Output `json:"output"`
	// Don't save this as this is set via the Output struct
	ResponseFormat string `json:"-"`
	Prompt         string `json:"-"`
	// contains filtered or unexported fields
}

func (*DallE) Query

func (q *DallE) Query(ctx context.Context) error

type DallERequest

type DallERequest struct {
	Model          string `json:"model"`
	N              int    `json:"n"`
	Size           string `json:"size"`
	Quality        string `json:"quality"`
	Style          string `json:"style"`
	ResponseFormat string `json:"response_format"`
	Prompt         string `json:"prompt"`
}

type ImageResponse

type ImageResponse struct {
	RevisedPrompt string `json:"revised_prompt"`
	URL           string `json:"url"`
	B64_JSON      string `json:"b64_json"`
}

type ImageResponses

type ImageResponses struct {
	Created int             `json:"created"`
	Data    []ImageResponse `json:"data"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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