chat_completion

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RoleTool constants.Role = "tool"

Check if RoleTool exists in constants, if not we'll need to handle it

Functions

This section is empty.

Types

type AssistantChatCompletionMessageUnion

type AssistantChatCompletionMessageUnion struct {
	Refusal      *string                         `json:"refusal,omitempty"`
	Name         *string                         `json:"name,omitempty"`
	Audio        AssistantMessageAudio           `json:"audio,omitempty"`
	Content      AssistantMessageContentUnion    `json:"content,omitempty"`
	FunctionCall AssistantMessageFunctionCall    `json:"function_call,omitempty"`
	ToolCalls    []AssistantMessageToolCallUnion `json:"tool_calls,omitempty"`
	Role         *string                         `json:"role,omitempty"` // "assistant"
}

type AssistantMessageAudio

type AssistantMessageAudio struct {
	ID string `json:"id"`
}

type AssistantMessageContentPartUnion

type AssistantMessageContentPartUnion struct {
	OfText    *TextPart    `json:",omitempty"`
	OfRefusal *RefusalPart `json:",omitempty"`
}

func (*AssistantMessageContentPartUnion) MarshalJSON

func (u *AssistantMessageContentPartUnion) MarshalJSON() ([]byte, error)

func (*AssistantMessageContentPartUnion) UnmarshalJSON

func (u *AssistantMessageContentPartUnion) UnmarshalJSON(data []byte) error

type AssistantMessageContentUnion

type AssistantMessageContentUnion struct {
	OfString *string                            `json:",omitempty"`
	OfList   []AssistantMessageContentPartUnion `json:",omitempty"`
}

func (*AssistantMessageContentUnion) MarshalJSON

func (u *AssistantMessageContentUnion) MarshalJSON() ([]byte, error)

func (*AssistantMessageContentUnion) UnmarshalJSON

func (u *AssistantMessageContentUnion) UnmarshalJSON(data []byte) error

type AssistantMessageCustomToolCall

type AssistantMessageCustomToolCall struct {
	Type   string                              `json:"type"` // "custom"
	ID     string                              `json:"id,omitempty"`
	Custom AssistantMessageCustomToolCallParam `json:"custom"`
}

type AssistantMessageCustomToolCallParam

type AssistantMessageCustomToolCallParam struct {
	Name  string `json:"name"`
	Input string `json:"input"`
}

type AssistantMessageFunctionCall

type AssistantMessageFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments,omitempty"`
}

type AssistantMessageFunctionToolCall

type AssistantMessageFunctionToolCall struct {
	Type     string                                `json:"type"` // "function"
	ID       string                                `json:"id,omitempty"`
	Function AssistantMessageFunctionToolCallParam `json:"function"`
}

type AssistantMessageFunctionToolCallParam

type AssistantMessageFunctionToolCallParam struct {
	Name      string `json:"name"`
	Arguments string `json:"input"`
}

type AssistantMessageToolCallUnion

type AssistantMessageToolCallUnion struct {
	OfFunction AssistantMessageFunctionToolCall `json:",omitempty"`
	OfCustom   AssistantMessageCustomToolCall   `json:",omitempty"`
}

func (*AssistantMessageToolCallUnion) MarshalJSON

func (u *AssistantMessageToolCallUnion) MarshalJSON() ([]byte, error)

func (*AssistantMessageToolCallUnion) UnmarshalJSON

func (u *AssistantMessageToolCallUnion) UnmarshalJSON(data []byte) error

type AudioParam

type AudioParam struct {
	Voice  string `json:"voice"`
	Format string `json:"format"`
}

type AudioPart

type AudioPart struct {
	Type       string     `json:"type,omitempty"` // "input_audio"
	InputAudio InputAudio `json:"input_audio,omitempty"`
}

type ChatCompletionChunk

type ChatCompletionChunk struct {
	Id                string                      `json:"id"`
	Object            string                      `json:"object"`
	Created           int                         `json:"created"`
	Model             string                      `json:"model"`
	ServiceTier       string                      `json:"service_tier"`
	SystemFingerprint string                      `json:"system_fingerprint"`
	Choices           []ChatCompletionChunkChoice `json:"choices"`
	Obfuscation       string                      `json:"obfuscation"`
	Usage             *Usage                      `json:"usage,omitempty"`
}

