ferriclink_core/
lib.rs

1//! # FerricLink Core
2//!
3//! Core abstractions for the FerricLink ecosystem, inspired by LangChain Core.
4//! This crate provides the fundamental building blocks for building AI applications
5//! with language models, tools, vector stores, and more.
6
7pub mod caches;
8pub mod callbacks;
9pub mod documents;
10pub mod embeddings;
11pub mod env;
12pub mod errors;
13pub mod example_selectors;
14pub mod globals;
15pub mod language_models;
16pub mod messages;
17pub mod rate_limiters;
18pub mod retrievers;
19pub mod runnables;
20pub mod serializable;
21pub mod structured_query;
22pub mod tools;
23pub mod utils;
24pub mod vectorstores;
25
26// Re-exports for convenience
27pub use caches::{BaseCache, CacheStats, CachedGenerations, InMemoryCache, TtlCache};
28pub use env::{RuntimeEnvironment, get_fresh_runtime_environment, get_runtime_environment};
29pub use errors::{
30    ErrorCode, FerricLinkError, IntoFerricLinkError, OutputParserException, Result,
31    TracerException, create_error_message,
32};
33pub use example_selectors::{
34    BaseExampleSelector, Example, LengthBasedExampleSelector, MaxMarginalRelevanceExampleSelector,
35    SemanticSimilarityExampleSelector, sorted_values,
36};
37pub use globals::{
38    clear_llm_cache, disable_debug, disable_verbose, enable_debug, enable_verbose, get_debug,
39    get_globals, get_verbose, globals_summary, has_llm_cache, init_globals, is_debug, is_verbose,
40    reset_globals, set_debug, set_llm_cache, set_verbose, toggle_debug, toggle_verbose,
41};
42pub use rate_limiters::{
43    AdvancedRateLimiter, BaseRateLimiter, InMemoryRateLimiter, InMemoryRateLimiterConfig,
44    RateLimiterConfig,
45};
46pub use serializable::Serializable;
47
48/// Version of the FerricLink Core crate
49pub const VERSION: &str = env!("CARGO_PKG_VERSION");
50
51/// Initialize the FerricLink Core crate
52///
53/// This function should be called early in your application to set up
54/// logging and other global configurations.
55pub fn init() -> Result<()> {
56    // Initialize global configuration
57    init_globals()?;
58
59    #[cfg(not(docsrs))]
60    {
61        tracing_subscriber::fmt::init();
62    }
63    Ok(())
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_version() {
72        // VERSION is a const string that can never be empty, so we just check it's not the default
73        assert_ne!(VERSION, "", "Version should not be empty");
74    }
75
76    #[test]
77    fn test_init() {
78        // This test may fail if globals are already initialized
79        // from other tests, which is expected behavior
80        let result = init();
81        if result.is_err() {
82            println!("Init failed (expected if globals already initialized): {result:?}",);
83        }
84        // We don't assert success here because globals can only be initialized once
85    }
86}