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, LcelStreamEvent, RetryConfig, RetryOn,
37 Runnable, RunnableAny, RunnableAnyWrapper, RunnableAssign, RunnableBinding, RunnableBranch,
38 RunnableConfig, RunnableExt, RunnableLambda, RunnableParallel, RunnablePassthrough,
39 RunnableRetry, RunnableSequence, RunnableWithFallbacks,
40};
41pub use structured_output::{
42 stream_structured_output, with_structured_output, PartialJsonError, PartialJsonParser,
43 StreamingStructuredOutputExt, StructuredOutputError, StructuredOutputExt,
44};
45pub use tools::{
46 BaseTool, FunctionCall, FunctionDefinition, StructuredOutput, Tool, ToolCall, ToolCallResult,
47 ToolDefinition, ToolError, ToolRegistry,
48};
49
50#[derive(Debug, thiserror::Error)]
55pub enum CoreError {
56 #[error("Tool error: {0}")]
58 Tool(#[from] ToolError),
59
60 #[error("JSON parse error: {0}")]
62 JsonParse(#[from] LlmJsonParseError),
63
64 #[error("Batch error: {0}")]
66 Batch(#[from] batch::BatchError),
67
68 #[error("Router error: {0}")]
70 Router(#[from] router_llm::RouterError),
71
72 #[error("Structured output error: {0}")]
74 StructuredOutput(#[from] StructuredOutputError),
75
76 #[error("Partial JSON error: {0}")]
78 PartialJson(#[from] PartialJsonError),
79
80 #[error("Output parser error: {0}")]
82 OutputParser(#[from] OutputParserError),
83
84 #[error("Math error: {0}")]
86 Math(#[from] math::MathError),
87
88 #[error("{0}")]
90 Other(String),
91}
92
93impl From<std::convert::Infallible> for CoreError {
95 fn from(_: std::convert::Infallible) -> Self {
96 unreachable!()
97 }
98}
99
100pub fn other_error<E: std::fmt::Display>(err: E) -> CoreError {
103 CoreError::Other(err.to_string())
104}
105
106impl From<CoreError> for runnables::LcelError {
108 fn from(err: CoreError) -> Self {
109 match &err {
110 CoreError::Tool(_) => runnables::LcelError::Tool(err.to_string()),
111 CoreError::JsonParse(_) => runnables::LcelError::Other(err.to_string()),
112 CoreError::Batch(_) => runnables::LcelError::Other(err.to_string()),
113 CoreError::Router(_) => runnables::LcelError::Other(err.to_string()),
114 CoreError::StructuredOutput(_) => runnables::LcelError::Other(err.to_string()),
115 CoreError::PartialJson(_) => runnables::LcelError::Other(err.to_string()),
116 CoreError::OutputParser(_) => runnables::LcelError::OutputParser(err.to_string()),
117 CoreError::Math(_) => runnables::LcelError::Other(err.to_string()),
118 CoreError::Other(_) => runnables::LcelError::Other(err.to_string()),
119 }
120 }
121}