type ChatCompletionChunkChoice

type ChatCompletionChunkChoice struct {
	Index        int                            `json:"index"`
	Delta        ChatCompletionChunkChoiceDelta `json:"delta"`
	FinishReason string                         `json:"finish_reason"`
	Obfuscation  *string                        `json:"obfuscation,omitempty"`
}

type ChatCompletionChunkChoiceDelta

type ChatCompletionChunkChoiceDelta struct {
	Role    constants.Role `json:"role"`
	Content string         `json:"content"`
	Refusal string         `json:"refusal"`
}

type ChatCompletionMessageUnion

type ChatCompletionMessageUnion struct {
	OfDeveloper *DeveloperChatCompletionMessageUnion `json:",omitzero"`
	OfSystem    *SystemChatCompletionMessageUnion    `json:",omitzero"`
	OfUser      *UserChatCompletionMessageUnion      `json:",omitzero"`
	OfAssistant *AssistantChatCompletionMessageUnion `json:",omitzero"`
	OfTool      *ToolChatCompletionMessageUnion      `json:",omitzero"`
	OfFunction  *FunctionChatCompletionMessageUnion  `json:",omitzero"`
}

func (*ChatCompletionMessageUnion) MarshalJSON

func (u *ChatCompletionMessageUnion) MarshalJSON() ([]byte, error)

func (*ChatCompletionMessageUnion) UnmarshalJSON

func (u *ChatCompletionMessageUnion) UnmarshalJSON(data []byte) error

type Choice

type Choice struct {
	FinishReason string         `json:"finish_reason"` // "stop", "length", "content_filter"
	Index        int64          `json:"index"`
	Logprobs     ChoiceLogprobs `json:"logprobs"`
	Message      OutputMessage  `json:"message"`
}

type ChoiceLogprobs

type ChoiceLogprobs struct {
	TextOffset    []int64              `json:"text_offset"`
	TokenLogprobs []float64            `json:"token_logprobs"`
	Tokens        []string             `json:"tokens"`
	TopLogprobs   []map[string]float64 `json:"top_logprobs"`
}

type CompletionUsageCompletionTokensDetails

type CompletionUsageCompletionTokensDetails struct {
	// When using Predicted Outputs, the number of tokens in the prediction that
	// appeared in the completion.
	AcceptedPredictionTokens int64 `json:"accepted_prediction_tokens"`
	// Audio input tokens generated by the model.
	AudioTokens int64 `json:"audio_tokens"`
	// Tokens generated by the model for reasoning.
	ReasoningTokens int64 `json:"reasoning_tokens"`
	// When using Predicted Outputs, the number of tokens in the prediction that did
	// not appear in the completion. However, like reasoning tokens, these tokens are
	// still counted in the total completion tokens for purposes of billing, output,
	// and context window limits.
	RejectedPredictionTokens int64 `json:"rejected_prediction_tokens"`
}

type CompletionUsagePromptTokensDetails

type CompletionUsagePromptTokensDetails struct {
	// Audio input tokens present in the prompt.
	AudioTokens int64 `json:"audio_tokens"`
	// Cached tokens present in the prompt.
	CachedTokens int64 `json:"cached_tokens"`
}

type ContentTypeFile

type ContentTypeFile string

func (*ContentTypeFile) MarshalJSON

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

func (*ContentTypeFile) UnmarshalJSON

func (m *ContentTypeFile) UnmarshalJSON(buf []byte) error

func (*ContentTypeFile) Value

func (m *ContentTypeFile) Value() string

type ContentTypeImageUrl

type ContentTypeImageUrl string

func (*ContentTypeImageUrl) MarshalJSON

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

func (*ContentTypeImageUrl) UnmarshalJSON

func (m *ContentTypeImageUrl) UnmarshalJSON(buf []byte) error

func (*ContentTypeImageUrl) Value

