openai

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 14 Imported by: 5

Documentation

Overview

openai package provides middleware for partial compatibility with the OpenAI REST API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChatMiddleware added in v0.2.0

func ChatMiddleware() gin.HandlerFunc

func CompletionsMiddleware added in v0.2.0

func CompletionsMiddleware() gin.HandlerFunc

func EmbeddingsMiddleware added in v0.2.6

func EmbeddingsMiddleware() gin.HandlerFunc

func ListMiddleware added in v0.2.0

func ListMiddleware() gin.HandlerFunc

func RetrieveMiddleware added in v0.2.0

func RetrieveMiddleware() gin.HandlerFunc

Types

type BaseWriter added in v0.2.0

type BaseWriter struct {
	gin.ResponseWriter
}

type ChatCompletion

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

type ChatCompletionChunk

type ChatCompletionChunk struct {
	Id                string        `json:"id"`
	Object            string        `json:"object"`
	Created           int64         `json:"created"`
	Model             string        `json:"model"`
	SystemFingerprint string        `json:"system_fingerprint"`
	Choices           []ChunkChoice `json:"choices"`
	Usage             *Usage        `json:"usage,omitempty"`
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model            string          `json:"model"`
	Messages         []Message       `json:"messages"`
	Stream           bool            `json:"stream"`
	StreamOptions    *StreamOptions  `json:"stream_options"`
	MaxTokens        *int            `json:"max_tokens"`
	Seed             *int            `json:"seed"`
	Stop             any             `json:"stop"`
	Temperature      *float64        `json:"temperature"`
	FrequencyPenalty *float64        `json:"frequency_penalty"`
	PresencePenalty  *float64        `json:"presence_penalty"`
	TopP             *float64        `json:"top_p"`
	ResponseFormat   *ResponseFormat `json:"response_format"`
	Tools            []api.Tool      `json:"tools"`
}

type ChatWriter added in v0.2.0

type ChatWriter struct {
	BaseWriter
	// contains filtered or unexported fields
}

func (*ChatWriter) Write added in v0.2.0

func (w *ChatWriter) Write(data []byte) (int, error)

type Choice

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

type ChunkChoice

type ChunkChoice struct {
	Index        int     `json:"index"`
	Delta        Message `json:"delta"`
	FinishReason *string `json:"finish_reason"`
}

type CompleteChunkChoice added in v0.2.0

type CompleteChunkChoice struct {
	Text         string  `json:"text"`
	Index        int     `json:"index"`
	FinishReason *string `json:"finish_reason"`
}

type CompleteWriter added in v0.2.0

type CompleteWriter struct {
	BaseWriter
	// contains filtered or unexported fields
}

func (*CompleteWriter) Write added in v0.2.0

func (w *CompleteWriter) Write(data []byte) (int, error)

type Completion added in v0.2.0

type Completion struct {
	Id                string                `json:"id"`
	Object            string                `json:"object"`
	Created           int64                 `json:"created"`
	Model             string                `json:"model"`
	SystemFingerprint string                `json:"system_fingerprint"`
	Choices           []CompleteChunkChoice `json:"choices"`
	Usage             Usage                 `json:"usage,omitempty"`
}

type CompletionChunk added in v0.2.0

type CompletionChunk struct {
	Id                string                `json:"id"`
	Object            string                `json:"object"`
	Created           int64                 `json:"created"`
	Choices           []CompleteChunkChoice `json:"choices"`
	Model             string                `json:"model"`
	SystemFingerprint string                `json:"system_fingerprint"`
	Usage             *Usage                `json:"usage,omitempty"`
}

type CompletionRequest added in v0.2.0

type CompletionRequest struct {
	Model            string         `json:"model"`
	Prompt           string         `json:"prompt"`
	FrequencyPenalty float32        `json:"frequency_penalty"`
	MaxTokens        *int           `json:"max_tokens"`
	PresencePenalty  float32        `json:"presence_penalty"`
	Seed             *int           `json:"seed"`
	Stop             any            `json:"stop"`
	Stream           bool           `json:"stream"`
	StreamOptions    *StreamOptions `json:"stream_options"`
	Temperature      *float32       `json:"temperature"`
	TopP             float32        `json:"top_p"`
	Suffix           string         `json:"suffix"`
}

TODO (https://github.com/ollama/ollama/issues/5259): support []string, []int and [][]int

type EmbedRequest added in v0.2.6

type EmbedRequest struct {
	Input any    `json:"input"`
	Model string `json:"model"`
}

type EmbedWriter added in v0.2.6

type EmbedWriter struct {
	BaseWriter
	// contains filtered or unexported fields
}

func (*EmbedWriter) Write added in v0.2.6

func (w *EmbedWriter) Write(data []byte) (int, error)

type Embedding added in v0.2.6

type Embedding struct {
	Object    string    `json:"object"`
	Embedding []float32 `json:"embedding"`
	Index     int       `json:"index"`
}

type EmbeddingList added in v0.2.6

type EmbeddingList struct {
	Object string         `json:"object"`
	Data   []Embedding    `json:"data"`
	Model  string         `json:"model"`
	Usage  EmbeddingUsage `json:"usage,omitempty"`
}

type EmbeddingUsage added in v0.3.3

type EmbeddingUsage struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

type Error

type Error struct {
	Message string  `json:"message"`
	Type    string  `json:"type"`
	Param   any     `json:"param"`
	Code    *string `json:"code"`
}

type ErrorResponse

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

func NewError

func NewError(code int, message string) ErrorResponse

type JsonSchema added in v0.5.0

type JsonSchema struct {
	Schema json.RawMessage `json:"schema"`
}

type ListCompletion added in v0.2.0

type ListCompletion struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

type ListWriter added in v0.2.0

type ListWriter struct {
	BaseWriter
}

func (*ListWriter) Write added in v0.2.0

func (w *ListWriter) Write(data []byte) (int, error)

type Message

type Message struct {
	Role      string     `json:"role"`
	Content   any        `json:"content"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

type Model added in v0.2.0

type Model struct {
	Id      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	OwnedBy string `json:"owned_by"`
}

type ResponseFormat

type ResponseFormat struct {
	Type       string      `json:"type"`
	JsonSchema *JsonSchema `json:"json_schema,omitempty"`
}

type RetrieveWriter added in v0.2.0

type RetrieveWriter struct {
	BaseWriter
	// contains filtered or unexported fields
}

func (*RetrieveWriter) Write added in v0.2.0

func (w *RetrieveWriter) Write(data []byte) (int, error)

type StreamOptions added in v0.5.2

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage"`
}

type ToolCall added in v0.2.6

type ToolCall struct {
	ID       string `json:"id"`
	Index    int    `json:"index"`
	Type     string `json:"type"`
	Function struct {
		Name      string `json:"name"`
		Arguments string `json:"arguments"`
	} `json:"function"`
}

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