types

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeText     = "text"
	ContentTypeImageURL = "image_url"
)
View Source
const (
	FinishReasonStop          = "stop"
	FinishReasonLength        = "length"
	FinishReasonFunctionCall  = "function_call"
	FinishReasonToolCalls     = "tool_calls"
	FinishReasonContentFilter = "content_filter"
	FinishReasonNull          = "null"
)
View Source
const (
	ChatMessageRoleSystem    = "system"
	ChatMessageRoleDeveloper = "developer"
	ChatMessageRoleUser      = "user"
	ChatMessageRoleAssistant = "assistant"
	ChatMessageRoleFunction  = "function"
	ChatMessageRoleTool      = "tool"
)
View Source
const (
	ToolChoiceTypeFunction = "function"
	ToolChoiceTypeAuto     = "auto"
	ToolChoiceTypeNone     = "none"
	ToolChoiceTypeRequired = "required"
)
View Source
const (
	EventTypeResponseDone   = "response.done"
	EventTypeSessionCreated = "session.created"
	EventTypeError          = "error"
)
View Source
const (
	APITollTypeWebSearchPreview = "web_search_preview"
	APITollTypeFileSearch       = "file_search"
	APITollTypeCodeInterpreter  = "code_interpreter"
	APITollTypeImageGeneration  = "image_generation"
)
View Source
const (
	InputTypeMessage              = "message"
	InputTypeFileSearchCall       = "file_search_call"
	InputTypeComputerCall         = "computer_call"
	InputTypeWebSearchCall        = "web_search_call"
	InputTypeComputerCallOutput   = "computer_call_output"
	InputTypeFunctionCall         = "function_call"
	InputTypeFunctionCallOutput   = "function_call_output"
	InputTypeReasoning            = "reasoning"
	InputTypeImageGenerationCall  = "image_generation_call"
	InputTypeCodeInterpreterCall  = "code_interpreter_call"
	InputTypeLocalShellCall       = "local_shell_call"
	InputTypeLocalShellCallOutput = "local_shell_call_output"
	InputTypeMCPListTools         = "mcp_list_tools"
	InputTypeMCPApprovalRequest   = "mcp_approval_request"
	InputTypeMCPApprovalResponse  = "mcp_approval_response"
	InputTypeMCPCall              = "mcp_call"
)
View Source
const (
	ContentTypeInputText   = "input_text"
	ContentTypeInputImage  = "input_image"
	ContentTypeInputFile   = "input_file"
	ContentTypeOutputText  = "output_text"
	ContentTypeSummaryText = "summary_text"
	ContentTypeRefusal     = "refusal"
)

input_text / input_image / input_file / output_text / refusal

View Source
const (
	ResponseStatusCompleted  = "completed"
	ResponseStatusFailed     = "failed"
	ResponseStatusInProgress = "in_progress"
	ResponseStatusCancelled  = "cancelled"
	ResponseStatusQueued     = "queued"
	ResponseStatusIncomplete = "incomplete"
)

completed, failed, in_progress, cancelled, queued, or incomplete

View Source
const (
	VideoModeTextToVideo  = "text2video"
	VideoModeImageToVideo = "image2video"

	VideoStatusSubmitted  = "submitted"
	VideoStatusQueued     = "queued"
	VideoStatusProcessing = "processing"
	VideoStatusCompleted  = "completed"
	VideoStatusFailed     = "failed"
)
View Source
const TaskSuccessCode = "success"

Variables

This section is empty.

Functions

func ConvertChatStatusToResponses

func ConvertChatStatusToResponses(status string) string

func ConvertResponsesStatusToChat

func ConvertResponsesStatusToChat(status string) string

Types

type Annotations

type Annotations struct {
	Type string `json:"type"` // file_citation / url_citation / container_file_citation / file_path
	// file_citation
	FileId string `json:"file_id,omitempty"` // The ID of the file that is cited.
	Index  int    `json:"index,omitempty"`   // The index of the file that is cited.

	// url_citation
	Url        string `json:"url,omitempty"`         // The URL of the web resource.
	Title      string `json:"title,omitempty"`       // The title of the web resource.
	StartIndex int    `json:"start_index,omitempty"` // The index of the first character of the URL citation in the message.
	EndIndex   int    `json:"end_index,omitempty"`   // The index of the last character of the URL citation in the message.

	// container_file_citation
	ContainerId string `json:"container_id,omitempty"` // The ID of the container file.

}

type Assistant

type Assistant struct {
	ID           string         `json:"id"`
	Object       string         `json:"object"`
	CreatedAt    int64          `json:"created_at"`
	Name         *string        `json:"name,omitempty"`
	Description  *string        `json:"description,omitempty"`
	Model        string         `json:"model"`
	Instructions *string        `json:"instructions,omitempty"`
	Tools        any            `json:"tools,omitempty"`
	FileIDs      []string       `json:"file_ids,omitempty"`
	Metadata     map[string]any `json:"metadata,omitempty"`
}

type AssistantDeleteResponse

type AssistantDeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Deleted bool   `json:"deleted"`
}

type AssistantFile

type AssistantFile struct {
	ID          string `json:"id"`
	Object      string `json:"object"`
	CreatedAt   int64  `json:"created_at"`
	AssistantID string `json:"assistant_id"`
}

type AssistantFileRequest

type AssistantFileRequest struct {
	FileID string `json:"file_id"`
}

type AssistantFilesList

type AssistantFilesList struct {
	AssistantFiles []AssistantFile `json:"data"`
}

type AssistantRequest

type AssistantRequest struct {
	Model        string         `json:"model"`
	Name         *string        `json:"name,omitempty"`
	Description  *string        `json:"description,omitempty"`
	Instructions *string        `json:"instructions,omitempty"`
	Tools        any            `json:"tools,omitempty"`
	FileIDs      []string       `json:"file_ids,omitempty"`
	Metadata     map[string]any `json:"metadata,omitempty"`
}

