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;
35pub mod sse;
36pub mod types;
37#[cfg(feature = "typesafe")]
38pub mod typesafe;
39
40#[cfg(feature = "http")]
41mod http;
42
43#[cfg(feature = "anthropic")]
44pub mod anthropic;
45#[cfg(feature = "bedrock")]
46pub mod bedrock;
47#[cfg(feature = "gemini")]
48pub mod gemini;
49#[cfg(feature = "openai")]
50pub mod openai;
51
52pub use error::LlmError;
53pub use registry::ModelRegistry;
54pub use types::{
55    ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
56    Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
57};
58
59/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
60pub fn register(registry: &mut graphrt_core::Registry) {
61    registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
62    registry.register_lazily_described(
63        "question-classifier",
64        nodes::descriptors::question_classifier,
65        nodes::classifier::factory,
66    );
67    registry.register_lazily_described(
68        "parameter-extractor",
69        nodes::descriptors::parameter_extractor,
70        nodes::extractor::factory,
71    );
72    registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
73    #[cfg(feature = "typesafe")]
74    registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
75}