handlers

package
v0.0.12 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: 8 Imported by: 0

Documentation

Overview

Package handlers provides HTTP handlers for the Hapax server. It implements request handling for completions, chat, and function calling using the gollm library and Hapax processing system.

The package follows these design principles: 1. Consistent error handling using the errors package 2. Structured logging with request IDs 3. Clear request validation and type conversion 4. Separation between request parsing and processing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Messages []gollm.PromptMessage `json:"messages" validate:"required,min=1"` // List of chat messages
}

ChatRequest represents a chat-style request with message history. It follows the gollm chat format with roles and content. Messages must be non-empty and contain valid roles.

type CompletionHandler

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

CompletionHandler handles different types of completion requests. It supports: - Simple text completion (default) - Chat completion with message history - Function calling (future feature)

func NewCompletionHandler

func NewCompletionHandler(processor *processing.Processor, logger *zap.Logger) *CompletionHandler

NewCompletionHandler creates a new completion handler with the given processor and logger. It requires both parameters to be non-nil.

func (*CompletionHandler) ServeHTTP

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

ServeHTTP implements http.Handler interface. It handles all completion requests by: 1. Determining the request type 2. Validating and parsing the request 3. Processing using the appropriate template 4. Formatting and returning the response

Error Handling: - ValidationError: Invalid request format or missing fields - ProcessingError: LLM or processing failures - InternalError: Unexpected system errors

Each error is logged with: - Request ID for tracking - Error type and message - Request context (type, path)

type CompletionRequest

type CompletionRequest struct {
	Input string `json:"input" validate:"required"` // The input text to complete
}

CompletionRequest represents a simple text completion request. This is the default request type when no specific type is specified. All fields are validated before processing.

type FunctionRequest

type FunctionRequest struct {
	Input               string `json:"input" validate:"required"`                // The input text
	FunctionDescription string `json:"function_description" validate:"required"` // Description of the function to call
}

FunctionRequest represents a function calling request. This is used for structured function-like interactions. Both input and function description are required.

Jump to

Keyboard shortcuts

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