miyabi_llm_core/
lib.rs

1//! Miyabi LLM Core - Unified LLM Interface for Rust
2//!
3//! This crate provides core traits and types for interacting with various LLM providers.
4//! It is designed to be provider-agnostic and serves as the foundation for provider-specific
5//! implementations (OpenAI, Anthropic, Google, etc.).
6//!
7//! # Features
8//!
9//! - **Unified Interface**: Single trait (`LlmClient`) for all providers
10//! - **Tool Calling**: First-class support for function/tool calling
11//! - **Streaming**: Optional streaming support via `LlmStreamingClient`
12//! - **Type Safety**: Strong typing for messages, roles, and tool definitions
13//! - **Async/Await**: Built on Tokio for efficient async operations
14//!
15//! # Example
16//!
17//! ```rust
18//! use miyabi_llm_core::{LlmClient, Message};
19//!
20//! async fn chat_example(client: impl LlmClient) -> Result<String, Box<dyn std::error::Error>> {
21//!     let messages = vec![
22//!         Message::system("You are a helpful assistant"),
23//!         Message::user("Hello!"),
24//!     ];
25//!
26//!     let response = client.chat(messages).await?;
27//!     Ok(response)
28//! }
29//! ```
30//!
31//! # Provider Implementations
32//!
33//! This crate defines the core interfaces. Actual provider implementations are in separate crates:
34//!
35//! - `miyabi-llm-openai` - OpenAI (GPT-4o, GPT-4 Turbo, o1)
36//! - `miyabi-llm-anthropic` - Anthropic (Claude 3.5 Sonnet, Opus)
37//! - `miyabi-llm-google` - Google (Gemini 1.5 Pro/Flash)
38//!
39//! # Architecture
40//!
41//! ```text
42//! miyabi-llm-core (this crate)
43//!     ├── LlmClient trait
44//!     ├── LlmStreamingClient trait
45//!     ├── Message, Role types
46//!     ├── ToolDefinition, ToolCall types
47//!     └── LlmError type
48//!         ↓ implements
49//!     ┌───────────────────────────────┐
50//!     │   Provider Implementations    │
51//!     ├───────────────────────────────┤
52//!     │ miyabi-llm-openai             │
53//!     │ miyabi-llm-anthropic          │
54//!     │ miyabi-llm-google             │
55//!     └───────────────────────────────┘
56//!         ↓ unified via
57//!     ┌───────────────────────────────┐
58//!     │   Integration Package         │
59//!     ├───────────────────────────────┤
60//!     │ miyabi-llm                    │
61//!     │ ├── HybridRouter              │
62//!     │ └── Feature flags             │
63//!     └───────────────────────────────┘
64//! ```
65
66pub mod client;
67pub mod error;
68pub mod message;
69pub mod streaming;
70pub mod tools;
71
72// Re-export main types
73pub use client::{LlmClient, ToolCallResponse};
74pub use error::{LlmError, Result};
75pub use message::{Message, Role};
76pub use streaming::{LlmStreamingClient, StreamEvent, StreamResponse};
77pub use tools::{ToolCall, ToolDefinition};