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