mem0_rust/llms/
mod.rs

1//! LLM providers for mem0-rust.
2//!
3//! This module provides various LLM backends for fact extraction:
4//! - OpenAI (GPT-4o, GPT-4o-mini)
5//! - Ollama (local models)
6//! - Anthropic (Claude)
7
8mod traits;
9
10pub use traits::{generate_json, GenerateOptions, LLM};
11
12#[cfg(feature = "openai")]
13mod openai;
14#[cfg(feature = "openai")]
15pub use openai::OpenAILLM;
16
17#[cfg(feature = "ollama")]
18mod ollama;
19#[cfg(feature = "ollama")]
20pub use ollama::OllamaLLM;
21
22#[cfg(feature = "anthropic")]
23mod anthropic;
24#[cfg(feature = "anthropic")]
25pub use anthropic::AnthropicLLM;
26
27use crate::config::LLMConfig;
28use crate::errors::LLMError;
29use std::sync::Arc;
30
31/// Create an LLM from configuration
32#[allow(unused_variables)]
33pub fn create_llm(config: &LLMConfig) -> Result<Arc<dyn LLM>, LLMError> {
34    #[cfg(feature = "openai")]
35    if let LLMConfig::OpenAI(cfg) = config {
36        return Ok(Arc::new(OpenAILLM::new(cfg.clone())?));
37    }
38
39    #[cfg(feature = "ollama")]
40    if let LLMConfig::Ollama(cfg) = config {
41        return Ok(Arc::new(OllamaLLM::new(cfg.clone())));
42    }
43
44    #[cfg(feature = "anthropic")]
45    if let LLMConfig::Anthropic(cfg) = config {
46        return Ok(Arc::new(AnthropicLLM::new(cfg.clone())?));
47    }
48
49    Err(LLMError::NotConfigured)
50}