type AssistantsList

type AssistantsList struct {
	Assistants []Assistant `json:"data"`
	LastID     *string     `json:"last_id"`
	FirstID    *string     `json:"first_id"`
	HasMore    bool        `json:"has_more"`
}

AssistantsList is a list of assistants.

type AudioRequest

type AudioRequest struct {
	File           *multipart.FileHeader `form:"file" binding:"required"`
	Model          string                `form:"model" binding:"required"`
	Language       string                `form:"language"`
	Prompt         string                `form:"prompt"`
	ResponseFormat string                `form:"response_format"`
	Temperature    float32               `form:"temperature"`
}

type AudioResponse

type AudioResponse struct {
	Task     string           `json:"task,omitempty"`
	Language string           `json:"language,omitempty"`
	Duration float64          `json:"duration,omitempty"`
	Segments any              `json:"segments,omitempty"`
	Text     string           `json:"text"`
	Words    []AudioWordsList `json:"words,omitempty"`
}

type AudioResponseWrapper

type AudioResponseWrapper struct {
	Headers map[string]string
	Body    []byte
}

type AudioWordsList

type AudioWordsList struct {
	Word  string  `json:"word"`
	Start float64 `json:"start"`
	End   float64 `json:"end"`
}

type ChatAudio

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

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index                int                   `json:"index"`
	Message              ChatCompletionMessage `json:"message"`
	LogProbs             any                   `json:"logprobs,omitempty"`
	FinishReason         string                `json:"finish_reason,omitempty"`
	ContentFilterResults any                   `json:"content_filter_results,omitempty"`
	FinishDetails        any                   `json:"finish_details,omitempty"`
}

func (*ChatCompletionChoice) CheckChoice

func (c *ChatCompletionChoice) CheckChoice(request *ChatCompletionRequest)

type ChatCompletionFunction

type ChatCompletionFunction struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Parameters  any    `json:"parameters"`
	Strict      *bool  `json:"strict,omitempty"`
}

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role             string                           `json:"role"`
	Content          any                              `json:"content,omitempty"`
	Refusal          string                           `json:"refusal,omitempty"`
	ReasoningContent string                           `json:"reasoning_content,omitempty"`
	Reasoning        string                           `json:"reasoning,omitempty"`
	Name             *string                          `json:"name,omitempty"`
	FunctionCall     *ChatCompletionToolCallsFunction `json:"function_call,omitempty"`
	ToolCalls        []*ChatCompletionToolCalls       `json:"tool_calls,omitempty"`
	ToolCallID       string                           `json:"tool_call_id,omitempty"`
	Audio            any                              `json:"audio,omitempty"`
	Annotations      any                              `json:"annotations,omitempty"`
	Image            []MultimediaData                 `json:"image,omitempty"`
	Images           []ChatMessagePart                `json:"images,omitempty"`
	CacheControl     any                              `json:"cache_control,omitempty"`
}

func (*ChatCompletionMessage) FuncToToolCalls

func (m *ChatCompletionMessage) FuncToToolCalls()

将FunctionCall转换为ToolCalls

func (*ChatCompletionMessage) IsSystemRole

func (m *ChatCompletionMessage) IsSystemRole() bool

func (ChatCompletionMessage) ParseContent

func (m ChatCompletionMessage) ParseContent() []ChatMessagePart

func (ChatCompletionMessage) StringContent

func (m ChatCompletionMessage) StringContent() string

func (*ChatCompletionMessage) ToolToFuncCalls

func (m *ChatCompletionMessage) ToolToFuncCalls()

将ToolCalls转换为FunctionCall

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model               string                        `json:"model" binding:"required"`
	Messages            []ChatCompletionMessage       `json:"messages" binding:"required"`
	System              any                           `json:"system,omitempty"`
	MaxTokens           int                           `json:"max_tokens,omitempty"`
	MaxCompletionTokens int                           `json:"max_completion_tokens,omitempty"`
	Temperature         *float64                      `json:"temperature,omitempty"`
	TopP                *float64                      `json:"top_p,omitempty"`
	TopK                *float64                      `json:"top_k,omitempty"`
	N                   *int                          `json:"n,omitempty"`
	Stream              bool                          `json:"stream,omitempty"`
	StreamOptions       *StreamOptions                `json:"stream_options,omitempty"`
	Stop                any                           `json:"stop,omitempty"`
	PresencePenalty     *float64                      `json:"presence_penalty,omitempty"`
	ResponseFormat      *ChatCompletionResponseFormat `json:"response_format,omitempty"`
	Seed                *int                          `json:"seed,omitempty"`
	FrequencyPenalty    *float64                      `json:"frequency_penalty,omitempty"`
	LogitBias           any                           `json:"logit_bias,omitempty"`
	LogProbs            *bool                         `json:"logprobs,omitempty"`
	TopLogProbs         int                           `json:"top_logprobs,omitempty"`
	User                string                        `json:"user,omitempty"`
	Functions           []*ChatCompletionFunction     `json:"functions,omitempty"`
	FunctionCall        any                           `json:"function_call,omitempty"`
	Tools               []*ChatCompletionTool         `json:"tools,omitempty"`
	ToolChoice          any                           `json:"tool_choice,omitempty"`
	ParallelToolCalls   bool                          `json:"parallel_tool_calls,omitempty"`
	Modalities          []string                      `json:"modalities,omitempty"`
	Audio               *ChatAudio                    `json:"audio,omitempty"`
	ReasoningEffort     *string                       `json:"reasoning_effort,omitempty"`
	Prediction          any                           `json:"prediction,omitempty"`
	WebSearchOptions    *WebSearchOptions             `json:"web_search_options,omitempty"`
	Verbosity           string                        `json:"verbosity,omitempty"` // 用于控制输出的详细程度

	Reasoning *ChatReasoning `json:"reasoning,omitempty"`

	// 考虑到后续一些模型逐步采用openai api格式扩展参数的方式进行服务提供,所以考虑把一些模型的特有参数放入可选参数
	EnableThinking *bool `json:"enable_thinking,omitempty"` // qwen3 思考开关
	ThinkingBudget *int  `json:"thinking_budget,omitempty"` // qwen3 思考长度,只有enable_thinking开启才生效
	EnableSearch   *bool `json:"enable_search,omitempty"`   // qwen 搜索开关

	Thinking *interface{} `json:"thinking,omitempty"` // thinking 思考开关,兼容火山引擎

	OneOtherArg string `json:"-"`
}

