openai

package
v0.0.0-...-d39df66 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletion

type ChatCompletion struct {
	Object string `json:"object"` // "chat.completion" | "chat.completion.chunk"

	ID string `json:"id"`

	Model   string `json:"model"`
	Created int64  `json:"created"`

	Choices []ChatCompletionChoice `json:"choices"`

	Usage *Usage `json:"usage,omitempty"`
}

https://platform.openai.com/docs/api-reference/chat/object

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index int `json:"index"`

	Delta   *ChatCompletionMessage `json:"delta,omitempty"`
	Message *ChatCompletionMessage `json:"message,omitempty"`

	FinishReason *FinishReason `json:"finish_reason"`
}

https://platform.openai.com/docs/api-reference/chat/object

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role MessageRole `json:"role,omitempty"`

	Content  string           `json:"content"`
	Contents []MessageContent `json:"-"`

	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
}

https://platform.openai.com/docs/api-reference/chat/object

func (*ChatCompletionMessage) MarshalJSON

func (m *ChatCompletionMessage) MarshalJSON() ([]byte, error)

func (*ChatCompletionMessage) UnmarshalJSON

func (m *ChatCompletionMessage) UnmarshalJSON(data []byte) error

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model string `json:"model"`

	Messages []ChatCompletionMessage `json:"messages"`

	Stream bool   `json:"stream,omitempty"`
	Stop   any    `json:"stop,omitempty"`
	Tools  []Tool `json:"tools,omitempty"`

	MaxTokens   *int     `json:"max_tokens,omitempty"`
	Temperature *float32 `json:"temperature,omitempty"`

	ResponseFormat *ChatCompletionResponseFormat `json:"response_format,omitempty"`
}

https://platform.openai.com/docs/api-reference/chat/create

type ChatCompletionResponseFormat

type ChatCompletionResponseFormat struct {
	Type       ResponseFormat `json:"type"`
	JSONSchema *Schema        `json:"json_schema,omitempty"`
}

https://platform.openai.com/docs/api-reference/chat/create

type Embedding

type Embedding struct {
	Object string `json:"object"` // "embedding"

	Index     int       `json:"index"`
	Embedding []float32 `json:"embedding"`
}

https://platform.openai.com/docs/api-reference/embeddings/object

type EmbeddingList

type EmbeddingList struct {
	Object string `json:"object"` // "list"

	Model string      `json:"model"`
	Data  []Embedding `json:"data"`

	Usage *Usage `json:"usage,omitempty"`
}

https://platform.openai.com/docs/api-reference/embeddings/create

type EmbeddingsRequest

type EmbeddingsRequest struct {
	Model string `json:"model"`

	Input any `json:"input"`
}

https://platform.openai.com/docs/api-reference/embeddings/create

func (*EmbeddingsRequest) UnmarshalJSON

func (r *EmbeddingsRequest) UnmarshalJSON(data []byte) error

type Error

type Error struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	Error Error `json:"error,omitempty"`
}

type FinishReason

type FinishReason string

https://platform.openai.com/docs/api-reference/chat/object

var (
	FinishReasonStop   FinishReason = "stop"
	FinishReasonLength FinishReason = "length"

	FinishReasonToolCalls     FinishReason = "tool_calls"
	FinishReasonContentFilter FinishReason = "content_filter"
)

type Function

type Function struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`

	Strict *bool `json:"strict,omitempty"`

	Parameters map[string]any `json:"parameters"`
}

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

https://platform.openai.com/docs/api-reference/chat/object

type Handler

type Handler struct {
	*config.Config
	http.Handler
}

func New

func New(cfg *config.Config) (*Handler, error)

func (*Handler) Attach

func (h *Handler) Attach(r chi.Router)

type Image

type Image struct {
	URL     string `json:"url,omitempty"`
	B64JSON string `json:"b64_json,omitempty"`

	RevisedPrompt string `json:"revised_prompt,omitempty"`
}

https://platform.openai.com/docs/api-reference/images/object

type ImageCreateRequest

type ImageCreateRequest struct {
	Model string `json:"model"`

	Prompt string     `json:"prompt"`
	Style  ImageStyle `json:"style,omitempty"`

	ResponseFormat string `json:"response_format,omitempty"`
}

https://platform.openai.com/docs/api-reference/images/create

type ImageList

type ImageList struct {
	Images []Image `json:"data"`
}

https://platform.openai.com/docs/api-reference/images/create

type ImageStyle

type ImageStyle string
const (
	ImageStyleNatural ImageStyle = "natural"
	ImageStyleVivid   ImageStyle = "vivid"
)

type MessageContent

type MessageContent struct {
	Type MessageContentType `json:"type,omitempty"`

	Text string `json:"text,omitempty"`

	FileURL  *MessageContentURL `json:"file_url,omitempty"` // non-standard
	ImageURL *MessageContentURL `json:"image_url,omitempty"`
}

type MessageContentType

type MessageContentType string
var (
	MessageContentTypeText     MessageContentType = "text"
	MessageContentTypeFileURL  MessageContentType = "file_url" // non-standard
	MessageContentTypeImageURL MessageContentType = "image_url"
)

type MessageContentURL

type MessageContentURL struct {
	URL string `json:"url"`
}

type MessageRole

type MessageRole string
var (
	MessageRoleSystem    MessageRole = "system"
	MessageRoleUser      MessageRole = "user"
	MessageRoleAssistant MessageRole = "assistant"
	MessageRoleTool      MessageRole = "tool"
)

type Model

type Model struct {
	Object string `json:"object"` // "model"

	ID      string `json:"id"`
	Created int64  `json:"created"`
	OwnedBy string `json:"owned_by"`
}

https://platform.openai.com/docs/api-reference/models/object

type ModelList

type ModelList struct {
	Object string `json:"object"` // "list"

	Models []Model `json:"data"`
}

https://platform.openai.com/docs/api-reference/models

type ResponseFormat

type ResponseFormat string
var (
	ResponseFormatText       ResponseFormat = "text"
	ResponseFormatJSONObject ResponseFormat = "json_object"
	ResponseFormatJSONSchema ResponseFormat = "json_schema"
)

type Schema

type Schema struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`

	Strict *bool `json:"strict,omitempty"`

	Schema map[string]any `json:"schema"`
}

type SpeechRequest

type SpeechRequest struct {
	Model string `json:"model"`

	Input string `json:"input"`
	Voice string `json:"voice"`
}

https://platform.openai.com/docs/api-reference/audio/createSpeech

type Tool

type Tool struct {
	Type ToolType `json:"type"`

	ToolFunction *Function `json:"function"`
}

type ToolCall

type ToolCall struct {
	ID string `json:"id"`

	Type ToolType `json:"type"`

	Index int `json:"index"`

	Function *FunctionCall `json:"function,omitempty"`
}

https://platform.openai.com/docs/api-reference/chat/object

type ToolType

type ToolType string

https://platform.openai.com/docs/api-reference/chat/object

var (
	ToolTypeFunction ToolType = "function"
)

type Transcription

type Transcription struct {
	Task string `json:"task"`

	Language string  `json:"language"`
	Duration float64 `json:"duration"`

	Text string `json:"text"`
}

type Usage

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

Jump to

Keyboard shortcuts

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