func (m *ContentTypeImageUrl) Value() string

type ContentTypeInputAudio

type ContentTypeInputAudio string

func (*ContentTypeInputAudio) MarshalJSON

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

func (*ContentTypeInputAudio) UnmarshalJSON

func (m *ContentTypeInputAudio) UnmarshalJSON(buf []byte) error

func (*ContentTypeInputAudio) Value

func (m *ContentTypeInputAudio) Value() string

type ContentTypeRefusal

type ContentTypeRefusal string

func (*ContentTypeRefusal) MarshalJSON

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

func (*ContentTypeRefusal) UnmarshalJSON

func (m *ContentTypeRefusal) UnmarshalJSON(buf []byte) error

func (*ContentTypeRefusal) Value

func (m *ContentTypeRefusal) Value() string

type ContentTypeText

type ContentTypeText string

func (*ContentTypeText) MarshalJSON

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

func (*ContentTypeText) UnmarshalJSON

func (m *ContentTypeText) UnmarshalJSON(buf []byte) error

func (*ContentTypeText) Value

func (m *ContentTypeText) Value() string

type DeveloperChatCompletionMessageUnion

type DeveloperChatCompletionMessageUnion struct {
	Name    *string                      `json:"name,omitempty"`
	Role    constants.Role               `json:"role,omitempty"` // "developer"
	Content DeveloperMessageContentUnion `json:"content,omitempty"`
}

type DeveloperMessageContentUnion

type DeveloperMessageContentUnion struct {
	OfString *string    `json:",omitempty"`
	OfList   []TextPart `json:",omitempty"`
}

func (*DeveloperMessageContentUnion) MarshalJSON

func (u *DeveloperMessageContentUnion) MarshalJSON() ([]byte, error)

func (*DeveloperMessageContentUnion) UnmarshalJSON

func (u *DeveloperMessageContentUnion) UnmarshalJSON(data []byte) error

type File

type File struct {
	FileID   *string `json:"file_id,omitempty"`
	Filename *string `json:"filename,omitempty"`
	FileData *string `json:"file_data,omitempty"`
}

type FilePart

type FilePart struct {
	Type string `json:"type,omitempty"`
	File File   `json:"file,omitempty"`
}

type FunctionCallOptionParam

type FunctionCallOptionParam struct {
	Name string `json:"name"`
}

type FunctionCallParam

type FunctionCallParam struct {
	OfFunctionCallMode   *string                  `json:",omitempty"`
	OfFunctionCallOption *FunctionCallOptionParam `json:",omitempty"`
}

type FunctionChatCompletionMessageUnion

type FunctionChatCompletionMessageUnion struct {
	Name    *string        `json:"name,omitempty"`
	Role    constants.Role `json:"role,omitempty"` //
	Content *string        `json:"content,omitempty"`
}

type FunctionsParam

type FunctionsParam struct {
	Name        string         `json:"name"`
	Description *string        `json:"description,omitempty"`
	Parameters  map[string]any `json:"parameters,omitempty"`
}

type ImagePart

type ImagePart struct {
	Type     string   `json:"type,omitempty"` // "image_url"
	ImageUrl ImageUrl `json:"image_url,omitempty"`
}

type ImageUrl

type ImageUrl struct {
	Url    string `json:"url"`
	Detail string `json:"detail"` // "auto", "low", "high"
}

type InputAudio

type InputAudio struct {
	Format string `json:"format,omitzero"` // "wav", "mp3"
	Data   string `json:"data"`
}

type OutputMessage

type OutputMessage struct {
	Role         constants.Role                   `json:"role"`
	Refusal      string                           `json:"refusal"`
	Content      string                           `json:"content"`
	FunctionCall AssistantMessageFunctionCall     `json:"function_call"`
	ToolCalls    []ToolChatCompletionMessageUnion `json:"tool_calls"`
	Audio        OutputMessageAudio               `json:"audio"`
}

type OutputMessageAudio

type OutputMessageAudio struct {
}

type RefusalPart

type RefusalPart struct {
	Type    string `json:"type"` // "refusal"
	Refusal string `json:"refusal,omitempty"`
}