func (ChatCompletionRequest) GetFunctionCate

func (r ChatCompletionRequest) GetFunctionCate() string

func (*ChatCompletionRequest) GetFunctions

func (r *ChatCompletionRequest) GetFunctions() []*ChatCompletionFunction

func (ChatCompletionRequest) ParseToolChoice

func (r ChatCompletionRequest) ParseToolChoice() (toolType, toolFunc string)

func (*ChatCompletionRequest) ToResponsesRequest

func (c *ChatCompletionRequest) ToResponsesRequest() *OpenAIResponsesRequest

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID                  string                 `json:"id"`
	Object              string                 `json:"object"`
	Created             any                    `json:"created"`
	Model               string                 `json:"model"`
	Choices             []ChatCompletionChoice `json:"choices"`
	Usage               *Usage                 `json:"usage,omitempty"`
	SystemFingerprint   string                 `json:"system_fingerprint,omitempty"`
	PromptFilterResults any                    `json:"prompt_filter_results,omitempty"`
}

func (*ChatCompletionResponse) GetContent

func (cc *ChatCompletionResponse) GetContent() string

func (*ChatCompletionResponse) ToResponses

type ChatCompletionResponseFormat

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

type ChatCompletionStreamChoice

type ChatCompletionStreamChoice struct {
	Index                int                             `json:"index"`
	Delta                ChatCompletionStreamChoiceDelta `json:"delta"`
	FinishReason         any                             `json:"finish_reason"`
	ContentFilterResults any                             `json:"content_filter_results,omitempty"`
	Usage                *Usage                          `json:"usage,omitempty"`
}

func (*ChatCompletionStreamChoice) CheckChoice

func (c *ChatCompletionStreamChoice) CheckChoice(request *ChatCompletionRequest)

func (ChatCompletionStreamChoice) ConvertOpenaiStream

func (c ChatCompletionStreamChoice) ConvertOpenaiStream() []ChatCompletionStreamChoice

type ChatCompletionStreamChoiceDelta

type ChatCompletionStreamChoiceDelta struct {
	Content          string                           `json:"content,omitempty"`
	Role             string                           `json:"role,omitempty"`
	FunctionCall     *ChatCompletionToolCallsFunction `json:"function_call,omitempty"`
	ToolCalls        []*ChatCompletionToolCalls       `json:"tool_calls,omitempty"`
	ReasoningContent string                           `json:"reasoning_content,omitempty"`
	Reasoning        string                           `json:"reasoning,omitempty"`
	Image            []MultimediaData                 `json:"image,omitempty"`
	Images           []ChatMessagePart                `json:"images,omitempty"`
}

func (*ChatCompletionStreamChoiceDelta) ToolToFuncCalls

func (m *ChatCompletionStreamChoiceDelta) ToolToFuncCalls()

type ChatCompletionStreamResponse

type ChatCompletionStreamResponse struct {
	ID                string                       `json:"id"`
	Object            string                       `json:"object"`
	Created           any                          `json:"created"`
	Model             string                       `json:"model"`
	Choices           []ChatCompletionStreamChoice `json:"choices"`
	PromptAnnotations any                          `json:"prompt_annotations,omitempty"`
	Usage             *Usage                       `json:"usage,omitempty"`
}

func (*ChatCompletionStreamResponse) GetResponseText

func (c *ChatCompletionStreamResponse) GetResponseText() (responseText string)

type ChatCompletionTool

type ChatCompletionTool struct {
	Type     string                 `json:"type"`
	Function ChatCompletionFunction `json:"function,omitzero"`

	ResponsesTools
}

type ChatCompletionToolCalls

type ChatCompletionToolCalls struct {
	Id       string                           `json:"id,omitempty"`
	Type     string                           `json:"type,omitempty"`
	Function *ChatCompletionToolCallsFunction `json:"function"`
	Index    int                              `json:"index"`
}

type ChatCompletionToolCallsFunction

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

func (*ChatCompletionToolCallsFunction) Split

type ChatMessageFile

type ChatMessageFile struct {
	Filename string `json:"filename,omitempty"`
	FileData string `json:"file_data,omitempty"`
}

type ChatMessageImageURL

type ChatMessageImageURL struct {
	URL    string `json:"url,omitempty"`
	Detail string `json:"detail,omitempty"`
}

type ChatMessagePart

type ChatMessagePart struct {
	Type       string               `json:"type,omitempty"`
	Text       string               `json:"text,omitempty"`
	ImageURL   *ChatMessageImageURL `json:"image_url,omitempty"`
	InputAudio *InputAudio          `json:"input_audio,omitempty"`
	Refusal    string               `json:"refusal,omitempty"`

	File *ChatMessageFile `json:"file,omitempty"`
}

type ChatReasoning

type ChatReasoning struct {
	MaxTokens int     `json:"max_tokens,omitempty"`
	Effort    string  `json:"effort,omitempty"`
	Summary   *string `json:"summary,omitempty"`
}

type CompletionChoice

type CompletionChoice struct {
	Text         string `json:"text"`
	Index        int    `json:"index"`
	FinishReason string `json:"finish_reason"`
	LogProbs     any    `json:"logprobs,omitempty"`
}

type CompletionRequest

