1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! LLM abstraction layer for Cognee.
//!
//! Provides async trait-based abstractions for Large Language Model interactions,
//! with support for structured output generation (inspired by Python's Instructor).
//!
//! # Features
//!
//! - **Async-first**: All operations are async, supporting both API calls and local inference
//! - **Structured outputs**: Generate type-safe structured data (e.g., knowledge graphs) from text
//! - **Provider-agnostic**: Trait-based design supports OpenAI, Anthropic, Ollama, local models, etc.
//! - **Configuration**: Flexible configuration with sensible defaults
//!
//! # Retry Logic
//!
//! This crate does not include built-in retry logic in the trait. Instead, use the
//! generic `retry_with_backoff` utility from `cognee-utils`:
//!
//! ```ignore
//! use cognee_llm::{Llm, LlmConfig, LlmProvider, LlmError};
//! use cognee_utils::retry::{retry_with_backoff, RetryConfig, RetryDecision};
//! use schemars::JsonSchema;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Serialize, Deserialize, JsonSchema)]
//! struct ExtractedData {
//! entities: Vec<String>,
//! relationships: Vec<(String, String, String)>,
//! }
//!
//! let config = LlmConfig::new(LlmProvider::OpenAI, "gpt-4")
//! .with_api_key("sk-...")
//! .with_temperature(0.0);
//!
//! let llm: Box<dyn Llm> = create_llm(config)?;
//!
//! // With retry logic
//! let retry_config = RetryConfig::new(3, 100, 5000);
//! let data: ExtractedData = retry_with_backoff(
//! retry_config,
//! || llm.create_structured_output(
//! "Alice told Bob to bring the documents.",
//! "Extract entities and relationships from the text.",
//! None,
//! ),
//! |error| match error {
//! LlmError::NetworkError(_) | LlmError::RateLimitExceeded(_) => RetryDecision::Retry,
//! LlmError::ContentPolicyViolation(_) | LlmError::AuthenticationError(_) => RetryDecision::Abort,
//! _ => RetryDecision::Retry,
//! },
//! ).await?;
//! ```
pub use OpenAIAdapter;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;