#![warn(missing_docs)]
pub mod batch;
pub mod cache;
pub mod json_parse;
pub mod judge;
pub mod language_models;
pub mod math;
pub mod output_parsers;
pub mod router_llm;
pub mod runnables;
pub mod ssrf;
pub mod structured_output;
pub mod token_counter;
pub mod tools;
pub use json_parse::{parse_llm_json, parse_llm_json_with_retry, LlmJsonParseError};
pub use judge::{structured_call, truncate, StructuredJudgeError};
pub use language_models::{
predict_tools, BaseChatModel, BaseLanguageModel, MultimodalError, MultimodalModel,
PredictToolsError, StreamChunk, TokenUsage,
};
pub use output_parsers::{
BaseOutputParser, CommaSeparatedListOutputParser, JsonOutputParser, OutputParserError,
OutputParserResult, StrOutputParser, StructuredOutputParser, TypedOutputParser,
};
pub use runnables::{
into_runnable_any, CancellationToken, LcelError, RetryConfig, RetryOn, Runnable, RunnableAny,
RunnableAnyWrapper, RunnableAssign, RunnableBinding, RunnableBranch, RunnableConfig,
RunnableConfigurable, RunnableConfigurableFields, RunnableExt, RunnableLambda,
RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence,
RunnableWithFallbacks,
};
pub use structured_output::{
stream_structured_output, with_structured_output, PartialJsonError, PartialJsonParser,
StreamingStructuredOutputExt, StructuredOutputError, StructuredOutputExt,
};
pub use tools::{
BaseTool, FunctionCall, FunctionDefinition, StructuredOutput, Tool, ToolCall, ToolCallBuilder,
ToolCallResult, ToolDefinition, ToolError, ToolRegistry,
};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum CoreError {
#[error("Tool error: {0}")]
Tool(#[from] ToolError),
#[error("JSON parse error: {0}")]
JsonParse(#[from] LlmJsonParseError),
#[error("Batch error: {0}")]
Batch(#[from] batch::BatchError),
#[error("Router error: {0}")]
Router(#[from] router_llm::RouterError),
#[error("Structured output error: {0}")]
StructuredOutput(#[from] StructuredOutputError),
#[error("Partial JSON error: {0}")]
PartialJson(#[from] PartialJsonError),
#[error("Output parser error: {0}")]
OutputParser(#[from] OutputParserError),
#[error("Math error: {0}")]
Math(#[from] math::MathError),
#[error("Token counting error: {0}")]
TokenCount(#[from] token_counter::TokenCounterError),
#[error("{0}")]
Other(String),
}
impl From<std::convert::Infallible> for CoreError {
fn from(_: std::convert::Infallible) -> Self {
unreachable!()
}
}
pub fn other_error<E: std::fmt::Display>(err: E) -> CoreError {
CoreError::Other(err.to_string())
}
impl From<CoreError> for runnables::LcelError {
fn from(err: CoreError) -> Self {
match &err {
CoreError::Tool(_) => runnables::LcelError::Tool(err.to_string()),
CoreError::JsonParse(_) => runnables::LcelError::Other(err.to_string()),
CoreError::Batch(_) => runnables::LcelError::Other(err.to_string()),
CoreError::Router(_) => runnables::LcelError::Other(err.to_string()),
CoreError::StructuredOutput(_) => runnables::LcelError::Other(err.to_string()),
CoreError::PartialJson(_) => runnables::LcelError::Other(err.to_string()),
CoreError::OutputParser(_) => runnables::LcelError::OutputParser(err.to_string()),
CoreError::Math(_) => runnables::LcelError::Other(err.to_string()),
CoreError::TokenCount(_) => runnables::LcelError::Other(err.to_string()),
CoreError::Other(_) => runnables::LcelError::Other(err.to_string()),
}
}
}