1#![warn(missing_docs)]
2pub mod batch;
14pub mod cache;
15pub mod cost;
16pub mod json_parse;
17pub mod judge;
18pub mod language_models;
19pub mod math;
20pub mod model_registry;
21pub mod observability;
22pub mod output_parsers;
23pub mod router_llm;
24pub mod runnables;
25pub mod ssrf;
26pub mod structured_output;
27pub mod text;
28pub mod token_counter;
29pub mod tools;
30
31pub use cost::{
33 CostError, CostRecord, CostReport, CostTracker, ModelPrice, ModelSpend, PricingTable,
34};
35pub use json_parse::{parse_llm_json, parse_llm_json_with_retry, LlmJsonParseError};
36pub use model_registry::{ModelCapabilities, ModelInfo, ModelRegistry};
37
38pub use judge::{structured_call, truncate, StructuredJudgeError};
39
40pub use language_models::{
41 predict_tools, BaseChatModel, BaseLanguageModel, MultimodalError, MultimodalModel,
42 PredictToolsError, StreamChunk, TokenUsage,
43};
44pub use output_parsers::{
45 BaseOutputParser, CommaSeparatedListOutputParser, JsonOutputParser, OutputParserError,
46 OutputParserResult, StrOutputParser, StructuredOutputParser, TypedOutputParser,
47};
48pub use runnables::{
49 into_runnable_any, CancellationToken, LcelError, RetryConfig, RetryOn, Runnable, RunnableAny,
50 RunnableAnyWrapper, RunnableAssign, RunnableBinding, RunnableBranch, RunnableConfig,
51 RunnableConfigurable, RunnableConfigurableFields, RunnableExt, RunnableLambda,
52 RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence,
53 RunnableWithFallbacks,
54};
55pub use structured_output::{
56 stream_structured_output, with_structured_output, PartialJsonError, PartialJsonParser,
57 StreamingStructuredOutputExt, StructuredOutputError, StructuredOutputExt,
58};
59pub use tools::{
60 BaseTool, FunctionCall, FunctionDefinition, StructuredOutput, Tool, ToolCall, ToolCallBuilder,
61 ToolCallResult, ToolDefinition, ToolError, ToolRegistry,
62};
63
64#[derive(Debug, thiserror::Error)]
69#[non_exhaustive]
70pub enum CoreError {
71 #[error("Tool error: {0}")]
73 Tool(#[from] ToolError),
74
75 #[error("JSON parse error: {0}")]
77 JsonParse(#[from] LlmJsonParseError),
78
79 #[error("Batch error: {0}")]
81 Batch(#[from] batch::BatchError),
82
83 #[error("Router error: {0}")]
85 Router(#[from] router_llm::RouterError),
86
87 #[error("Structured output error: {0}")]
89 StructuredOutput(#[from] StructuredOutputError),
90
91 #[error("Partial JSON error: {0}")]
93 PartialJson(#[from] PartialJsonError),
94
95 #[error("Output parser error: {0}")]
97 OutputParser(#[from] OutputParserError),
98
99 #[error("Math error: {0}")]
101 Math(#[from] math::MathError),
102
103 #[error("Token counting error: {0}")]
105 TokenCount(#[from] token_counter::TokenCounterError),
106
107 #[error("{0}")]
109 Other(String),
110}
111
112impl From<std::convert::Infallible> for CoreError {
114 fn from(_: std::convert::Infallible) -> Self {
115 unreachable!()
116 }
117}
118
119pub fn other_error<E: std::fmt::Display>(err: E) -> CoreError {
122 CoreError::Other(err.to_string())
123}
124
125impl From<CoreError> for runnables::LcelError {
127 fn from(err: CoreError) -> Self {
128 match &err {
129 CoreError::Tool(_) => runnables::LcelError::Tool(err.to_string()),
130 CoreError::JsonParse(_) => runnables::LcelError::Other(err.to_string()),
131 CoreError::Batch(_) => runnables::LcelError::Other(err.to_string()),
132 CoreError::Router(_) => runnables::LcelError::Other(err.to_string()),
133 CoreError::StructuredOutput(_) => runnables::LcelError::Other(err.to_string()),
134 CoreError::PartialJson(_) => runnables::LcelError::Other(err.to_string()),
135 CoreError::OutputParser(_) => runnables::LcelError::OutputParser(err.to_string()),
136 CoreError::Math(_) => runnables::LcelError::Other(err.to_string()),
137 CoreError::TokenCount(_) => runnables::LcelError::Other(err.to_string()),
138 CoreError::Other(_) => runnables::LcelError::Other(err.to_string()),
139 }
140 }
141}