type CompletionRequest struct {
	Model            string         `json:"model" binding:"required"`
	Prompt           any            `json:"prompt" binding:"required"`
	Suffix           string         `json:"suffix,omitempty"`
	MaxTokens        int            `json:"max_tokens,omitempty"`
	Temperature      float32        `json:"temperature,omitempty"`
	TopP             float32        `json:"top_p,omitempty"`
	N                int            `json:"n,omitempty"`
	Stream           bool           `json:"stream,omitempty"`
	StreamOptions    *StreamOptions `json:"stream_options,omitempty"`
	LogProbs         int            `json:"logprobs,omitempty"`
	Echo             bool           `json:"echo,omitempty"`
	Stop             []string       `json:"stop,omitempty"`
	PresencePenalty  float32        `json:"presence_penalty,omitempty"`
	FrequencyPenalty float32        `json:"frequency_penalty,omitempty"`
	BestOf           int            `json:"best_of,omitempty"`
	LogitBias        any            `json:"logit_bias,omitempty"`
	User             string         `json:"user,omitempty"`
}

type CompletionResponse

type CompletionResponse struct {
	ID      string             `json:"id"`
	Object  string             `json:"object"`
	Created any                `json:"created"`
	Model   string             `json:"model"`
	Choices []CompletionChoice `json:"choices"`
	Usage   *Usage             `json:"usage,omitempty"`
}

type CompletionTokensDetails

type CompletionTokensDetails struct {
	AudioTokens              int `json:"audio_tokens,omitempty"`
	TextTokens               int `json:"text_tokens,omitempty"`
	ReasoningTokens          int `json:"reasoning_tokens"`
	AcceptedPredictionTokens int `json:"accepted_prediction_tokens"`
	RejectedPredictionTokens int `json:"rejected_prediction_tokens"`
	ImageTokens              int `json:"image_tokens,omitempty"`
}

func (*CompletionTokensDetails) Merge

type ContentResponses

type ContentResponses struct {
	Type string `json:"type"` // input_text / input_image / input_file / output_text / refusal
	//input_text
	Text string `json:"text,omitempty"`

	//input_image
	Detail   string `json:"detail,omitempty"`    // The detail level of the image to be sent to the model. One of high, low, or auto. Defaults to auto.
	FileId   string `json:"file_id,omitempty"`   // The ID of the file to be sent to the model.
	ImageUrl string `json:"image_url,omitempty"` // The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image in a data URL.

	// input_file
	FileData string `json:"file_data,omitempty"` // The content of the file to be sent to the model.
	FileUrl  string `json:"file_url,omitempty"`  // The URL of the file to be sent to the model.
	FileName string `json:"file_name,omitempty"` // The name of the file to be sent to the model.

	// output_text
	Annotations []Annotations `json:"annotations,omitempty"` // The annotations of the text output.
	Logprobs    any           `json:"logprobs,omitempty"`

	// refusal
	Refusal *RefusalResponses `json:"refusal,omitempty"`
}

func (*ContentResponses) ToChatContent

func (c *ContentResponses) ToChatContent() (*ChatMessagePart, error)

type Embedding

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

type EmbeddingRequest

type EmbeddingRequest struct {
	Model          string `json:"model" binding:"required"`
	Input          any    `json:"input" binding:"required"`
	EncodingFormat string `json:"encoding_format,omitempty"`
	Dimensions     int    `json:"dimensions,omitempty"`
	User           string `json:"user,omitempty"`
}

func (EmbeddingRequest) ParseInput

func (r EmbeddingRequest) ParseInput() []string

func (EmbeddingRequest) ParseInputString

func (r EmbeddingRequest) ParseInputString() string

type EmbeddingResponse

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

type Event

type Event struct {
	EventId     string         `json:"event_id"`
	Type        string         `json:"type"`
	Response    *ResponseEvent `json:"response,omitempty"`
	ErrorDetail *EventError    `json:"error,omitempty"`
}

func NewErrorEvent

func NewErrorEvent(eventId, errType, code, message string) *Event

func (*Event) Error

func (e *Event) Error() string

func (*Event) IsError

func (e *Event) IsError() bool

type EventError

type EventError struct {
	OpenAIError
	EventId string `json:"event_id"`
}

type ExtraBilling

type ExtraBilling struct {
	Type      string `json:"type"`
	CallCount int    `json:"call_count"`
}

type FormatJsonSchema

type FormatJsonSchema struct {
	Description string `json:"description,omitempty"`
	Name        string `json:"name"`
	Schema      any    `json:"schema,omitempty"`
	Strict      any    `json:"strict,omitempty"`
}

type ImageEditRequest

type ImageEditRequest struct {
	Image          *multipart.FileHeader   `form:"image"`
	Images         []*multipart.FileHeader `form:"image[]"`
	Mask           *multipart.FileHeader   `form:"mask"`
	Model          string                  `form:"model"`
	Prompt         string                  `form:"prompt"`
	N              int                     `form:"n"`
	Size           string                  `form:"size"`
	ResponseFormat string                  `form:"response_format"`
	User           string                  `form:"user"`
}

type ImageRequest

type ImageRequest struct {
	Prompt           string  `json:"prompt,omitempty" binding:"required"`
	Model            string  `json:"model,omitempty"`
	N                int     `json:"n,omitempty"`
	Quality          string  `json:"quality,omitempty"`
	Size             string  `json:"size,omitempty"`
	Style            string  `json:"style,omitempty"`
	ResponseFormat   string  `json:"response_format,omitempty"`
	User             string  `json:"user,omitempty"`
	AspectRatio      *string `json:"aspect_ratio,omitempty"`
	OutputQuality    *int    `json:"output_quality,omitempty"`
	SafetyTolerance  *string `json:"safety_tolerance,omitempty"`
	PromptUpsampling *string `json:"prompt_upsampling,omitempty"`

	Background        *string `json:"background,omitempty"`
	Moderation        *string `json:"moderation,omitempty"`
	OutputCompression *int    `json:"output_compression,omitempty"`
	OutputFormat      *string `json:"output_format,omitempty"`
}

