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