model

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ContentTypeText       = "text"
	ContentTypeImageURL   = "image_url"
	ContentTypeInputAudio = "input_audio"
	// Chat §4 content part 全集补齐(T3 建模 audio/file/refusal)
	ContentTypeFile    = "file"
	ContentTypeRefusal = "refusal"
)
View Source
const (
	CodeInvalidSourceJSON     = "invalid_source_json"
	CodeInvalidSourceShape    = "invalid_source_shape"
	CodeUnsupportedMapping    = "unsupported_mapping"
	CodeMalformedToolCall     = "malformed_tool_call"
	CodeInvalidStreamEvent    = "invalid_stream_event"
	CodeUnsupportedOutputItem = "unsupported_output_item"
)

协议转换稳定机器码枚举(全局约束 §1.3):值一旦发布不得改名,客户端与日志按此分派。

View Source
const (
	DirectionChatRequestToResponses  = "chat_request_to_responses"
	DirectionResponsesRequestToChat  = "responses_request_to_chat"
	DirectionResponsesResponseToChat = "responses_response_to_chat"
	DirectionChatResponseToResponses = "chat_response_to_responses"
)

协议转换方向枚举(全局约束 §1.3),Path 使用源协议 JSON path。

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio

type Audio struct {
	Voice  string `json:"voice,omitempty"`
	Format string `json:"format,omitempty"`
}

type CompletionTokensDetails

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

CompletionTokensDetails 是网关内部 usage 的输出细分(chat-completions-protocol.md §8.2)。

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 Error

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

type ErrorWithStatusCode

type ErrorWithStatusCode struct {
	Error
	StatusCode int `json:"status_code"`
}

func (*ErrorWithStatusCode) LooksLikeRequestShapeFailure added in v1.0.1

func (e *ErrorWithStatusCode) LooksLikeRequestShapeFailure() bool

LooksLikeRequestShapeFailure 判定错误是否属于客户端请求形态类失败(请求体/参数/格式非法等)。 此类失败来自客户端输入而非渠道健康问题,不应用于渠道健康惩罚(不计数、不冷却); marker 列表与渠道冷却口径保持一致。nil 接收者返回 false。

func (*ErrorWithStatusCode) SemanticText added in v1.0.1

func (e *ErrorWithStatusCode) SemanticText() string

SemanticText 返回错误的语义拼接文本(小写 type | code | message), 供跨层基于文本 marker 的错误分类复用;nil 接收者返回空串。

type Function

type Function struct {
	Description string `json:"description,omitempty"`
	Name        string `json:"name,omitempty"`       // when splicing claude tools stream messages, it is empty
	Parameters  any    `json:"parameters,omitempty"` // request
	Arguments   any    `json:"arguments,omitempty"`  // response
	// Strict 用指针区分"未提供"与显式 false(chat-completions-protocol.md §5.1),
	// 并在 Chat→Responses 工具扁平转换中原样保留。
	Strict *bool `json:"strict,omitempty"`
}

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"`
	Verbosity           string          `json:"verbosity,omitempty"` // §2.2 low|medium|high,Chat→Responses 转 text.verbosity
	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 ImageURL

type ImageURL struct {
	Url    string `json:"url,omitempty"`
	Detail string `json:"detail,omitempty"`
}

type InputTokensDetails

type InputTokensDetails struct {
	CachedTokens     int `json:"cached_tokens"`
	CacheWriteTokens int `json:"cache_write_tokens"`
}

InputTokensDetails contains detailed input token statistics(Responses §6) cache_write_tokens 是 §6 必填的缓存写入明细,缺失会导致 capture 重序列化丢字段。

type JSONSchema

type JSONSchema struct {
	Description string                 `json:"description,omitempty"`
	Name        string                 `json:"name"`
	Schema      map[string]interface{} `json:"schema,omitempty"`
	Strict      *bool                  `json:"strict,omitempty"`
}

type Message