type ImageResponse

type ImageResponse struct {
	Created any                      `json:"created,omitempty"`
	Data    []ImageResponseDataInner `json:"data,omitempty"`
	Usage   *ResponsesUsage          `json:"usage,omitempty"`
}

type ImageResponseDataInner

type ImageResponseDataInner struct {
	URL           string `json:"url,omitempty"`
	B64JSON       string `json:"b64_json,omitempty"`
	RevisedPrompt string `json:"revised_prompt,omitempty"`
}

type IncompleteDetail

type IncompleteDetail struct {
	Reason string `json:"reason,omitempty"`
}

type InputAudio

type InputAudio struct {
	Data   string `json:"data"`
	Format string `json:"format"`
}

type InputResponses

type InputResponses struct {
	Role    string `json:"role,omitempty"`
	Content any    `json:"content,omitempty"` // string or ContentResponses
	Type    string `json:"type,omitempty"`    // message / file_search_call / computer_call / web_search_call / computer_call_output / function_call / function_call_output / reasoning / image_generation_call / code_interpreter_call / local_shell_call / local_shell_call_output / mcp_list_tools / mcp_approval_request / mcp_approval_response / mcp_call
	Status  string `json:"status,omitempty"`  // The status of item. One of in_progress, completed, or incomplete. Populated when items are returned via API.

	// file_search_call
	ID      string `json:"id,omitempty"`
	Queries any    `json:"queries,omitempty"`
	Results any    `json:"results,omitempty"` // The results of the file search call.

	// computer_call
	Action              any    `json:"action,omitempty"`
	CallID              string `json:"call_id,omitempty"`
	PendingSafetyChecks any    `json:"pending_safety_checks,omitempty"`

	// computer_call_output
	Output                   any `json:"output,omitempty"`
	AcknowledgedSafetyChecks any `json:"acknowledged_safety_checks,omitempty"`

	// function_call
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`

	// reasoning
	Summary          *SummaryResponses `json:"summary,omitempty"`
	EncryptedContent *string           `json:"encrypted_content,omitempty"`

	// image_generation_call
	Result any `json:"result,omitempty"`

	// code_interpreter_call
	Code        string `json:"code,omitempty"`
	ContainerID string `json:"container_id,omitempty"`

	// mcp_list_tools
	ServerLabel string `json:"server_label,omitempty"`
	Tools       any    `json:"tools,omitempty"`
	Error       string `json:"error,omitempty"`

	// mcp_approval_request
	ApprovalRequestID string `json:"approval_request_id,omitempty"`
	Approve           bool   `json:"approve,omitempty"`
	Reason            string `json:"reason,omitempty"`

	Input any `json:"input,omitempty"` // The input to the tool call. This can be a string or a list of ContentResponses.
}

func (*InputResponses) ParseContent

func (i *InputResponses) ParseContent() ([]ContentResponses, error)

type ModerationRequest

type ModerationRequest struct {
	Input any    `json:"input,omitempty" binding:"required"`
	Model string `json:"model,omitempty"`
}

type ModerationResponse

type ModerationResponse struct {
	ID      string `json:"id"`
	Model   string `json:"model"`
	Results any    `json:"results"`
}

type MultimediaData

type MultimediaData struct {
	Data       string `json:"data"`
	ExpiresAt  int64  `json:"expires_at,omitempty"`
	ID         string `json:"id,omitempty"`
	Transcript string `json:"transcript,omitempty"`
}

type OpenAIError

type OpenAIError struct {
	Code       any    `json:"code,omitempty"`
	Message    string `json:"message"`
	Param      string `json:"param,omitempty"`
	Type       string `json:"type,omitempty"`
	InnerError any    `json:"innererror,omitempty"`
}

func (*OpenAIError) Error

func (e *OpenAIError) Error() string

type OpenAIErrorResponse

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

type OpenAIErrorWithStatusCode

type OpenAIErrorWithStatusCode struct {
	OpenAIError
	StatusCode int  `json:"status_code"`
	LocalError bool `json:"-"`
}

type OpenAIResponsesRequest

type OpenAIResponsesRequest struct {
	Input              any              `json:"input,omitempty"`
	Model              string           `json:"model" binding:"required"`
	Include            any              `json:"include,omitempty"`
	Instructions       string           `json:"instructions,omitempty"`
	MaxOutputTokens    int              `json:"max_output_tokens,omitempty"`
	MaxToolCalls       *int             `json:"max_tool_calls,omitempty"`
	ParallelToolCalls  bool             `json:"parallel_tool_calls,omitempty"`
	PreviousResponseID string           `json:"previous_response_id,omitempty"`
	Reasoning          *ReasoningEffort `json:"reasoning,omitempty"`
	Store              *bool            `json:"store,omitempty"` // 是否存储响应结果
	Stream             bool             `json:"stream,omitempty"`
	Temperature        *float64         `json:"temperature,omitempty"`
	Text               *ResponsesText   `json:"text,omitempty"`
	ToolChoice         any              `json:"tool_choice,omitempty"`
	Tools              []ResponsesTools `json:"tools,omitempty"`
	TopLogProbs        any              `json:"top_logprobs,omitempty"` // The number of top log probabilities to return for each token in the response.
	TopP               *float64         `json:"top_p,omitempty"`
	Truncation         string           `json:"truncation,omitempty"`

	ConvertChat bool `json:"-"`
}

func (*OpenAIResponsesRequest) InputToMessages

func (r *OpenAIResponsesRequest) InputToMessages() ([]ChatCompletionMessage, error)

func (*OpenAIResponsesRequest) ParseInput

func (r *OpenAIResponsesRequest) ParseInput() ([]InputResponses, error)

func (*OpenAIResponsesRequest) ToChatCompletionRequest

func (r *OpenAIResponsesRequest) ToChatCompletionRequest() (*ChatCompletionRequest, error)

type OpenAIResponsesResponses

type OpenAIResponsesResponses struct {
	CreatedAt          any               `json:"created_at,omitempty"`
	Error              *OpenAIError      `json:"error,omitempty"`
	ID                 string            `json:"id,omitempty"`
	IncompleteDetail   *IncompleteDetail `json:"incomplete_details,omitempty"`
	Instructions       any               `json:"instructions,omitempty"`
	MaxOutputTokens    int               `json:"max_output_tokens,omitempty"`
	Model              string            `json:"model"`
	Object             string            `json:"object"`
	Output             []ResponsesOutput `json:"output,omitempty"`
	ParallelToolCalls  bool              `json:"parallel_tool_calls,omitempty"`
	PreviousResponseID string            `json:"previous_response_id,omitempty"`
	Reasoning          *ReasoningEffort  `json:"reasoning,omitempty"`
	Status             string            `json:"status"`
	Temperature        *float64          `json:"temperature,omitempty"`
	Text               any               `json:"text,omitempty"`
	ToolChoice         any               `json:"tool_choice,omitempty"`
	Tools              []ResponsesTools  `json:"tools,omitempty"`
	TopP               *float64          `json:"top_p,omitempty"`
	Truncation         string            `json:"truncation,omitempty"`

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

func (*OpenAIResponsesResponses) GetContent

func (cc *OpenAIResponsesResponses) GetContent() string

func (*OpenAIResponsesResponses) ToChat

type OpenAIResponsesStreamResponses

type OpenAIResponsesStreamResponses struct {
	Type           string `json:"type"`            // 始终存在
	SequenceNumber int    `json:"sequence_number"` // 始终存在
	// response.created  第一条数据
	// response.in_progress 第二条数据
	// response.completed  最后一条数据
	// response.failed 内容过滤返回
	// response.incomplete 内容不完整返回
	Response *OpenAIResponsesResponses `json:"response,omitempty"`

	// response.output_item.added response.output_item.done 在新项目的前后, 函数调用时,会在added先输出需要调用的函数名, done 会输出完整的项目数据
	OutputIndex *int             `json:"output_index,omitempty"` // 当前项目的索引,从0开始
	Item        *ResponsesOutput `json:"item,omitempty"`

	ItemID string `json:"item_id,omitempty"` // 项目的ID,和response.output_item 中的Item.ID一致

	// response.content_part.added response.content_part.done 在output_text的前后,done 会输出完整的output_text
	ContentIndex *int              `json:"content_index,omitempty"`
	Part         *ContentResponses `json:"part,omitempty"`

	// response.output_text.delta  response.output_text.done 文本输出
	Delta any     `json:"delta,omitempty"` // 仅在response.output_text.delta / response.refusal.delta / response.function_call_arguments.delta存在
	Text  *string `json:"text,omitempty"`  // 仅在response.output_text.done存在

	// response.refusal.delta response.refusal.done 拒绝输出
	Refusal *string `json:"refusal,omitempty"` // 仅在response.refusal.done存在

	// response.function_call_arguments.delta response.function_call_arguments.done
	Arguments any `json:"arguments,omitempty"` // 仅在response.function_call_arguments.done存在

	// response.reasoning_summary_part.added response.reasoning_summary_part.done 在reasoning_summary_text的前后,done 会输出完整的reasoning_summary_text
	SummaryIndex *int `json:"summary_index,omitempty"` // 当前摘要的索引,从0开始

	//  response.image_generation_call.completed response.image_generation_call.generating response.image_generation_call.in_progress response.image_generation_call.partial_image
	PartialImageIndex *int    `json:"partial_image_index,omitempty"` // 当前图片的索引,从0开始
	PartialImageB64   *string `json:"partial_image_b64,omitempty"`   // 仅在response.image_generation_call.partial_image存在

	// error
	Code    *string `json:"code,omitempty"`    // 错误代码
	Message *string `json:"message,omitempty"` // 错误信息
	Param   *any    `json:"param,omitempty"`   // 错误参数
}

type PromptTokensDetails

type PromptTokensDetails struct {
	AudioTokens          int `json:"audio_tokens,omitempty"`
	CachedTokens         int `json:"cached_tokens,omitempty"`
	TextTokens           int `json:"text_tokens,omitempty"`
	ImageTokens          int `json:"image_tokens,omitempty"`
	CachedTokensInternal int `json:"cached_tokens_internal,omitempty"`

	CachedWriteTokens int `json:"-"`
	CachedReadTokens  int `json:"-"`
}

func (*PromptTokensDetails) Merge

func (i *PromptTokensDetails) Merge(other *PromptTokensDetails)

type ReasoningEffort

type ReasoningEffort struct {
	Effort          *string `json:"effort,omitempty"`
	GenerateSummary *string `json:"generate_summary,omitempty"` // Deprecated
	Summary         *string `json:"summary,omitempty"`
}

type RefusalResponses

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

type RerankError

type RerankError struct {
	Detail string `json:"detail"`
}

func (*RerankError) Error

func (e *RerankError) Error() string

type RerankErrorWithStatusCode

type RerankErrorWithStatusCode struct {
	RerankError
	StatusCode int  `json:"status_code"`
	LocalError bool `json:"-"`
}

type RerankRequest

type RerankRequest struct {
	Model     string `json:"model" binding:"required"`
	Query     string `json:"query" binding:"required"`
	TopN      int    `json:"top_n"`
	Documents []any  `json:"documents" binding:"required"`
}

func (*RerankRequest) GetDocumentsList

func (r *RerankRequest) GetDocumentsList() ([]string, error)

type RerankResponse

type RerankResponse struct {
	Model   string         `json:"model"`
	Usage   *Usage         `json:"usage"`
	Results []RerankResult `json:"results"`
}

type RerankResult

type RerankResult struct {
	Index          int                  `json:"index"`
	Document       RerankResultDocument `json:"document,omitempty"`
	RelevanceScore float64              `json:"relevance_score"`
}

type RerankResultDocument

type RerankResultDocument struct {
	Text string `json:"text"`
}

type ResponseEvent

type ResponseEvent struct {
	ID     string      `json:"id"`
	Object string      `json:"object"`
	Status string      `json:"status"`
	Usage  *UsageEvent `json:"usage,omitempty"`
}

type ResponsesOutput

type ResponsesOutput struct {
	Type    string `json:"type"`
	ID      string `json:"id"`
	Status  string `json:"status"`
	Role    string `json:"role,omitempty"`
	Content any    `json:"content,omitempty"`

	Queries             any                `json:"queries,omitempty"`
	Results             any                `json:"results,omitempty"`
	Arguments           *string            `json:"arguments,omitempty"`
	CallID              string             `json:"call_id,omitempty"`
	Name                string             `json:"name,omitempty"`
	Action              any                `json:"action,omitempty"`
	PendingSafetyChecks any                `json:"pending_safety_checks,omitempty"`
	Summary             []SummaryResponses `json:"summary,omitempty"`
	EncryptedContent    *string            `json:"encrypted_content,omitempty"`

	Code        any    `json:"code,omitempty"`
	ContainerID string `json:"container_id,omitempty"`
	Outputs     any    `json:"outputs,omitempty"`
	ServerLabel any    `json:"server_label,omitempty"`
	Error       any    `json:"error,omitempty"`
	Output      any    `json:"output,omitempty"` // The output of the tool call.
	Tools       any    `json:"tools,omitempty"`  // The tools available for the tool call.

	Background    any    `json:"background,omitempty"`
	OutputFormat  any    `json:"output_format,omitempty"`
	Quality       string `json:"quality,omitempty"`
	Result        any    `json:"result,omitempty"`         // The result of the image generation call.
	Size          string `json:"size,omitempty"`           // The size of the image to be generated.
	RevisedPrompt any    `json:"revised_prompt,omitempty"` // The revised prompt for the image generation call.
}

func (ResponsesOutput) GetSummaryString

func (m ResponsesOutput) GetSummaryString() string

func (ResponsesOutput) StringContent

func (m ResponsesOutput) StringContent() string

type ResponsesOutputToolCall

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

type ResponsesText

type ResponsesText struct {
	Format    *ResponsesTextFormat `json:"format,omitempty"`
	Verbosity string               `json:"verbosity,omitempty"`
}

type ResponsesTextFormat

type ResponsesTextFormat struct {
	Type        string `json:"type,omitempty"`
	Name        string `json:"name,omitempty"` // The name of the text format. This is used to identify the text format in the response.
	Schema      any    `json:"schema,omitempty"`
	Description string `json:"description,omitempty"`
	Strict      any    `json:"strict,omitempty"`
}

type ResponsesTools

type ResponsesTools struct {
	Type string `json:"type"`
	// Web Search
	UserLocation      any    `json:"user_location,omitempty"`
	SearchContextSize string `json:"search_context_size,omitempty"`
	// File Search
	VectorStoreIds []string `json:"vector_store_ids,omitempty"`
	MaxNumResults  uint     `json:"max_num_results,omitempty"`
	Filters        any      `json:"filters,omitempty"`
	RankingOptions any      `json:"ranking_options,omitempty"`
	// Computer Use
	DisplayWidth  uint   `json:"display_width,omitempty"`
	DisplayHeight uint   `json:"display_height,omitempty"`
	Environment   string `json:"environment,omitempty"`
	// Function
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters,omitempty"`
	Strict      *bool  `json:"strict,omitempty"`

	//MCP
	ServerLabel     string `json:"server_label,omitempty"`
	ServerURL       string `json:"server_url,omitempty"`
	AllowedTools    any    `json:"allowed_tools,omitempty"`
	Headers         any    `json:"headers,omitempty"`
	RequireApproval any    `json:"require_approval,omitempty"`

	// Code interpreter
	Container any `json:"container,omitempty"`
	// Image generation tool
	Background        any    `json:"background,omitempty"`
	InputImageMask    any    `json:"input_image_mask,omitempty"`
	Model             string `json:"model,omitempty"`
	Moderation        any    `json:"moderation,omitempty"`
	OutputCompression any    `json:"output_compression,omitempty"`
	OutputFormat      any    `json:"output_format,omitempty"`
	PartialImages     any    `json:"partial_images,omitempty"`
	Quality           string `json:"quality,omitempty"`
	Size              string `json:"size,omitempty"`
}

