1pub mod batch;
13pub mod cache;
14pub mod json_parse;
15pub mod judge;
16pub mod language_models;
17pub mod math;
18pub mod output_parsers;
19pub mod router_llm;
20pub mod runnables;
21pub mod structured_output;
22pub mod token_counter;
23pub mod tools;
24
25pub use json_parse::{parse_llm_json, parse_llm_json_with_retry, LlmJsonParseError};
27
28pub use judge::{structured_call, truncate, StructuredJudgeError};
29
30pub use language_models::{BaseChatModel, BaseLanguageModel, MultimodalError, MultimodalModel};
31pub use output_parsers::{
32 BaseOutputParser, CommaSeparatedListOutputParser, JsonOutputParser, OutputParserError,
33 OutputParserResult, StrOutputParser, StructuredOutputParser, TypedOutputParser,
34};
35pub use runnables::{
36 into_runnable_any, CancellationToken, LcelError, RetryConfig, RetryOn, Runnable, RunnableAny,
37 RunnableAnyWrapper, RunnableAssign, RunnableBinding, RunnableBranch, RunnableConfig,
38 RunnableConfigurable, RunnableConfigurableFields, RunnableExt, RunnableLambda,
39 RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence,
40 RunnableWithFallbacks,
41};
42pub use structured_output::{
43 stream_structured_output, with_structured_output, PartialJsonError, PartialJsonParser,
44 StreamingStructuredOutputExt, StructuredOutputError, StructuredOutputExt,
45};
46pub use tools::{
47 BaseTool, FunctionCall, FunctionDefinition, StructuredOutput, Tool, ToolCall, ToolCallResult,
48 ToolDefinition, ToolError, ToolRegistry,
49};
50
51#[derive(Debug, thiserror::Error)]
56pub enum CoreError {
57 #[error("Tool error: {0}")]
59 Tool(#[from] ToolError),
60
61 #[error("JSON parse error: {0}")]
63 JsonParse(#[from] LlmJsonParseError),
64
65 #[error("Batch error: {0}")]
67 Batch(#[from] batch::BatchError),
68
69 #[error("Router error: {0}")]
71 Router(#[from] router_llm::RouterError),
72
73 #[error("Structured output error: {0}")]
75 StructuredOutput(#[from] StructuredOutputError),
76
77 #[error("Partial JSON error: {0}")]
79 PartialJson(#[from] PartialJsonError),
80
81 #[error("Output parser error: {0}")]
83 OutputParser(#[from] OutputParserError),
84
85 #[error("Math error: {0}")]
87 Math(#[from] math::MathError),
88
89 #[error("{0}")]
91 Other(String),
92}
93
94impl From<std::convert::Infallible> for CoreError {
96 fn from(_: std::convert::Infallible) -> Self {
97 unreachable!()
98 }
99}
100
101pub fn other_error<E: std::fmt::Display>(err: E) -> CoreError {
104 CoreError::Other(err.to_string())
105}
106
107impl From<CoreError> for runnables::LcelError {
109 fn from(err: CoreError) -> Self {
110 match &err {
111 CoreError::Tool(_) => runnables::LcelError::Tool(err.to_string()),
112 CoreError::JsonParse(_) => runnables::LcelError::Other(err.to_string()),
113 CoreError::Batch(_) => runnables::LcelError::Other(err.to_string()),
114 CoreError::Router(_) => runnables::LcelError::Other(err.to_string()),
115 CoreError::StructuredOutput(_) => runnables::LcelError::Other(err.to_string()),
116 CoreError::PartialJson(_) => runnables::LcelError::Other(err.to_string()),
117 CoreError::OutputParser(_) => runnables::LcelError::OutputParser(err.to_string()),
118 CoreError::Math(_) => runnables::LcelError::Other(err.to_string()),
119 CoreError::Other(_) => runnables::LcelError::Other(err.to_string()),
120 }
121 }
122}