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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! # ai_assistant_core
//!
//! Simple, ergonomic Rust **client and server** for local LLMs.
//!
//! Connect to **Ollama**, **LM Studio**, or any **OpenAI-compatible** server
//! in a few lines of code. List models, chat, stream responses, and **serve
//! your local model** as an OpenAI-compatible API accessible remotely.
//!
//! ## Quick Start — Client
//!
//! ```rust,no_run
//! use ai_assistant_core::{ollama, Message};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), ai_assistant_core::Error> {
//! let provider = ollama();
//!
//! // List available models
//! let models = provider.models().await?;
//! println!("Models: {:?}", models.iter().map(|m| &m.name).collect::<Vec<_>>());
//!
//! // Simple chat
//! let reply = provider.chat("llama3.2:1b", "What is Rust?").await?;
//! println!("{reply}");
//!
//! // Chat with message history
//! let messages = vec![
//! Message::system("You are a helpful assistant."),
//! Message::user("Explain ownership in Rust in 2 sentences."),
//! ];
//! let reply = provider.send("llama3.2:1b", &messages).await?;
//! println!("{reply}");
//!
//! Ok(())
//! }
//! ```
//!
//! ## Streaming
//!
//! ```rust,no_run
//! use ai_assistant_core::ollama;
//! use futures::StreamExt;
//!
//! # async fn example() -> Result<(), ai_assistant_core::Error> {
//! let provider = ollama();
//! let mut stream = provider.chat_stream("llama3.2:1b", "Tell me a joke").await?;
//! while let Some(chunk) = stream.next().await {
//! print!("{}", chunk?);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Providers
//!
//! ```rust,no_run
//! use ai_assistant_core::{ollama, ollama_at, lm_studio, openai_compat};
//!
//! let o = ollama(); // localhost:11434
//! let o2 = ollama_at("http://192.168.1.50:11434"); // remote Ollama
//! let lm = lm_studio(); // localhost:1234
//! let custom = openai_compat("http://localhost:8080/v1"); // any OpenAI-compatible
//! ```
//!
//! ## Auto-detection
//!
//! ```rust,no_run
//! use ai_assistant_core::detect;
//!
//! # async fn example() -> Result<(), ai_assistant_core::Error> {
//! let providers = detect(&[]).await;
//! for p in &providers {
//! println!("{} at {} ({} models)", p.name, p.url, p.model_count);
//! }
//! if let Some(p) = providers.first() {
//! let reply = p.provider.chat(&p.models[0], "Hello!").await?;
//! println!("{reply}");
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Serve Your Model (feature `serve`)
//!
//! Expose your local LLM as an OpenAI-compatible API:
//!
//! ```rust,ignore
//! use ai_assistant_core::{ollama, serve};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), ai_assistant_core::Error> {
//! let provider = ollama();
//! serve::quick(provider).await?; // serves on :8090
//! Ok(())
//! }
//! ```
//!
//! With more control:
//!
//! ```rust,ignore
//! use ai_assistant_core::{ollama, ProviderServiceBuilder};
//!
//! # async fn example() -> Result<(), ai_assistant_core::Error> {
//! ProviderServiceBuilder::new(ollama())
//! .port(9090)
//! .token("my_secret")
//! .nat() // STUN + UPnP for remote access
//! .start().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Binary: `ai_serve`
//!
//! ```bash
//! cargo install ai_assistant_core --bin ai_serve --features serve
//! ai_serve # auto-detect + serve
//! ai_serve --nat --token secret # with remote access + auth
//! ```
//!
//! ## Need more?
//!
//! For advanced features (RAG, multi-agent, security, distributed clusters, MCP,
//! autonomous agents, and more), check out the full
//! [ai_assistant](https://github.com/OrlandoLuque/ai_assistant) suite.
pub use ;
pub use Error;
pub use Provider;
pub use ;
pub use ;
pub use ;
/// Create an Ollama provider pointing to `http://localhost:11434`.
/// Create an Ollama provider at a custom URL.
/// Create an LM Studio provider pointing to `http://localhost:1234/v1`.
/// Create a provider for any OpenAI-compatible API.