type ResponsesUsage

type ResponsesUsage struct {
	InputTokens         int                                `json:"input_tokens"`
	OutputTokens        int                                `json:"output_tokens"`
	TotalTokens         int                                `json:"total_tokens"`
	OutputTokensDetails *ResponsesUsageOutputTokensDetails `json:"output_tokens_details"`
	InputTokensDetails  *ResponsesUsageInputTokensDetails  `json:"input_tokens_details"`
}

func (*ResponsesUsage) ToOpenAIUsage

func (u *ResponsesUsage) ToOpenAIUsage() *Usage

type ResponsesUsageInputTokensDetails

type ResponsesUsageInputTokensDetails struct {
	CachedTokens int `json:"cached_tokens"`
	TextTokens   int `json:"text_tokens,omitempty"`
	ImageTokens  int `json:"image_tokens,omitempty"`
}

type ResponsesUsageOutputTokensDetails

type ResponsesUsageOutputTokensDetails struct {
	ReasoningTokens int `json:"reasoning_tokens"`
}

type SpeechAudioRequest

type SpeechAudioRequest struct {
	Model          string  `json:"model" binding:"required"`
	Input          string  `json:"input" binding:"required"`
	Voice          string  `json:"voice" binding:"required"`
	ResponseFormat string  `json:"response_format,omitempty"`
	Speed          float64 `json:"speed,omitempty"`
}

