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