Documentation
¶
Overview ¶
Package openai provides HTTP handlers for constant.OpenAI API endpoints. This package implements the constant.OpenAI-compatible API interface, including model listing and chat completion functionality. It supports both streaming and non-streaming responses, and manages a pool of clients to interact with backend services. The handlers translate constant.OpenAI API requests to the appropriate backend format and convert responses back to constant.OpenAI-compatible format.
Package openai provides HTTP handlers for OpenAIResponses API endpoints. This package implements the OpenAIResponses-compatible API interface, including model listing and chat completion functionality. It supports both streaming and non-streaming responses, and manages a pool of clients to interact with backend services. The handlers translate OpenAIResponses API requests to the appropriate backend format and convert responses back to OpenAIResponses-compatible format.
Index ¶
- type APIHandler
- type ResponsesAPIHandler
- func (h *ResponsesAPIHandler) Compact(c *gin.Context)
- func (h *ResponsesAPIHandler) HandlerType() string
- func (h *ResponsesAPIHandler) Models() []map[string]any
- func (h *ResponsesAPIHandler) OpenAIResponsesModels(c *gin.Context)
- func (h *ResponsesAPIHandler) Responses(c *gin.Context)
- func (h *ResponsesAPIHandler) ResponsesWebsocket(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIHandler ¶
type APIHandler struct {
*handlers.BaseAPIHandler
}
APIHandler contains the handlers for constant.OpenAI API endpoints. It holds a pool of clients to interact with the backend service.
func NewAPIHandler ¶
func NewAPIHandler(apiHandlers *handlers.BaseAPIHandler) *APIHandler
NewAPIHandler creates a new constant.OpenAI API handlers instance. It takes an BaseAPIHandler instance as input and returns an APIHandler.
Parameters:
- apiHandlers: The base API handlers instance
Returns:
- *APIHandler: A new constant.OpenAI API handlers instance
func (*APIHandler) ChatCompletions ¶
func (h *APIHandler) ChatCompletions(c *gin.Context)
ChatCompletions handles the /v1/chat/completions endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler based on the model provider.
Parameters:
- c: The Gin context containing the HTTP request and response
func (*APIHandler) Completions ¶
func (h *APIHandler) Completions(c *gin.Context)
Completions handles the /v1/completions endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler based on the model provider. This endpoint follows the constant.OpenAI completions API specification.
Parameters:
- c: The Gin context containing the HTTP request and response
func (*APIHandler) HandlerType ¶
func (h *APIHandler) HandlerType() string
HandlerType returns the identifier for this handler implementation.
func (*APIHandler) Models ¶
func (h *APIHandler) Models() []map[string]any
Models returns the constant.OpenAI-compatible model metadata supported by this handler.
func (*APIHandler) OpenAIModels ¶
func (h *APIHandler) OpenAIModels(c *gin.Context)
OpenAIModels handles the /v1/models endpoint. It returns a list of available AI models with their capabilities and specifications in constant.OpenAI-compatible format.
type ResponsesAPIHandler ¶
type ResponsesAPIHandler struct {
*handlers.BaseAPIHandler
}
ResponsesAPIHandler contains the handlers for OpenAIResponses API endpoints. It holds a pool of clients to interact with the backend service.
func NewResponsesAPIHandler ¶
func NewResponsesAPIHandler(apiHandlers *handlers.BaseAPIHandler) *ResponsesAPIHandler
NewResponsesAPIHandler creates a new OpenAIResponses API handlers instance. It takes an BaseAPIHandler instance as input and returns an ResponsesAPIHandler.
Parameters:
- apiHandlers: The base API handlers instance
Returns:
- *ResponsesAPIHandler: A new OpenAIResponses API handlers instance
func (*ResponsesAPIHandler) Compact ¶
func (h *ResponsesAPIHandler) Compact(c *gin.Context)
func (*ResponsesAPIHandler) HandlerType ¶
func (h *ResponsesAPIHandler) HandlerType() string
HandlerType returns the identifier for this handler implementation.
func (*ResponsesAPIHandler) Models ¶
func (h *ResponsesAPIHandler) Models() []map[string]any
Models returns the OpenAIResponses-compatible model metadata supported by this handler.
func (*ResponsesAPIHandler) OpenAIResponsesModels ¶
func (h *ResponsesAPIHandler) OpenAIResponsesModels(c *gin.Context)
OpenAIResponsesModels handles the /v1/models endpoint. It returns a list of available AI models with their capabilities and specifications in OpenAIResponses-compatible format.
func (*ResponsesAPIHandler) Responses ¶
func (h *ResponsesAPIHandler) Responses(c *gin.Context)
Responses handles the /v1/responses endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler based on the model provider.
Parameters:
- c: The Gin context containing the HTTP request and response
func (*ResponsesAPIHandler) ResponsesWebsocket ¶
func (h *ResponsesAPIHandler) ResponsesWebsocket(c *gin.Context)
ResponsesWebsocket handles websocket requests for /v1/responses. It accepts `response.create` and `response.append` requests and streams response events back as JSON websocket text messages.