Skip to main content

turul_llm_core/
lib.rs

1//! Provider-neutral LLM client trait + request/response types + error
2//! taxonomy.
3//!
4//! The crate carries no provider SDKs, and no HTTP client unless the
5//! `http` feature is enabled (adapters enable it; adopters of the trait
6//! do not need to). Concrete adapters live in sibling crates
7//! (`turul-llm-ollama`, `turul-llm-openai`, etc.) so the trait stays
8//! cheap to depend on for callers who do not need a specific provider.
9//! The shared helpers are [`ChatResponseShape`] (decode a chat-style
10//! response) and, behind the `http` feature, `http::send_chat`; adopters
11//! do not need either.
12//!
13//! # The trait
14//!
15//! [`LlmClient`] exposes a single async operation: take a fully-rendered
16//! prompt plus an optional JSON Schema 2020-12 document describing the
17//! expected output shape, return a parsed JSON value that the caller can
18//! validate / consume.
19//!
20//! Callers are expected to:
21//!
22//! - Render the prompt themselves (e.g. via a manifest template engine).
23//!   The trait does not own the template surface — different callers
24//!   render prompts differently.
25//! - Supply the output schema when they need structured output. Adapters
26//!   pass it through to the provider's structured-output API and MUST
27//!   NOT loosen what the schema declares.
28//! - Validate the returned `parsed_output` against their schema. The
29//!   trait deliberately stops short of running validation itself so that
30//!   adopters can pick their preferred JSON Schema validator.
31//!
32//! # Object safety
33//!
34//! `LlmClient` is object-safe: callers that want to swap providers at
35//! runtime hold `Arc<dyn LlmClient>` and route based on configuration.
36//! The compile-time assertion lives in this crate's tests.
37
38pub mod client;
39pub mod decode;
40pub mod error;
41pub mod guard;
42#[cfg(feature = "http")]
43pub mod http;
44pub mod request;
45pub mod response;
46
47pub use client::LlmClient;
48pub use decode::ChatResponseShape;
49pub use error::LlmError;
50pub use guard::{GuardedClient, PromptCountPolicy, TokenCounter};
51pub use request::{CompletionRequest, ContextBudget, ExecutionHints};
52pub use response::{CompletionResponse, StopReason, Usage};