type StreamOptions

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

type SummaryResponses

type SummaryResponses struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type TaskDto

type TaskDto struct {
	TaskID     string         `json:"task_id"` // 第三方id,不一定有/ song id\ Task id
	Action     string         `json:"action"`  // 任务类型, song, lyrics, description-mode
	Status     string         `json:"status"`  // 任务状态, submitted, queueing, processing, success, failed
	FailReason string         `json:"fail_reason"`
	SubmitTime int64          `json:"submit_time"`
	StartTime  int64          `json:"start_time"`
	FinishTime int64          `json:"finish_time"`
	Progress   string         `json:"progress"`
	Data       datatypes.JSON `json:"data"`
}

type TaskResponse

type TaskResponse[T any] struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Data    *T     `json:"data,omitempty"`
}

func (*TaskResponse[T]) IsSuccess

func (t *TaskResponse[T]) IsSuccess() bool

type TextResponses

type TextResponses struct {
	Format struct {
		Type string `json:"type"`
	} `json:"format"`
}

type Usage

type Usage struct {
	PromptTokens            int                     `json:"prompt_tokens"`
	CompletionTokens        int                     `json:"completion_tokens"`
	TotalTokens             int                     `json:"total_tokens"`
	PromptTokensDetails     PromptTokensDetails     `json:"prompt_tokens_details"`
	CompletionTokensDetails CompletionTokensDetails `json:"completion_tokens_details"`

	ExtraTokens  map[string]int          `json:"-"`
	ExtraBilling map[string]ExtraBilling `json:"-"`
	TextBuilder  strings.Builder         `json:"-"`
}