type Request

type Request struct {
	Messages            []ChatCompletionMessageUnion `json:"messages"`
	Model               string                       `json:"model"`
	FrequencyPenalty    *float64                     `json:"frequency_penalty,omitempty"`
	Logprobs            *bool                        `json:"logprobs,omitempty"`
	MaxCompletionTokens *int64                       `json:"max_completion_tokens,omitempty"`
	MaxTokens           *int64                       `json:"max_tokens,omitempty"` // Deprecated in favour of `MaxCompletionTokens`
	N                   *int64                       `json:"n,omitempty"`          // How many choices needs to be generated
	PresencePenalty     *float64                     `json:"presence_penalty,omitempty"`
	Seed                *int64                       `json:"seed,omitempty"`
	Store               *bool                        `json:"store,omitempty"`
	Temperature         *float64                     `json:"temperature,omitempty"`
	TopLogprobs         *int64                       `json:"top_logprobs,omitempty"`
	TopP                *float64                     `json:"top_p,omitempty"`
	ParallelToolCalls   *bool                        `json:"parallel_tool_calls,omitempty"`
	PromptCacheKey      *string                      `json:"prompt_cache_key,omitempty"`
	SafetyIdentifier    *string                      `json:"safety_identifier,omitempty"`
	User                *string                      `json:"user,omitempty"`
	Audio               *AudioParam                  `json:"audio,omitempty"`
	LogitBias           map[string]int64             `json:"logit_bias,omitempty"`
	Metadata            map[string]string            `json:"metadata,omitempty"`
	Modalities          []string                     `json:"modalities,omitempty"`       // "text", "audio"
	ReasoningEffort     *string                      `json:"reasoning_effort,omitempty"` // "minimal", "low", "medium", "high"
	ServiceTier         *string                      `json:"service_tier,omitempty"`     // "auto", "default", "flex", "scale", "priority"
	Stop                *StopParam                   `json:"stop,omitempty"`
	Stream              *bool                        `json:"stream,omitempty"`
	StreamOptions       *StreamOptionParam           `json:"stream_options,omitempty"` // Set only when setting stream=true
	Verbosity           *string                      `json:"verbosity,omitempty"`      // "low", "medium", "high"
	FunctionCall        *FunctionCallParam           `json:"function_call,omitempty"`  // Deprecated in favour of `tool_choice`
	Functions           []FunctionsParam             `json:"functions,omitempty"`      // Deprecated in favour of tools
	Prediction          any                          `json:"prediction,omitempty"`
	ResponseFormat      any                          `json:"response_format,omitempty"`
	ToolChoice          *string                      `json:"tool_choice,omitempty"`
	Tools               any                          `json:"tools,omitempty"`
	WebSearchOptions    any                          `json:"web_search_options,omitempty"`
}

func (*Request) IsStreamingRequest

func (s *Request) IsStreamingRequest() bool

type Response

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

type ResponseChunk

type ResponseChunk struct {
	OfChatCompletionChunk *ChatCompletionChunk `json:",omitempty"`
}

func (*ResponseChunk) MarshalJSON

func (u *ResponseChunk) MarshalJSON() ([]byte, error)

func (*ResponseChunk) UnmarshalJSON

func (u *ResponseChunk) UnmarshalJSON(data []byte) error

type StopParam

type StopParam struct {
	OfString *string  `json:",omitempty"`
	OfList   []string `json:",omitempty"`
}

type StreamOptionParam

type StreamOptionParam struct {
	IncludeObfuscation *bool `json:"include_obfuscation,omitempty"`
	IncludeUsage       *bool `json:"include_usage,omitempty"`
}

type StringConstant

type StringConstant interface {
	Value() string
}

type SystemChatCompletionMessageUnion

type SystemChatCompletionMessageUnion struct {
	Name    *string                   `json:"name,omitempty"`
	Role    constants.Role            `json:"role,omitempty"` // system
	Content SystemMessageContentUnion `json:"content,omitempty"`
}

type SystemMessageContentUnion

