af_llm/lib.rs
1//! `af-llm` — unified async LLM access for the Agent Factory platform.
2//!
3//! Provider-neutral model transport and request types. Provides:
4//!
5//! - [`LlmClient`] — async chat completions against any OpenAI-compatible
6//! endpoint, with a hard per-request timeout and a shared
7//! [`CircuitBreaker`].
8//! - Strongly-typed request/response models ([`CompletionRequest`],
9//! [`CompletionResponse`], [`ChatMessage`], [`Tool`], …) — the Pydantic
10//! equivalent, validated at the wire boundary.
11//! - [`parse_json`] — pull structured output out of fenced LLM text into any
12//! `serde` type.
13//!
14//! # Example
15//!
16//! ```no_run
17//! use af_llm::{LlmClient, LlmConfig, CompletionRequest, ChatMessage};
18//!
19//! # async fn run() -> af_llm::Result<()> {
20//! let client = LlmClient::new(LlmConfig::new("http://localhost:4000/v1", ""))?;
21//! let req = CompletionRequest::new(
22//! "deepseek/deepseek-chat",
23//! vec![ChatMessage::user("Say hi in one word.")],
24//! );
25//! let resp = client.complete_stream_single_attempt(&req, |_, _| {}).await?;
26//! println!("{:?}", resp.first_content());
27//! # Ok(())
28//! # }
29//! ```
30
31#![deny(missing_docs)]
32#![deny(rustdoc::broken_intra_doc_links)]
33
34pub mod circuit_breaker;
35pub mod client;
36pub mod error;
37/// Governed binary resource resolution at the provider boundary.
38pub mod images;
39pub mod json;
40pub mod stream;
41pub mod types;
42
43pub use circuit_breaker::{CircuitBreaker, State as CircuitState, Status as CircuitStatus};
44pub use client::{LlmClient, LlmConfig, DEFAULT_TIMEOUT};
45pub use error::{LlmError, Result};
46pub use json::{parse_json, strip_code_fence};
47pub use stream::StreamDelta;
48pub use types::{
49 AssistantBlock, ChatMessage, Choice, CompletionRequest, CompletionResponse, FinishReason,
50 FunctionCall, FunctionDef, InputImage, ReasoningEffort, Role, StreamOptions, Tool, ToolCall,
51 ToolChoice, Usage,
52};