Documentation
¶
Index ¶
- Constants
- func APIKeyMiddleware(apiKey string) gin.HandlerFunc
- func CORSMiddleware(origins []string) gin.HandlerFunc
- func LoopbackSecurityMiddleware(corsOrigins []string) gin.HandlerFunc
- func MaxBodyBytesMiddleware(limit int64) gin.HandlerFunc
- func NewModelsHandler(r *gin.Engine, vendorManager *ai.VendorsManager)
- func NewStrategiesHandler(r *gin.Engine)
- func Serve(registry *core.PluginRegistry, address string, apiKey string, ...) (err error)
- func ServeOllama(registry *core.PluginRegistry, address string, version string, apiKey string, ...) error
- type APIConvert
- type ChatHandler
- type ChatRequest
- type ConfigHandler
- type ContextsHandler
- type FabricResponseFormat
- type Model
- type ModelDetails
- type ModelsHandler
- type OllamaMessage
- type OllamaModel
- type OllamaRequestBody
- type OllamaResponse
- type PatternApplyRequest
- type PatternsHandler
- type PromptRequest
- type RedactingWriter
- type SessionsHandler
- type StorageHandler
- func (h *StorageHandler[T]) Delete(c *gin.Context)
- func (h *StorageHandler[T]) Exists(c *gin.Context)
- func (h *StorageHandler[T]) Get(c *gin.Context)
- func (h *StorageHandler[T]) GetNames(c *gin.Context)
- func (h *StorageHandler[T]) Rename(c *gin.Context)
- func (h *StorageHandler[T]) Save(c *gin.Context)
- type StrategyMeta
- type StreamResponse
- type YouTubeHandler
- type YouTubeRequest
- type YouTubeResponse
Constants ¶
const APIKeyHeader = "X-API-Key"
const MaxRequestBodyBytes = 50 << 20 // 50 MiB
MaxRequestBodyBytes is the maximum size of a request body that the server reads. It is large enough for chat requests with images and attached documents.
Variables ¶
This section is empty.
Functions ¶
func APIKeyMiddleware ¶
func APIKeyMiddleware(apiKey string) gin.HandlerFunc
APIKeyMiddleware validates API key for protected endpoints. Swagger documentation endpoints (/swagger/*) are exempt from authentication to allow users to browse and test the API documentation freely.
func CORSMiddleware ¶ added in v1.4.508
func CORSMiddleware(origins []string) gin.HandlerFunc
CORSMiddleware lets browser clients on the listed origins call the server. The origin "*" allows each origin: the response copies the request Origin, not "*". The middleware never allows the origin "null". Register it before APIKeyMiddleware, so a preflight request does not get a 401. Serve and ServeOllama do not register it when the list is empty.
func LoopbackSecurityMiddleware ¶ added in v1.4.516
func LoopbackSecurityMiddleware(corsOrigins []string) gin.HandlerFunc
LoopbackSecurityMiddleware examines the requests to a server that has no API key. Serve and ServeOllama use it only when there is no key, because then the server does no authentication. corsOrigins is the list from cleanCORSOrigins.
The middleware does two checks:
- The Host header must be "localhost", a loopback IP address or the host of a CORS origin. The host name of a web page can resolve to 127.0.0.1. The browser then sends that name in the Host header, and the middleware rejects the request.
- A POST, PUT, DELETE or PATCH request must not have an Origin header from a different origin. A browser sends some of these requests to a different origin with no CORS preflight, for example a text/plain POST. A page on a different loopback port is a different origin. The middleware accepts a request with no Origin header, for example from curl or the CLI.
A server with an API key does not use this middleware. A browser must do a CORS preflight before it sends the X-API-Key header to a different origin.
func MaxBodyBytesMiddleware ¶ added in v1.4.516
func MaxBodyBytesMiddleware(limit int64) gin.HandlerFunc
MaxBodyBytesMiddleware stops a request body at limit bytes. When Content-Length is more than limit, it answers 413 before the handler runs. The middleware reads a body with no length (chunked) before the handler runs, and answers 413 if the body is more than limit. The handler then reads a second copy of a chunked body, thus a chunked request can use two times limit. Without this read, a handler gets the MaxBytesError and answers 400, not 413. limit must be more than 0.
func NewModelsHandler ¶
func NewModelsHandler(r *gin.Engine, vendorManager *ai.VendorsManager)
func NewStrategiesHandler ¶
NewStrategiesHandler registers the /strategies GET endpoint
func Serve ¶
func Serve(registry *core.PluginRegistry, address string, apiKey string, corsOrigins []string) (err error)
@title Fabric REST API @version 1.0 @description REST API for Fabric AI augmentation framework. Provides endpoints for chat completions, pattern management, contexts, sessions, and more. @contact.name Fabric Support @contact.url https://github.com/danielmiessler/fabric @license.name MIT @license.url https://opensource.org/licenses/MIT @host localhost:8080 @BasePath / @securityDefinitions.apikey ApiKeyAuth @in header @name X-API-Key
func ServeOllama ¶
func ServeOllama(registry *core.PluginRegistry, address string, version string, apiKey string, corsOrigins []string) error
ServeOllama operates the Ollama-compatible API server on address. An empty apiKey sets authentication to off. This is permitted only for loopback binds.
Types ¶
type APIConvert ¶
type APIConvert struct {
// contains filtered or unexported fields
}
type ChatHandler ¶
type ChatHandler struct {
// contains filtered or unexported fields
}
func NewChatHandler ¶
func NewChatHandler(r *gin.Engine, registry *core.PluginRegistry, db *fsdb.Db) *ChatHandler
func (*ChatHandler) HandleChat ¶
func (h *ChatHandler) HandleChat(c *gin.Context)
HandleChat godoc @Summary Stream chat completions @Description Stream AI responses using Server-Sent Events (SSE) @Tags chat @Accept json @Produce text/event-stream @Param request body ChatRequest true "Chat request with prompts and options" @Success 200 {object} StreamResponse "Streaming response" @Failure 400 {object} map[string]string @Security ApiKeyAuth @Router /chat [post]
type ChatRequest ¶
type ChatRequest struct {
Prompts []PromptRequest `json:"prompts"`
Language string `json:"language"`
ModelContextLength int `json:"modelContextLength,omitempty"` // Context window size
domain.ChatOptions // Embed the ChatOptions from common package
}
type ConfigHandler ¶
type ConfigHandler struct {
// contains filtered or unexported fields
}
ConfigHandler defines the handler for configuration-related operations
func NewConfigHandler ¶
func NewConfigHandler(r *gin.Engine, db *fsdb.Db) *ConfigHandler
func (*ConfigHandler) GetConfig ¶
func (h *ConfigHandler) GetConfig(c *gin.Context)
func (*ConfigHandler) UpdateConfig ¶
func (h *ConfigHandler) UpdateConfig(c *gin.Context)
type ContextsHandler ¶
type ContextsHandler struct {
*StorageHandler[fsdb.Context]
// contains filtered or unexported fields
}
ContextsHandler defines the handler for contexts-related operations
func NewContextsHandler ¶
func NewContextsHandler(r *gin.Engine, contexts *fsdb.ContextsEntity) (ret *ContextsHandler)
NewContextsHandler creates a new ContextsHandler
type FabricResponseFormat ¶
type ModelDetails ¶
type ModelsHandler ¶
type ModelsHandler struct {
// contains filtered or unexported fields
}
func (*ModelsHandler) GetModelNames ¶
func (h *ModelsHandler) GetModelNames(c *gin.Context)
GetModelNames godoc @Summary List all available models @Description Get a list of all available AI models grouped by vendor @Tags models @Produce json @Success 200 {object} map[string]interface{} "Returns models (array) and vendors (map)" @Failure 500 {object} map[string]string @Security ApiKeyAuth @Router /models/names [get]
type OllamaMessage ¶
type OllamaModel ¶
type OllamaModel struct {
Models []Model `json:"models"`
}
type OllamaRequestBody ¶
type OllamaResponse ¶
type OllamaResponse struct {
Model string `json:"model"`
CreatedAt string `json:"created_at"`
Message OllamaMessage `json:"message"`
DoneReason string `json:"done_reason,omitempty"`
Done bool `json:"done"`
TotalDuration int64 `json:"total_duration,omitempty"`
LoadDuration int64 `json:"load_duration,omitempty"`
PromptEvalCount int64 `json:"prompt_eval_count,omitempty"`
PromptEvalDuration int64 `json:"prompt_eval_duration,omitempty"`
EvalCount int64 `json:"eval_count,omitempty"`
EvalDuration int64 `json:"eval_duration,omitempty"`
}
type PatternApplyRequest ¶
type PatternApplyRequest struct {
Input string `json:"input"`
Variables map[string]string `json:"variables,omitempty"`
}
PatternApplyRequest represents the request body for applying a pattern
type PatternsHandler ¶
type PatternsHandler struct {
*StorageHandler[fsdb.Pattern]
// contains filtered or unexported fields
}
PatternsHandler defines the handler for patterns-related operations
func NewPatternsHandler ¶
func NewPatternsHandler(r *gin.Engine, patterns *fsdb.PatternsEntity) (ret *PatternsHandler)
NewPatternsHandler creates a new PatternsHandler
func (*PatternsHandler) ApplyPattern ¶
func (h *PatternsHandler) ApplyPattern(c *gin.Context)
ApplyPattern handles the POST /patterns/:name/apply route @Summary Apply pattern with variables @Description Apply a pattern with variable substitution @Tags patterns @Accept json @Produce json @Param name path string true "Pattern name" @Param request body PatternApplyRequest true "Pattern application request" @Success 200 {object} fsdb.Pattern @Failure 400 {object} map[string]string @Failure 500 {object} map[string]string @Security ApiKeyAuth @Router /patterns/{name}/apply [post]
func (*PatternsHandler) Get ¶
func (h *PatternsHandler) Get(c *gin.Context)
Get handles the GET /patterns/:name route - returns raw pattern without variable processing @Summary Get a pattern @Description Retrieve a pattern by name @Tags patterns @Accept json @Produce json @Param name path string true "Pattern name" @Success 200 {object} fsdb.Pattern @Failure 400 {object} map[string]string @Failure 500 {object} map[string]string @Security ApiKeyAuth @Router /patterns/{name} [get]
type PromptRequest ¶
type PromptRequest struct {
UserInput string `json:"userInput"`
Vendor string `json:"vendor"`
Model string `json:"model"`
ContextName string `json:"contextName"`
PatternName string `json:"patternName"`
StrategyName string `json:"strategyName"` // Optional strategy name
SessionName string `json:"sessionName"` // Session name for multi-turn conversations
Variables map[string]string `json:"variables,omitempty"` // Pattern variables
}
type RedactingWriter ¶ added in v1.4.530
type RedactingWriter struct {
// contains filtered or unexported fields
}
RedactingWriter masks secret request headers in what gin.Recovery writes. Recovery prints the whole request dump in one Write call, for both the debug-mode panic dump and the broken-pipe dump.
type SessionsHandler ¶
type SessionsHandler struct {
*StorageHandler[fsdb.Session]
// contains filtered or unexported fields
}
SessionsHandler defines the handler for sessions-related operations
func NewSessionsHandler ¶
func NewSessionsHandler(r *gin.Engine, sessions *fsdb.SessionsEntity) (ret *SessionsHandler)
NewSessionsHandler creates a new SessionsHandler
type StorageHandler ¶
type StorageHandler[T any] struct { // contains filtered or unexported fields }
StorageHandler defines the handler for storage-related operations
func NewStorageHandler ¶
func NewStorageHandler[T any](r *gin.Engine, entityType string, storage db.Storage[T]) (ret *StorageHandler[T])
NewStorageHandler creates a new StorageHandler
func (*StorageHandler[T]) Delete ¶
func (h *StorageHandler[T]) Delete(c *gin.Context)
Delete handles the DELETE /storage/:name route
func (*StorageHandler[T]) Exists ¶
func (h *StorageHandler[T]) Exists(c *gin.Context)
Exists handles the GET /storage/exists/:name route. The storage Exists contract cannot report an invalid name, and the handler must validate the name itself. An invalid name is a 400, not a "false".
func (*StorageHandler[T]) Get ¶
func (h *StorageHandler[T]) Get(c *gin.Context)
Get handles the GET /storage/:name route
func (*StorageHandler[T]) GetNames ¶
func (h *StorageHandler[T]) GetNames(c *gin.Context)
GetNames handles the GET /storage/names route
func (*StorageHandler[T]) Rename ¶
func (h *StorageHandler[T]) Rename(c *gin.Context)
Rename handles the PUT /storage/rename/:oldName/:newName route
func (*StorageHandler[T]) Save ¶
func (h *StorageHandler[T]) Save(c *gin.Context)
Save handles the POST /storage/save/:name route
type StrategyMeta ¶
type StrategyMeta struct {
Name string `json:"name"`
Description string `json:"description"`
Prompt string `json:"prompt"`
}
StrategyMeta represents the minimal info about a strategy
type StreamResponse ¶
type StreamResponse struct {
Type string `json:"type"` // "content", "usage", "error", "complete"
Format string `json:"format,omitempty"` // "markdown", "mermaid", "plain"
Content string `json:"content,omitempty"`
Usage *domain.UsageMetadata `json:"usage,omitempty"`
}
type YouTubeHandler ¶
type YouTubeHandler struct {
// contains filtered or unexported fields
}
func NewYouTubeHandler ¶
func NewYouTubeHandler(r *gin.Engine, registry *core.PluginRegistry) *YouTubeHandler
func (*YouTubeHandler) Transcript ¶
func (h *YouTubeHandler) Transcript(c *gin.Context)
Transcript godoc @Summary Get YouTube video transcript @Description Retrieves the transcript of a YouTube video along with video metadata (title and description) @Tags youtube @Accept json @Produce json @Param request body YouTubeRequest true "YouTube transcript request with URL, language, and timestamp options" @Success 200 {object} YouTubeResponse "Successful response with transcript and metadata" @Failure 400 {object} map[string]string "Bad request - invalid URL or playlist URL provided" @Failure 500 {object} map[string]string "Internal server error - failed to retrieve transcript or metadata" @Security ApiKeyAuth @Router /youtube/transcript [post]
type YouTubeRequest ¶
type YouTubeRequest struct {
URL string `json:"url" binding:"required" example:"https://www.youtube.com/watch?v=dQw4w9WgXcQ"` // YouTube video URL (required)
Language string `json:"language,omitempty" example:"en"` // Language code for transcript (default: "en")
Timestamps bool `json:"timestamps,omitempty" example:"false"` // Include timestamps in the transcript (default: false)
}
YouTubeRequest represents a request to get a YouTube video transcript
type YouTubeResponse ¶
type YouTubeResponse struct {
Transcript string `json:"transcript" example:"This is the video transcript..."` // The video transcript text
VideoId string `json:"videoId" example:"dQw4w9WgXcQ"` // YouTube video ID
Title string `json:"title" example:"Example Video Title"` // Video title from YouTube metadata
Description string `json:"description" example:"This is the video description from YouTube..."` // Video description from YouTube metadata
}
YouTubeResponse represents the response containing video transcript and metadata