type SystemMessageContentUnion struct {
	OfString *string    `json:",omitempty"`
	OfList   []TextPart `json:",omitempty"`
}

func (*SystemMessageContentUnion) MarshalJSON

func (u *SystemMessageContentUnion) MarshalJSON() ([]byte, error)

func (*SystemMessageContentUnion) UnmarshalJSON

func (u *SystemMessageContentUnion) UnmarshalJSON(data []byte) error

type TextPart

type TextPart struct {
	Type string `json:"type,omitempty"` // "text"
	Text string `json:"text,omitempty"`
}

type ToolCallTypeCustom

type ToolCallTypeCustom string

func (*ToolCallTypeCustom) MarshalJSON

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

func (*ToolCallTypeCustom) UnmarshalJSON

func (m *ToolCallTypeCustom) UnmarshalJSON(buf []byte) error

func (*ToolCallTypeCustom) Value

func (m *ToolCallTypeCustom) Value() string

type ToolCallTypeFunction

type ToolCallTypeFunction string

func (*ToolCallTypeFunction) MarshalJSON

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

func (*ToolCallTypeFunction) UnmarshalJSON

func (m *ToolCallTypeFunction) UnmarshalJSON(buf []byte) error

func (*ToolCallTypeFunction) Value

func (m *ToolCallTypeFunction) Value() string

type ToolChatCompletionMessageUnion

type ToolChatCompletionMessageUnion struct {
	Role       constants.Role          `json:"role,omitempty"` // tool
	Content    ToolMessageContentUnion `json:"content,omitempty"`
	ToolCallID string                  `json:"tool_call_id,omitempty"`
}

type ToolMessageContentUnion

type ToolMessageContentUnion struct {
	OfString *string    `json:",omitempty"`
	OfList   []TextPart `json:",omitempty"`
}

func (*ToolMessageContentUnion) MarshalJSON

func (u *ToolMessageContentUnion) MarshalJSON() ([]byte, error)

func (*ToolMessageContentUnion) UnmarshalJSON

func (u *ToolMessageContentUnion) UnmarshalJSON(data []byte) error

type Usage

type Usage struct {
	// Number of tokens in the generated completion.
	CompletionTokens int64 `json:"completion_tokens,required"`
	// Number of tokens in the prompt.
	PromptTokens int64 `json:"prompt_tokens,required"`
	// Total number of tokens used in the request (prompt + completion).
	TotalTokens int64 `json:"total_tokens,required"`
	// Breakdown of tokens used in a completion.
	CompletionTokensDetails CompletionUsageCompletionTokensDetails `json:"completion_tokens_details"`
	// Breakdown of tokens used in the prompt.
	PromptTokensDetails CompletionUsagePromptTokensDetails `json:"prompt_tokens_details"`
}

type UserChatCompletionMessageUnion

type UserChatCompletionMessageUnion struct {
	Name    *string                 `json:"name,omitempty"`
	Role    constants.Role          `json:"role,omitempty"` // user
	Content UserMessageContentUnion `json:"content,omitempty"`
}

type UserMessageContentPartUnion

type UserMessageContentPartUnion struct {
	OfText       *TextPart  `json:",omitempty"`
	OfImageUrl   *ImagePart `json:",omitempty"`
	OfInputAudio *AudioPart `json:",omitempty"`
	OfFile       *FilePart  `json:",omitempty"`
}

func (*UserMessageContentPartUnion) MarshalJSON

func (u *UserMessageContentPartUnion) MarshalJSON() ([]byte, error)

func (*UserMessageContentPartUnion) UnmarshalJSON

func (u *UserMessageContentPartUnion) UnmarshalJSON(data []byte) error

type UserMessageContentUnion

type UserMessageContentUnion struct {
	OfString *string                       `json:",omitempty"`
	OfList   []UserMessageContentPartUnion `json:",omitempty"`
}

func (*UserMessageContentUnion) MarshalJSON

func (u *UserMessageContentUnion) MarshalJSON() ([]byte, error)

func (*UserMessageContentUnion) UnmarshalJSON

func (u *UserMessageContentUnion) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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