func (*Usage) GetExtraTokens

func (u *Usage) GetExtraTokens() map[string]int

func (*Usage) IncExtraBilling

func (u *Usage) IncExtraBilling(key string, bType string)

func (*Usage) SetExtraTokens

func (u *Usage) SetExtraTokens(key string, value int)

func (*Usage) ToResponsesUsage

func (u *Usage) ToResponsesUsage() *ResponsesUsage

type UsageEvent

type UsageEvent struct {
	InputTokens        int                     `json:"input_tokens"`
	OutputTokens       int                     `json:"output_tokens"`
	TotalTokens        int                     `json:"total_tokens"`
	InputTokenDetails  PromptTokensDetails     `json:"input_token_details,omitempty"`
	OutputTokenDetails CompletionTokensDetails `json:"output_token_details,omitempty"`

	ExtraTokens map[string]int `json:"-"`
}

func (*UsageEvent) GetExtraTokens

func (u *UsageEvent) GetExtraTokens() map[string]int

func (*UsageEvent) Merge

func (u *UsageEvent) Merge(other *UsageEvent)

func (*UsageEvent) SetExtraTokens

func (u *UsageEvent) SetExtraTokens(key string, value int)

func (*UsageEvent) ToChatUsage

func (u *UsageEvent) ToChatUsage() *Usage

type VideoListResponse

type VideoListResponse struct {
	Object string            `json:"object"`
	Data   []VideoTaskObject `json:"data"`
}

type VideoRequest

type VideoRequest struct {
	Model        string         `json:"model,omitempty"`
	Mode         string         `json:"mode,omitempty"`
	Prompt       string         `json:"prompt,omitempty"`
	ImageURL     string         `json:"image_url,omitempty"`
	ImageB64JSON string         `json:"image_b64_json,omitempty"`
	Size         string         `json:"size,omitempty"`
	Duration     *int           `json:"duration,omitempty"`
	FPS          *int           `json:"fps,omitempty"`
	Seed         *int           `json:"seed,omitempty"`
	N            *int           `json:"n,omitempty"`
	ExtraFields  map[string]any `json:"-"`
}

func (VideoRequest) MarshalJSON

func (r VideoRequest) MarshalJSON() ([]byte, error)

func (*VideoRequest) UnmarshalJSON

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

type VideoTaskError

type VideoTaskError struct {
	Message string `json:"message,omitempty"`
	Type    string `json:"type,omitempty"`
	Code    any    `json:"code,omitempty"`
}

type VideoTaskObject

type VideoTaskObject struct {
	ID          string          `json:"id,omitempty"`
	Object      string          `json:"object,omitempty"`
	Created     int64           `json:"created,omitempty"`
	Model       string          `json:"model,omitempty"`
	Mode        string          `json:"mode,omitempty"`
	Status      string          `json:"status,omitempty"`
	Prompt      string          `json:"prompt,omitempty"`
	Size        string          `json:"size,omitempty"`
	Duration    *int            `json:"duration,omitempty"`
	FPS         *int            `json:"fps,omitempty"`
	Seed        *int            `json:"seed,omitempty"`
	ContentURL  string          `json:"content_url,omitempty"`
	DownloadURL string          `json:"download_url,omitempty"`
	Error       *VideoTaskError `json:"error,omitempty"`
}

type VideoTaskProperties

type VideoTaskProperties struct {
	Model       string `json:"model,omitempty"`
	Mode        string `json:"mode,omitempty"`
	Prompt      string `json:"prompt,omitempty"`
	Size        string `json:"size,omitempty"`
	ImageSource string `json:"image_source,omitempty"`
	HasImageB64 bool   `json:"has_image_b64,omitempty"`
	Duration    *int   `json:"duration,omitempty"`
	FPS         *int   `json:"fps,omitempty"`
	Seed        *int   `json:"seed,omitempty"`
}

type WebSearchOptions

type WebSearchOptions struct {
	SearchContextSize string `json:"search_context_size,omitempty"`
	UserLocation      any    `json:"user_location,omitempty"`
}

Jump to

Keyboard shortcuts

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