graphrt_llm/lib.rs
1//! # graphrt-llm
2//!
3//! Model providers and model-calling nodes for graphrt.
4//!
5//! - [`ChatModel`]: provider-neutral streaming chat interface.
6//! - [`openai`] (feature `openai`): any OpenAI-compatible endpoint.
7//! - [`anthropic`] (feature `anthropic`): the Anthropic Messages API.
8//! - [`ModelRegistry`]: named providers, registered as a host service.
9//! - Nodes: `llm`, `question-classifier`, `parameter-extractor` and `agent`
10//! (a tool-calling loop over [`graphrt_core::tool::ToolRegistry`]).
11//!
12//! ```no_run
13//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
14//! let mut registry = graphrt_core::Registry::with_builtins();
15//! graphrt_llm::register(&mut registry);
16//! # #[cfg(feature = "http")]
17//! let models = graphrt_llm::ModelRegistry::from_env()?;
18//! # #[cfg(not(feature = "http"))]
19//! # let models = graphrt_llm::ModelRegistry::new();
20//! let services = graphrt_core::Services::new().with(models);
21//! # let _ = (registry, services);
22//! # Ok(())
23//! # }
24//! ```
25
26/// Keeping a conversation inside the model's context window (feature `context`).
27///
28/// Public only for the benchmark in `examples/context_bench.rs`, not a stable
29/// API: workflows use the `context_window` key of the `agent` and `llm` nodes.
30#[cfg(feature = "context")]
31#[doc(hidden)]
32pub mod context;
33pub mod credential_config;
34pub mod credentials;
35pub mod error;
36/// Scripted model for tests and offline examples (feature `mock`, on by default).
37#[cfg(any(test, feature = "mock"))]
38pub mod mock;
39pub mod nodes;
40pub mod providers;
41pub mod registry;
42/// Record / replay provider for deterministic runs (feature `replay`).
43#[cfg(feature = "replay")]
44pub mod replay;
45pub mod sse;
46/// Plain completions for work outside a run (feature `text-model`).
47#[cfg(feature = "text-model")]
48pub mod text_model;
49pub mod types;
50#[cfg(feature = "typesafe")]
51pub mod typesafe;
52
53#[cfg(feature = "http")]
54mod http;
55#[cfg(feature = "http")]
56pub use http::prewarm_http_client;
57
58#[cfg(feature = "anthropic")]
59pub mod anthropic;
60#[cfg(feature = "bedrock")]
61pub mod bedrock;
62#[cfg(feature = "gemini")]
63pub mod gemini;
64#[cfg(feature = "openai")]
65pub mod openai;
66
67pub use error::LlmError;
68pub use registry::ModelRegistry;
69pub use types::{
70 ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
71 Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
72};
73
74/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
75pub fn register(registry: &mut graphrt_core::Registry) {
76 registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
77 registry.register_lazily_described(
78 "question-classifier",
79 nodes::descriptors::question_classifier,
80 nodes::classifier::factory,
81 );
82 registry.register_lazily_described(
83 "parameter-extractor",
84 nodes::descriptors::parameter_extractor,
85 nodes::extractor::factory,
86 );
87 registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
88 #[cfg(feature = "typesafe")]
89 registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
90}