Documentation
¶
Index ¶
- Variables
- func AppendToFile(filename string, content string)
- func ApplyPatchInputFromProxyArguments(rawArguments string, action string) string
- func BuildApplyPatchInput(ops []ApplyPatchOperation) string
- func ConvertChatResponseToResponses(chatResponseBody []byte, model string, fallbackReasoningToMessage bool) []byte
- func ConvertChatResponseToResponsesWithContext(chatResponseBody []byte, model string, fallbackReasoningToMessage bool, ...) []byte
- func ConvertOpenAIChatToResponses(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, ...) []string
- func ConvertOpenAIChatToResponsesWithContext(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, ...) []string
- func ConvertResponsesToChatRequest(modelName string, inputRawJSON []byte, stream bool) []byte
- func DoResponsesResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)
- func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode
- func GetStreamCompletedBody(param interface{}, originalRequestRawJSON []byte) []byte
- func GetStreamUsage(param interface{}) (promptTokens, completionTokens, totalTokens, cachedTokens int)
- func RenderTerminalStreamReadErrorEvent(c *gin.Context, err error)
- func StreamResponsesHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, string, *model.Usage)
- type Adaptor
- func (a *Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)
- func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)
- func (a *Adaptor) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)
- func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)
- func (a *Adaptor) GetChannelName() string
- func (a *Adaptor) GetModelList() []string
- func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error)
- func (a *Adaptor) Init(meta *meta.Meta)
- func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error
- type ApplyPatchHunk
- type ApplyPatchLineOp
- type ApplyPatchOperation
- type CodexCustomToolKind
- type CodexCustomToolSpec
- type CodexFunctionToolSpec
- type CodexToolContext
- func (ctx CodexToolContext) IsBuiltinTool(name, kind string) bool
- func (ctx CodexToolContext) IsCustomToolProxy(upstreamName string) bool
- func (ctx CodexToolContext) OpenAINameForFunctionTool(upstreamName string) (name string, namespace string)
- func (ctx CodexToolContext) OriginalCustomToolName(upstreamName string) string
- type SSEEvent
Constants ¶
This section is empty.
Variables ¶
var ModelList = []string{
"gpt-4o",
"gpt-4o-mini",
"gpt-4-turbo",
"gpt-4",
"gpt-3.5-turbo",
"o1",
"o1-mini",
}
Functions ¶
func AppendToFile ¶
appendToFile 追加内容到文件(文件不存在则创建)
func ApplyPatchInputFromProxyArguments ¶
ApplyPatchInputFromProxyArguments reconstructs apply_patch grammar input from proxy arguments.
func BuildApplyPatchInput ¶
func BuildApplyPatchInput(ops []ApplyPatchOperation) string
BuildApplyPatchInput builds raw apply_patch grammar input from operations.
func ConvertChatResponseToResponses ¶
func ConvertChatResponseToResponses(chatResponseBody []byte, model string, fallbackReasoningToMessage bool) []byte
ConvertChatResponseToResponses 把上游 chat 响应转回 codex Responses 格式。 保留为 3 参数旧入口,等价于 ConvertChatResponseToResponsesWithContext(..., nil)。
func ConvertChatResponseToResponsesWithContext ¶
func ConvertChatResponseToResponsesWithContext(chatResponseBody []byte, model string, fallbackReasoningToMessage bool, originalRequestRawJSON []byte) []byte
ConvertChatResponseToResponsesWithContext 把上游 chat 响应转回 codex Responses 格式。 当 originalRequestRawJSON 非 nil 时,从原始 Responses 请求里解析 CodexToolContext, 用于在 tool_calls 还原时识别 namespace 字段与 custom_tool_call 类型。 当 originalRequestRawJSON 为 nil 时,退化到旧 3 参数行为(保持 100% 向后兼容)。
func ConvertOpenAIChatToResponses ¶
func ConvertOpenAIChatToResponses(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) []string
ConvertOpenAIChatToResponses 将 OpenAI Chat Completions SSE 转换为 Responses SSE 事件。 旧 5 参数入口,作为 thin wrapper 调用 ConvertOpenAIChatToResponsesWithContext 并传 nil 作为 originalRequestRawJSON,保持对历史调用方的 100% 行为兼容。 originalRequestRawJSON: 原始的 Responses API 请求 JSON(用于回显字段) requestRawJSON: 转换后的 Chat Completions 请求 JSON rawJSON: OpenAI Chat Completions SSE 行 param: 状态指针(*any,在多次调用间保持状态)
func ConvertOpenAIChatToResponsesWithContext ¶
func ConvertOpenAIChatToResponsesWithContext(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) []string
ConvertOpenAIChatToResponsesWithContext 将 OpenAI Chat Completions SSE 转换为 Responses SSE 事件。 当 originalRequestRawJSON 非 nil 时,从原始 Responses 请求里解析 CodexToolContext, 用于在 tool_calls 流式 output_item.added 事件中携带正确的 name/namespace/custom_tool_call 类型。 当 originalRequestRawJSON 为 nil 时,退化到无 CodexCtx 行为(name 保留原上游名,无 namespace 字段)。 #5 修复:流式 output_item.added 事件必须在 first chunk 时就带 name/namespace/input,与 #4 非流式对称。 originalRequestRawJSON: 原始的 Responses API 请求 JSON requestRawJSON: 转换后的 Chat Completions 请求 JSON rawJSON: OpenAI Chat Completions SSE 行 param: 状态指针(*any,在多次调用间保持状态) fallbackReasoningToMessage: 兜底无 content 仅 reasoning 时复制文本为 message
func DoResponsesResponse ¶
func ErrorWrapper ¶
func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode
func GetStreamCompletedBody ¶
func GetStreamUsage ¶
func GetStreamUsage(param interface{}) (promptTokens, completionTokens, totalTokens, cachedTokens int)
Types ¶
type Adaptor ¶
func (*Adaptor) ConvertImageRequest ¶
func (a *Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)
func (*Adaptor) ConvertRequest ¶
func (*Adaptor) DoResponse ¶
func (*Adaptor) GetChannelName ¶
func (*Adaptor) GetModelList ¶
type ApplyPatchHunk ¶
type ApplyPatchHunk struct {
Context string
Lines []ApplyPatchLineOp
}
ApplyPatchHunk represents a patch hunk.
type ApplyPatchLineOp ¶
ApplyPatchLineOp represents a patch line operation.
type ApplyPatchOperation ¶
type ApplyPatchOperation struct {
Type string
Path string
MoveTo string
Content string
Hunks []ApplyPatchHunk
}
ApplyPatchOperation represents a single patch operation.
type CodexCustomToolKind ¶
type CodexCustomToolKind string
CodexCustomToolKind classifies the type of Codex custom tool.
const ( CodexCustomToolRaw CodexCustomToolKind = "raw" CodexCustomToolApplyPatch CodexCustomToolKind = "apply_patch" CodexCustomToolExec CodexCustomToolKind = "exec" CodexCustomToolBuiltIn CodexCustomToolKind = "builtin" )
type CodexCustomToolSpec ¶
type CodexCustomToolSpec struct {
OpenAIName string
GrammarDefinition string
Kind CodexCustomToolKind
ProxyAction string // "", add_file, delete_file, update_file, replace_file, batch
}
CodexCustomToolSpec describes a single Codex custom tool and its upstream proxy.
type CodexFunctionToolSpec ¶
CodexFunctionToolSpec describes a normal function tool for namespace tracking.
type CodexToolContext ¶
type CodexToolContext struct {
CustomTools map[string]CodexCustomToolSpec
FunctionTools map[string]CodexFunctionToolSpec
BuiltinTools map[string]string
HasCustomTools bool
HasNamespaceTools bool
}
CodexToolContext holds parsed information about all tools in a request.
func BuildCodexToolContextFromRaw ¶
func BuildCodexToolContextFromRaw(tools []interface{}) CodexToolContext
BuildCodexToolContextFromRaw builds Codex tool context from raw tools slice.
func (CodexToolContext) IsBuiltinTool ¶
func (ctx CodexToolContext) IsBuiltinTool(name, kind string) bool
IsBuiltinTool returns whether the given upstream name is a registered built-in tool of the requested kind.
func (CodexToolContext) IsCustomToolProxy ¶
func (ctx CodexToolContext) IsCustomToolProxy(upstreamName string) bool
IsCustomToolProxy returns whether the given upstream name is a Codex custom tool proxy.
func (CodexToolContext) OpenAINameForFunctionTool ¶
func (ctx CodexToolContext) OpenAINameForFunctionTool(upstreamName string) (name string, namespace string)
OpenAINameForFunctionTool returns the unflattened (name, namespace) for an upstream flat function name.
func (CodexToolContext) OriginalCustomToolName ¶
func (ctx CodexToolContext) OriginalCustomToolName(upstreamName string) string
OriginalCustomToolName returns the original Codex tool name for a proxy name.