Skip to main content

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
26pub mod credential_config;
27pub mod credentials;
28pub mod error;
29/// Scripted model for tests and offline examples (feature `mock`, on by default).
30#[cfg(any(test, feature = "mock"))]
31pub mod mock;
32pub mod nodes;
33pub mod providers;
34pub mod registry;
35/// Record / replay provider for deterministic runs (feature `replay`).
36#[cfg(feature = "replay")]
37pub mod replay;
38pub mod sse;
39pub mod types;
40#[cfg(feature = "typesafe")]
41pub mod typesafe;
42
43#[cfg(feature = "http")]
44mod http;
45
46#[cfg(feature = "anthropic")]
47pub mod anthropic;
48#[cfg(feature = "bedrock")]
49pub mod bedrock;
50#[cfg(feature = "gemini")]
51pub mod gemini;
52#[cfg(feature = "openai")]
53pub mod openai;
54
55pub use error::LlmError;
56pub use registry::ModelRegistry;
57pub use types::{
58    ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
59    Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
60};
61
62/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
63pub fn register(registry: &mut graphrt_core::Registry) {
64    registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
65    registry.register_lazily_described(
66        "question-classifier",
67        nodes::descriptors::question_classifier,
68        nodes::classifier::factory,
69    );
70    registry.register_lazily_described(
71        "parameter-extractor",
72        nodes::descriptors::parameter_extractor,
73        nodes::extractor::factory,
74    );
75    registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
76    #[cfg(feature = "typesafe")]
77    registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
78}