server

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package server implements the HTTP server and routing logic for the Hapax LLM service. It provides endpoints for LLM completions, health checks, and Prometheus metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionHandler

type CompletionHandler struct {
	// contains filtered or unexported fields
}

CompletionHandler processes LLM completion requests. It maintains a reference to the LLM client to generate responses.

func NewCompletionHandler

func NewCompletionHandler(llm gollm.LLM) *CompletionHandler

NewCompletionHandler creates a new completion handler with the specified LLM client.

func (*CompletionHandler) ServeHTTP

func (h *CompletionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for completion requests. It: 1. Validates the request method and body 2. Extracts the prompt from the request 3. Sends the prompt to the LLM for completion 4. Returns the generated completion to the client

type CompletionRequest

type CompletionRequest struct {
	Prompt string `json:"prompt"`
}

CompletionRequest represents an incoming completion request from clients. The prompt field contains the text to send to the LLM for completion.

type CompletionResponse

type CompletionResponse struct {
	Completion string `json:"completion"`
}

CompletionResponse represents the response sent back to clients. The completion field contains the generated text from the LLM.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router handles HTTP routing and middleware configuration. It sets up all endpoints and applies common middleware to requests.

func NewRouter

func NewRouter(completion http.Handler) *Router

NewRouter creates a new router with all endpoints configured. It: 1. Sets up common middleware (request ID, timing, panic recovery, CORS) 2. Configures the completion endpoint for LLM requests 3. Adds health check endpoint for container orchestration 4. Adds metrics endpoint for Prometheus monitoring

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface for the router. This allows the router to be used directly with the standard library's HTTP server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the HTTP server instance. It wraps the standard library's http.Server with our configuration. The running boolean tracks whether the server is operational, while the mu mutex protects concurrent access to this state. This ensures that multiple goroutines do not interfere with each other when checking or updating the server's status.

func NewServer

func NewServer(configPath string, logger *zap.Logger) (*Server, error)

NewServer creates a new server with the specified configuration and handler. It configures timeouts and limits based on the provided configuration.

func NewServerWithConfig added in v0.0.16

func NewServerWithConfig(cfg config.Watcher, llm gollm.LLM, logger *zap.Logger) (*Server, error)

NewServerWithConfig for testing now takes care of the LLM

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins serving HTTP requests and blocks until shutdown. It handles graceful shutdown when the context is cancelled, ensuring that all connections are properly closed before exiting.

Directories

Path Synopsis
Package handlers provides HTTP handlers for the Hapax server.
Package handlers provides HTTP handlers for the Hapax server.
Package middleware provides various middleware functions for HTTP handlers.
Package middleware provides various middleware functions for HTTP handlers.
Package processing provides request processing and response formatting for LLM interactions.
Package processing provides request processing and response formatting for LLM interactions.
Package routing provides dynamic HTTP routing with versioning and health checks.
Package routing provides dynamic HTTP routing with versioning and health checks.

Jump to

Keyboard shortcuts

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