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