Documentation
¶
Index ¶
- Constants
- type Audio
- type CompletionTokensDetails
- type ContentBlock
- type Error
- type ErrorWithStatusCode
- type Function
- type GeneralOpenAIRequest
- type ImageRequest
- type ImageURL
- type InputTokensDetails
- type JSONSchema
- type Message
- type MessageContent
- type OutputTokensDetails
- type PromptTokensDetails
- type ResponseError
- type ResponseFormat
- type ResponseStreamErrorEvent
- type ResponsesDelta
- type ResponsesItem
- type ResponsesRequest
- type ResponsesResponse
- type ResponsesStreamCapture
- type ResponsesStreamEvent
- type ResponsesStreamFrame
- type ResponsesUsage
- type StreamOptions
- type Tool
- type ToolUse
- type Usage
Constants ¶
const ( ContentTypeText = "text" ContentTypeImageURL = "image_url" ContentTypeInputAudio = "input_audio" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompletionTokensDetails ¶
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // input_text, output_text
Text string `json:"text"`
}
ContentBlock is a content block for nested content arrays
type ErrorWithStatusCode ¶
type GeneralOpenAIRequest ¶
type GeneralOpenAIRequest struct {
// https://platform.openai.com/docs/api-reference/chat/create
Messages []Message `json:"messages,omitempty"`
Model string `json:"model,omitempty"`
Store *bool `json:"store,omitempty"`
ReasoningEffort *string `json:"reasoning_effort,omitempty"`
Metadata any `json:"metadata,omitempty"`
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
LogitBias any `json:"logit_bias,omitempty"`
Logprobs *bool `json:"logprobs,omitempty"`
TopLogprobs *int `json:"top_logprobs,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
N int `json:"n,omitempty"`
Modalities []string `json:"modalities,omitempty"`
Prediction any `json:"prediction,omitempty"`
Audio *Audio `json:"audio,omitempty"`
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
Seed float64 `json:"seed,omitempty"`
ServiceTier *string `json:"service_tier,omitempty"`
Stop any `json:"stop,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
TopK int `json:"top_k,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
ParallelTooCalls *bool `json:"parallel_tool_calls,omitempty"`
User string `json:"user,omitempty"`
FunctionCall any `json:"function_call,omitempty"`
Functions any `json:"functions,omitempty"`
// https://platform.openai.com/docs/api-reference/embeddings/create
Input any `json:"input,omitempty"`
EncodingFormat string `json:"encoding_format,omitempty"`
Dimensions int `json:"dimensions,omitempty"`
// https://platform.openai.com/docs/api-reference/images/create
Prompt any `json:"prompt,omitempty"`
Quality *string `json:"quality,omitempty"`
Size string `json:"size,omitempty"`
Style *string `json:"style,omitempty"`
// Others
Instruction string `json:"instruction,omitempty"`
NumCtx int `json:"num_ctx,omitempty"`
}
func (GeneralOpenAIRequest) ParseInput ¶
func (r GeneralOpenAIRequest) ParseInput() []string
type ImageRequest ¶
type ImageRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt" binding:"required"`
N int `json:"n,omitempty"`
Size string `json:"size,omitempty"`
Quality string `json:"quality,omitempty"`
ResponseFormat string `json:"response_format,omitempty"`
Style string `json:"style,omitempty"`
User string `json:"user,omitempty"`
}
type InputTokensDetails ¶
type InputTokensDetails struct {
CachedTokens int `json:"cached_tokens"`
}
InputTokensDetails contains detailed input token statistics
type JSONSchema ¶
type Message ¶
type Message struct {
Role string `json:"role,omitempty"`
Content any `json:"content,omitempty"`
ReasoningContent any `json:"reasoning_content,omitempty"`
Name *string `json:"name,omitempty"`
ToolCalls []Tool `json:"tool_calls,omitempty"`
ToolCallId string `json:"tool_call_id,omitempty"`
}
func (Message) IsStringContent ¶
func (Message) ParseContent ¶
func (m Message) ParseContent() []MessageContent
func (Message) StringContent ¶
type MessageContent ¶
type OutputTokensDetails ¶
type OutputTokensDetails struct {
ReasoningTokens int `json:"reasoning_tokens"`
}
OutputTokensDetails contains detailed output token statistics
type PromptTokensDetails ¶
type PromptTokensDetails struct {
CachedTokens int `json:"cached_tokens"` // 缓存命中的token数
}
type ResponseError ¶
type ResponseError struct {
Code string `json:"code"`
Message string `json:"message"`
Type string `json:"type,omitempty"`
}
ResponseError represents an error in a failed Responses API response
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type,omitempty"`
JsonSchema *JSONSchema `json:"json_schema,omitempty"`
}
type ResponseStreamErrorEvent ¶
type ResponseStreamErrorEvent struct {
Type string `json:"type"`
Code string `json:"code"`
Message string `json:"message"`
SequenceNumber int `json:"sequence_number,omitempty"`
}
ResponseStreamErrorEvent represents a streaming error event
type ResponsesDelta ¶
type ResponsesDelta struct {
Type string `json:"type,omitempty"`
Content interface{} `json:"content,omitempty"`
}
ResponsesDelta is the streaming delta data
type ResponsesItem ¶
type ResponsesItem struct {
ID string `json:"id,omitempty"`
Type string `json:"type"` // message, text, function_call, function_call_output
Role string `json:"role,omitempty"` // user, assistant (for type=message)
Status string `json:"status,omitempty"`
Content interface{} `json:"content,omitempty"` // string or []ContentBlock
Summary interface{} `json:"summary,omitempty"`
ToolUse *ToolUse `json:"tool_use,omitempty"`
CallID string `json:"call_id,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Arguments json.RawMessage `json:"arguments,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
}
ResponsesItem is a message item in Responses API
func (ResponsesItem) ArgumentsString ¶
func (r ResponsesItem) ArgumentsString() string
func (ResponsesItem) InputString ¶
func (r ResponsesItem) InputString() string
func (ResponsesItem) OutputString ¶
func (r ResponsesItem) OutputString() string
type ResponsesRequest ¶
type ResponsesRequest struct {
Model string `json:"model"`
Instructions string `json:"instructions,omitempty"` // system prompt
Input interface{} `json:"input"` // string or []ResponsesItem
PreviousResponseID string `json:"previous_response_id,omitempty"`
Store *bool `json:"store,omitempty"` // default true
MaxTokens int `json:"max_output_tokens,omitempty"` // max output tokens
Temperature float64 `json:"temperature,omitempty"` // temperature
TopP float64 `json:"top_p,omitempty"` // top_p
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` // frequency penalty
PresencePenalty float64 `json:"presence_penalty,omitempty"` // presence penalty
Stream bool `json:"stream,omitempty"` // stream output
Stop interface{} `json:"stop,omitempty"` // stop sequences
User string `json:"user,omitempty"` // user identifier
StreamOptions interface{} `json:"stream_options,omitempty"` // stream options
Tools []map[string]interface{} `json:"-"` // function tools
RawTools []interface{} `json:"tools,omitempty"` // raw tools definition
ToolChoice interface{} `json:"tool_choice,omitempty"` // string or object
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"` // parallel tool calls
// TransformerMetadata is used to preserve original format info during request transformation
// This field is not serialized to JSON, only valid within the same request processing chain
TransformerMetadata map[string]interface{} `json:"-"`
}
ResponsesRequest is the request structure for Responses API
type ResponsesResponse ¶
type ResponsesResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Output []ResponsesItem `json:"output"`
Status string `json:"status"` // completed, failed
PreviousID string `json:"previous_id,omitempty"`
Usage ResponsesUsage `json:"usage"`
Created int64 `json:"created,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
ResponsesResponse is the response structure for Responses API
type ResponsesStreamCapture ¶
type ResponsesStreamCapture struct {
Frames []ResponsesStreamFrame `json:"frames"`
Response *ResponsesResponse `json:"response,omitempty"`
Usage *ResponsesUsage `json:"-"`
}
ResponsesStreamCapture captures the full SSE sequence and the final completed response.
type ResponsesStreamEvent ¶
type ResponsesStreamEvent struct {
ID string `json:"id,omitempty"`
Item *ResponsesItem `json:"item,omitempty"`
Model string `json:"model,omitempty"`
Output []ResponsesItem `json:"output,omitempty"`
Status string `json:"status,omitempty"`
PreviousID string `json:"previous_id,omitempty"`
Usage *ResponsesUsage `json:"usage,omitempty"`
Type string `json:"type,omitempty"` // delta, done
Delta interface{} `json:"delta,omitempty"`
Response *ResponsesResponse `json:"response,omitempty"`
}
ResponsesStreamEvent is a streaming event for Responses API
type ResponsesStreamFrame ¶
type ResponsesStreamFrame struct {
Event string `json:"event,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Done bool `json:"done,omitempty"`
}
ResponsesStreamFrame preserves one SSE frame as emitted by the upstream stream.
type ResponsesUsage ¶
type ResponsesUsage struct {
InputTokens int `json:"input_tokens"`
InputTokensDetails *InputTokensDetails `json:"input_tokens_details,omitempty"`
OutputTokens int `json:"output_tokens"`
OutputTokensDetails *OutputTokensDetails `json:"output_tokens_details,omitempty"`
TotalTokens int `json:"total_tokens"`
// Claude extension fields for cache creation statistics
CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
CacheCreation5mInputTokens int `json:"cache_creation_5m_input_tokens,omitempty"` // 5min TTL
CacheCreation1hInputTokens int `json:"cache_creation_1h_input_tokens,omitempty"` // 1hour TTL
CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"`
CacheTTL string `json:"cache_ttl,omitempty"` // "5m" | "1h" | "mixed"
}
ResponsesUsage is the usage statistics for Responses API Supports detailed usage fields for both OpenAI Responses API and Claude API
type StreamOptions ¶
type StreamOptions struct {
IncludeUsage bool `json:"include_usage,omitempty"`
}
type ToolUse ¶
type ToolUse struct {
ID string `json:"id"`
Name string `json:"name"`
Input interface{} `json:"input"`
}
ToolUse defines a tool usage
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,omitempty"`
CompletionTokensDetails *CompletionTokensDetails `json:"completion_tokens_details,omitempty"`
}