Split monolithic 1012-line main.rs into layered hexagonal architecture: - Domain: entity types and LlmError enum - Application: prompt building, sampler construction, tool call parsing - Infrastructure: LlamaEngine wrapping llama-cpp-2 with isolated unsafe transmute - Presentation: Axum handlers, middleware (auth), error chain, router - Config: type-safe AppConfig with LazyLock - Bootstrap: Application struct with build() + run() Resolves build_sampler/build_sampler_params duplication. Adds simple web chat UI at GET /. Co-Authored-By: Claude Code <noreply@anthropic.com>
39 lines
838 B
Rust
39 lines
838 B
Rust
//! Domain-level error types.
|
|
//!
|
|
//! Framework-agnostic errors that can be mapped to HTTP errors
|
|
//! at the presentation layer.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Errors originating from LLM inference operations.
|
|
#[derive(Error, Debug)]
|
|
pub enum LlmError {
|
|
/// Invalid request parameters
|
|
#[error("Invalid request: {0}")]
|
|
InvalidRequest(String),
|
|
|
|
/// Model or inference error
|
|
#[error("Model error: {0}")]
|
|
Model(String),
|
|
|
|
/// Authentication failure
|
|
#[error("Authentication failed")]
|
|
Unauthorized,
|
|
|
|
/// Internal/unexpected error
|
|
#[error("Internal error: {0}")]
|
|
Internal(String),
|
|
}
|
|
|
|
impl From<String> for LlmError {
|
|
fn from(s: String) -> Self {
|
|
LlmError::Internal(s)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for LlmError {
|
|
fn from(s: &str) -> Self {
|
|
LlmError::Internal(s.to_string())
|
|
}
|
|
}
|