type Message struct {
	Role    string `json:"role,omitempty"`
	Content any    `json:"content,omitempty"`
	// Refusal 对应 Chat §3.1 assistant 消息顶层 refusal 字段;指针区分"未提供"与显式空串。
	Refusal          *string `json:"refusal,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 (m Message) IsStringContent() bool

func (Message) ParseContent

func (m Message) ParseContent() ([]MessageContent, error)

ParseContent 防御性安全解析 message content(chat-completions-protocol.md §4)。 字符串 content 视为单一 text part;数组 content 逐 part 做类型检查,任何形状违约 (非对象元素、必填子字段缺失或类型错误、未知 part type)均返回 error 且不 panic, 失败路径不返回部分结果,调用方不得 swallow。

func (Message) StringContent

func (m Message) StringContent() string

type MessageContent

type MessageContent struct {
	Type       string    `json:"type,omitempty"`
	Text       string    `json:"text,omitempty"`
	Refusal    string    `json:"refusal,omitempty"`
	ImageURL   *ImageURL `json:"image_url,omitempty"`
	InputAudio any       `json:"input_audio,omitempty"`
	File       any       `json:"file,omitempty"`
}

MessageContent 覆盖 Chat §4 全部 5 种 content part;audio/file 以原始对象承载, 必填子字段的合法性校验由各转换方的前置校验负责(如 chatgptsub T2)。

type OutputTokensDetails

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

OutputTokensDetails contains detailed output token statistics(Responses §6)

type PromptTokensDetails

type PromptTokensDetails struct {
	CachedTokens     int `json:"cached_tokens"` // 缓存命中的token数
	CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
	AudioTokens      int `json:"audio_tokens,omitempty"`
	TextTokens       int `json:"text_tokens,omitempty"`
	ImageTokens      int `json:"image_tokens,omitempty"`
}

PromptTokensDetails 是网关内部 usage 的输入细分(chat-completions-protocol.md §8.1)。 CacheWriteTokens 只作为 detail 承载供日志与后续计费策略使用,不参与现有 quota 公式。

type ProtocolConversionError added in v1.0.1

type ProtocolConversionError struct {
	Code      string
	Direction string
	Path      string
	Cause     error
}

ProtocolConversionError 是跨协议转换的显式错误边界(全局约束 §1.3)。 未来自各 adaptor 的不可无损映射必须归入此类型,禁止记日志后静默继续。

func (*ProtocolConversionError) Error added in v1.0.1

func (e *ProtocolConversionError) Error() string

Error 输出稳定机器码 + 方向 + 源协议 JSON path,Cause 存在时追加其文本。

func (*ProtocolConversionError) Unwrap added in v1.0.1

func (e *ProtocolConversionError) Unwrap() error

Unwrap 暴露底层原因,使 errors.Is/errors.As 可继续追溯。

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 ResponseIncompleteDetails added in v1.0.1

type ResponseIncompleteDetails struct {
	Reason string `json:"reason"`
}

ResponseIncompleteDetails represents the incomplete reason in an incomplete Responses API response Reason 枚举见 docs/responses-protocol.md §4:max_output_tokens、content_filter、steered 等

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, error)

ArgumentsString 返回 function_call arguments 的实际 JSON 字符串(Responses §3.2)。

func (ResponsesItem) InputString

func (r ResponsesItem) InputString() (string, error)

InputString 返回 custom_tool_call input 的实际字符串(Responses §3.5)。

func (ResponsesItem) OutputString

func (r ResponsesItem) OutputString() (string, error)

OutputString 返回 output 类 item output 字段的实际字符串(Responses §3.3)。

type ResponsesRequest

type ResponsesRequest struct {
	Model              string   `json:"model"`
	Instructions       string   `json:"instructions,omitempty"` // system prompt
	Input              any      `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
	Stream             bool     `json:"stream,omitempty"`              // stream output
	StreamOptions      any      `json:"stream_options,omitempty"`      // stream options
	RawTools           []any    `json:"tools,omitempty"`               // §9 扁平工具定义
	ToolChoice         any      `json:"tool_choice,omitempty"`         // string or object
	ParallelToolCalls  *bool    `json:"parallel_tool_calls,omitempty"` // parallel tool calls

	Reasoning   any      `json:"reasoning,omitempty"`    // 推理配置(§2 effort 等)
	Text        any      `json:"text,omitempty"`         // 输出文本配置(§2 format/verbosity)
	Modalities  []string `json:"modalities,omitempty"`   // 输出模态
	Metadata    any      `json:"metadata,omitempty"`     // 附加元数据
	ServiceTier *string  `json:"service_tier,omitempty"` // 服务层级
	User        string   `json:"user,omitempty"`         // user identifier

	// 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]any `json:"-"`
}

