openai

package
v0.0.0-...-fa30edc Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleSystem    = "system"
)
View Source
const (
	GPT35Turbo = "gpt-3.5-turbo-1106"
	GPT4       = "gpt-4-1106-preview"
)
View Source
const (
	DALLE3 = "dall-e-3"
	GPT4V  = "gpt-4-vision-preview"
)
View Source
const (
	TTS     = "tts-1"
	TTS_HQ  = "tts-1-hq"
	WHISPER = "whisper-1"
)

Variables

This section is empty.

Functions

func ConvertPNGToDataURI

func ConvertPNGToDataURI(data []byte) string

func CreateImageRequest

func CreateImageRequest(token string, prompt string) (*http.Request, error)

func CreateSpeechToTextRequest

func CreateSpeechToTextRequest(token string, audio []byte) (*http.Request, error)

func CreateTextCompletionRequest

func CreateTextCompletionRequest(token string, model string, messages Messages) (*http.Request, error)

func CreateTextToSpeechRequest

func CreateTextToSpeechRequest(token string, text string, opts ...TTSReqOptions) (*http.Request, error)

func CreateVisionRequest

func CreateVisionRequest(token string, messages Messages) (*http.Request, error)

func Do

func Do(ctx context.Context, token string, prompt Prompt) (io.Reader, error)

func DoImageRequest

func DoImageRequest(ctx context.Context, token string, prompt string) ([]byte, error)

func ErrorBadRequest

func ErrorBadRequest(r http.Response) error

func ErrorRateLimitExceeded

func ErrorRateLimitExceeded(r http.Response) error

func NewClientError

func NewClientError(r *http.Response) error

func ParseCreateImageResponse

func ParseCreateImageResponse(resp *http.Response) (string, error)

func ParseLinkToImage

func ParseLinkToImage(link string) ([]byte, error)

func ParseTextCompletionRequest

func ParseTextCompletionRequest(resp *http.Response) (io.Reader, error)

func ParseVisionResponse

func ParseVisionResponse(resp *http.Response) (io.Reader, error)

func SpeechToText

func SpeechToText(ctx context.Context, token string, audio []byte) (string, error)

func TextToSpeech

func TextToSpeech(ctx context.Context, token string, text string) ([]byte, error)

func URLToURI

func URLToURI(url url.URL) (string, error)

Types

type BadRequestError

type BadRequestError struct {
	PromptTokens int
	TotalTokens  int
	TokenLimit   int
}

func (BadRequestError) Error

func (e BadRequestError) Error() string

type ClientError

type ClientError struct {
	Status     string
	StatusCode int
}

func (ClientError) Error

func (e ClientError) Error() string

type ImageRequest

type ImageRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
	N      int    `json:"n"`
	Size   string `json:"size"`
}

Image Generation Capability

type ImageResponse

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

type Message

type Message interface {
	GetFormat() string
}

type Messages

type Messages []Message

func MessageFromPrompt

func MessageFromPrompt(prompt Prompt) Messages

type Prompt

type Prompt interface {
	GetPurpose() string
	GetHistory() ([]string, []string)
	GetQuestion() string
	GetReferences() [][]byte
}

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
}

func (RateLimitError) Error

func (e RateLimitError) Error() string

type TTSReqOptions

func WithVoice

func WithVoice(voice Voice) TTSReqOptions

type TextCompletionRequest

type TextCompletionRequest struct {
	Model    string   `json:"model"`
	Messages Messages `json:"messages"`
}

type TextCompletionResponse

type TextCompletionResponse struct {
	Choices []struct {
		Message TextMessage `json:"message"`
	} `json:"choices"`
}

type TextMessage

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

func (TextMessage) GetFormat

func (m TextMessage) GetFormat() string

type TextToSpeechRequestBody

type TextToSpeechRequestBody struct {
	Model string `json:"model"`
	Input string `json:"input"`
	Voice Voice  `json:"voice"`
}

type VisionCompletionResponse

type VisionCompletionResponse struct {
	Choices []struct {
		Message struct {
			Content string `json:"content"`
		} `json:"message"`
	} `json:"choices"`
}

type VisionImageURL

type VisionImageURL struct {
	Type     string `json:"type"`
	ImageURL struct {
		URL string `json:"url"`
	} `json:"image_url"`
}

type VisionMessage

type VisionMessage struct {
	Role    string           `json:"role"`
	Content []VisionImageURL `json:"content"`
}

func (VisionMessage) GetContent

func (m VisionMessage) GetContent() string

func (VisionMessage) GetFormat

func (m VisionMessage) GetFormat() string

type VisionRequest

type VisionRequest struct {
	Model     string   `json:"model"`
	Messages  Messages `json:"messages"`
	MaxTokens int      `json:"max_tokens"`
}

type Voice

type Voice string
const (
	Alloy   Voice = "alloy"
	Echo    Voice = "echo"
	Fable   Voice = "fable"
	Onyx    Voice = "onyx"
	Nova    Voice = "nova"
	Shimmer Voice = "shimmer"
)

Jump to

Keyboard shortcuts

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