1mod 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#[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}