Documentation ¶
Index ¶
- Variables
- func ReleaseChatRequest(req *ChatRequest)
- func ReleaseChatResponse(res *ChatResponse)
- type ChatMessage
- type ChatParams
- type ChatRequest
- type ChatResponse
- type ChatStreamChunk
- type ChatStreamError
- type ChatStreamMessage
- type ChatStreamRequest
- type Error
- type ErrorName
- type EventType
- type FinishReason
- type HealthSchema
- type Metadata
- type ModelChunkResponse
- type ModelParamsOverride
- type ModelResponse
- type RouterListSchema
- type StreamRequestID
- type TokenUsage
Constants ¶
This section is empty.
Variables ¶
var ErrNoModelAvailable = NewError( 503, AllModelsUnavailable, "all providers are unavailable", )
var ErrRouteNotFound = NewError( fiber.StatusNotFound, RouteNotFound, "requested route is not found or method is not allowed", )
var ErrRouterNotFound = NewError(fiber.StatusNotFound, RouterNotFound, "router is not found")
var ErrUnsupportedMediaType = NewError( fiber.StatusBadRequest, UnsupportedMediaType, "application/json is the only supported media type", )
Functions ¶
func ReleaseChatRequest ¶
func ReleaseChatRequest(req *ChatRequest)
ReleaseChatRequest release objects from the pool
func ReleaseChatResponse ¶
func ReleaseChatResponse(res *ChatResponse)
ReleaseChatResponse release objects from the pool
Types ¶
type ChatMessage ¶
type ChatMessage struct { // The role of the author of this message. One of system, user, or assistant. Role string `json:"role" validate:"required"` // The content of the message. Content string `json:"content" validate:"required"` }
ChatMessage is a message in a chat request.
type ChatParams ¶
type ChatParams struct {
Messages []ChatMessage
}
ChatParams represents a chat request params that overrides the default model params from configs
type ChatRequest ¶
type ChatRequest struct { Message ChatMessage `json:"message" validate:"required"` MessageHistory []ChatMessage `json:"message_history,omitempty"` OverrideParams *map[string]ModelParamsOverride `json:"override_params,omitempty"` }
ChatRequest defines Glide's Chat Request Schema unified across all language models
func NewChatFromStr ¶
func NewChatFromStr(message string) *ChatRequest
func (*ChatRequest) ModelParams ¶
func (r *ChatRequest) ModelParams(modelNameOrID string) *ModelParamsOverride
func (*ChatRequest) Params ¶
func (r *ChatRequest) Params(modelID string, modelName string) *ChatParams
Params returns a specific chat request params account for model-specific overrides.
type ChatResponse ¶
type ChatResponse struct { ID string `json:"id"` Created int `json:"created_at"` Provider string `json:"provider_id"` RouterID string `json:"router_id"` ModelID string `json:"model_id"` ModelName string `json:"model_name"` Cached bool `json:"cached"` ModelResponse ModelResponse `json:"model_response"` }
ChatResponse defines Glide's Chat Response Schema unified across all language models
func GetChatResponse ¶
func GetChatResponse() *ChatResponse
GetChatResponse get objects from the pool
type ChatStreamChunk ¶
type ChatStreamChunk struct { ModelID string `json:"model_id"` Provider string `json:"provider_id"` ModelName string `json:"model_name"` Cached bool `json:"cached"` ModelResponse ModelChunkResponse `json:"model_response"` FinishReason *FinishReason `json:"finish_reason,omitempty"` }
ChatStreamChunk defines a message for a chunk of streaming chat response
type ChatStreamError ¶
type ChatStreamError struct { Name ErrorName `json:"name"` Message string `json:"message"` FinishReason *FinishReason `json:"finish_reason,omitempty"` }
type ChatStreamMessage ¶
type ChatStreamMessage struct { ID StreamRequestID `json:"id"` CreatedAt int `json:"created_at"` RouterID string `json:"router_id"` Metadata *Metadata `json:"metadata,omitempty"` Chunk *ChatStreamChunk `json:"chunk,omitempty"` Error *ChatStreamError `json:"error,omitempty"` }
func NewChatStreamChunk ¶
func NewChatStreamChunk( reqID StreamRequestID, routerID string, reqMetadata *Metadata, chunk *ChatStreamChunk, ) *ChatStreamMessage
func NewChatStreamError ¶
func NewChatStreamError( reqID StreamRequestID, routerID string, errName ErrorName, errMsg string, reqMetadata *Metadata, finishReason *FinishReason, ) *ChatStreamMessage
type ChatStreamRequest ¶
type ChatStreamRequest struct { ID StreamRequestID `json:"id" validate:"required"` *ChatRequest OverrideParams *map[string]ModelParamsOverride `json:"override_params,omitempty"` Metadata *Metadata `json:"metadata,omitempty"` }
ChatStreamRequest defines a message that requests a new streaming chat
func NewChatStreamFromStr ¶
func NewChatStreamFromStr(message string) *ChatStreamRequest
type Error ¶
type Error struct { Status int `json:"-"` Name string `json:"name"` Message string `json:"message"` }
Error / Error contains more context than the built-in error type, so we know information like error code and message that are useful to propagate to clients
func NewPayloadParseErr ¶
type ErrorName ¶
type ErrorName = string
var ( UnsupportedMediaType ErrorName = "unsupported_media_type" RouteNotFound ErrorName = "route_not_found" PayloadParseError ErrorName = "payload_parse_error" RouterNotFound ErrorName = "router_not_found" NoModelConfigured ErrorName = "no_model_configured" UnknownError ErrorName = "unknown_error" )
type FinishReason ¶
type FinishReason = string
var ( ReasonComplete FinishReason = "complete" ReasonMaxTokens FinishReason = "max_tokens" ReasonContentFiltered FinishReason = "content_filtered" ReasonError FinishReason = "error" ReasonOther FinishReason = "other" )
type HealthSchema ¶
type HealthSchema struct {
Healthy bool `json:"healthy"`
}
type ModelChunkResponse ¶
type ModelChunkResponse struct { Metadata *Metadata `json:"metadata,omitempty"` Message ChatMessage `json:"message"` }
type ModelParamsOverride ¶
type ModelParamsOverride struct { // TODO: should be just string? Message ChatMessage `json:"message,omitempty"` }
ModelParamsOverride allows to redefine chat message and model params based on the model ID
Glide provides an abstraction around concreate models and this is a way to be able to provide model-specific params if needed. The override is going to be applied if Glide picks the referenced there (it may pick another model to serve a given request)
type ModelResponse ¶
type ModelResponse struct { Metadata map[string]string `json:"metadata"` Message ChatMessage `json:"message"` TokenUsage TokenUsage `json:"token_usage"` }
ModelResponse is the unified response from the provider.
type RouterListSchema ¶
type RouterListSchema struct {
Routers []interface{} `json:"routers"`
}
RouterListSchema returns list of active configured routers.
Routers config is exposed as an opaque value to indicate that user services must not use it to base any logic on it. The endpoint is used for debugging/informational reasons
type StreamRequestID ¶
type StreamRequestID = string