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};
28pub use output_parsers::{
29 BaseOutputParser, CommaSeparatedListOutputParser, JsonOutputParser, OutputParserError,
30 OutputParserResult, StrOutputParser, StructuredOutputParser, TypedOutputParser,
31};
32pub use runnables::{
33 into_runnable_any, LcelError, LcelStreamEvent, Runnable, RunnableAny, RunnableAnyWrapper,
34 RunnableBinding, RunnableBranch, RunnableConfig, RunnableExt, RunnableLambda, RunnableParallel,
35 RunnablePassthrough, RunnableSequence,
36};
37pub use structured_output::{
38 stream_structured_output, with_structured_output, PartialJsonError, PartialJsonParser,
39 StreamingStructuredOutputExt, StructuredOutputError, StructuredOutputExt,
40};
41pub use tools::{
42 BaseTool, FunctionCall, FunctionDefinition, StructuredOutput, Tool, ToolCall, ToolCallResult,
43 ToolDefinition, ToolError, ToolRegistry,
44};
45
46#[derive(Debug, thiserror::Error)]
51pub enum CoreError {
52 #[error("Tool error: {0}")]
54 Tool(#[from] ToolError),
55
56 #[error("JSON parse error: {0}")]
58 JsonParse(#[from] LlmJsonParseError),
59
60 #[error("Batch error: {0}")]
62 Batch(#[from] batch::BatchError),
63
64 #[error("Router error: {0}")]
66 Router(#[from] router_llm::RouterError),
67
68 #[error("Structured output error: {0}")]
70 StructuredOutput(#[from] StructuredOutputError),
71
72 #[error("Partial JSON error: {0}")]
74 PartialJson(#[from] PartialJsonError),
75
76 #[error("Output parser error: {0}")]
78 OutputParser(#[from] OutputParserError),
79
80 #[error("Math error: {0}")]
82 Math(#[from] math::MathError),
83
84 #[error("{0}")]
86 Other(String),
87}
88
89impl From<std::convert::Infallible> for CoreError {
91 fn from(_: std::convert::Infallible) -> Self {
92 unreachable!()
93 }
94}
95
96pub fn other_error<E: std::fmt::Display>(err: E) -> CoreError {
99 CoreError::Other(err.to_string())
100}
101
102impl From<CoreError> for runnables::LcelError {
104 fn from(err: CoreError) -> Self {
105 match &err {
106 CoreError::Tool(_) => runnables::LcelError::Tool(err.to_string()),
107 CoreError::JsonParse(_) => runnables::LcelError::Other(err.to_string()),
108 CoreError::Batch(_) => runnables::LcelError::Other(err.to_string()),
109 CoreError::Router(_) => runnables::LcelError::Other(err.to_string()),
110 CoreError::StructuredOutput(_) => runnables::LcelError::Other(err.to_string()),
111 CoreError::PartialJson(_) => runnables::LcelError::Other(err.to_string()),
112 CoreError::OutputParser(_) => runnables::LcelError::OutputParser(err.to_string()),
113 CoreError::Math(_) => runnables::LcelError::Other(err.to_string()),
114 CoreError::Other(_) => runnables::LcelError::Other(err.to_string()),
115 }
116 }
117}