schemas

package
v0.0.0-...-df6d72d Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoModelAvailable = NewError(
	503,
	AllModelsUnavailable,
	"all providers are unavailable",
)
View Source
var ErrRouteNotFound = NewError(
	fiber.StatusNotFound,
	RouteNotFound,
	"requested route is not found or method is not allowed",
)
View Source
var ErrRouterNotFound = NewError(fiber.StatusNotFound, RouterNotFound, "router is not found")
View Source
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 GetChatRequest

func GetChatRequest() *ChatRequest

GetChatRequest get objects from the pool

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 FromErr

func FromErr(err error) Error

func NewError

func NewError(status int, name string, message string) Error

func NewPayloadParseErr

func NewPayloadParseErr(err error) Error

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

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"
	ModelUnavailable     ErrorName = "model_unavailable"
	AllModelsUnavailable ErrorName = "all_models_unavailable"
	UnknownError         ErrorName = "unknown_error"
)

type EventType

type EventType = string

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 Metadata

type Metadata = map[string]any

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

type TokenUsage

type TokenUsage struct {
	PromptTokens   int `json:"prompt_tokens"`
	ResponseTokens int `json:"response_tokens"`
	TotalTokens    int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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