server

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 11 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.

func NewServer

func NewServer(cfg config.ServerConfig, handler http.Handler) *Server

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

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.

Directories

Path Synopsis
Package handlers provides HTTP handlers for the Hapax server.
Package handlers provides HTTP handlers for the Hapax server.
Package processing provides request processing and response formatting for LLM interactions.
Package processing provides request processing and response formatting for LLM interactions.
Package provider implements LLM provider management functionality.
Package provider implements LLM provider management functionality.

Jump to

Keyboard shortcuts

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