ResponsesRequest is the request structure for Responses API 顶层字段对齐 docs/responses-protocol.md §2:采样/布尔字段用指针保留显式零值与 false (temperature/top_p/store/parallel_tool_calls/service_tier),否则 omitempty 会吞掉 客户端显式意图;stop/frequency_penalty/presence_penalty 不属于 Responses 请求 schema, 非缺省值必须在转换边界显式拒绝而非序列化丢失。

type ResponsesResponse

type ResponsesResponse struct {
	ID                string                     `json:"id"`
	Object            string                     `json:"object"`
	Model             string                     `json:"model"`
	Output            []ResponsesItem            `json:"output"`
	Status            string                     `json:"status"` // completed, failed
	PreviousID        *string                    `json:"previous_response_id"`
	Usage             ResponsesUsage             `json:"usage"`
	Created           int64                      `json:"created_at"`
	Error             *ResponseError             `json:"error"`
	IncompleteDetails *ResponseIncompleteDetails `json:"incomplete_details"`

	// 以下为 §4 的可回显请求字段,capture 重序列化时必须原名保留
	Instructions      any            `json:"instructions"`
	MaxOutputTokens   *int           `json:"max_output_tokens"`
	ParallelToolCalls bool           `json:"parallel_tool_calls"`
	Reasoning         any            `json:"reasoning"`
	ServiceTier       string         `json:"service_tier"`
	Temperature       *float64       `json:"temperature"`
	ToolChoice        any            `json:"tool_choice"`
	Tools             []interface{}  `json:"tools"`
	TopP              *float64       `json:"top_p"`
	Truncated         bool           `json:"truncated"`
	User              any            `json:"user"`
	Metadata          map[string]any `json:"metadata"`
	Store             *bool          `json:"store"`
	Text              any            `json:"text"`
	Modalities        []string       `json:"modalities"`
	OutputText        string         `json:"output_text,omitempty"`
}

ResponsesResponse is the response structure for Responses API wire key 严格对齐 docs/responses-protocol.md §4:时间为 created_at、前序引用为 previous_response_id, 不得再输出 created/previous_id。Go 字段名保持 Created/PreviousID 不变,避免下游转换函数被连带改名。 codex 直通日志 capture 快照经本结构体序列化,缺字段会导致 response.incomplete 终态的截断原因丢失。

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"`
	ItemID     string             `json:"item_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_response_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"`
	OutputTokens        int                  `json:"output_tokens"`
	OutputTokensDetails *OutputTokensDetails `json:"output_tokens_details"`
	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 五个顶层字段与两个 details 对象按 §6 全必填:details 指针不带 omitempty, 使生成端始终输出该对象(nil 输出 null),同时解析上游缺失时仍可为 nil 以识别畸形来源。

type StreamOptions

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

type Tool

type Tool struct {
	Id       string   `json:"id,omitempty"`
	Type     string   `json:"type,omitempty"` // when splicing claude tools stream messages, it is empty
	Function Function `json:"function"`
}

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"`
}

Jump to

Keyboard shortcuts

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