Skip to main content

dioxus_ai/
lib.rs

1//! # Dioxus AI
2//!
3//! AI hooks for Dioxus applications - chat, completions, and streaming.
4//!
5//! ## Features
6//!
7//! - `use_chat` - Reactive chat with message history and streaming
8//! - `use_completion` - Single completion requests
9//! - Built on `llm-client` for provider support (OpenAI, Anthropic, OpenRouter)
10//!
11//! ## Example
12//!
13//! ```rust,ignore
14//! use dioxus::prelude::*;
15//! use dioxus_ai::{use_chat, ChatOptions};
16//!
17//! #[component]
18//! fn Chat() -> Element {
19//!     let mut chat = use_chat(ChatOptions {
20//!         provider: "openai".to_string(),
21//!         api_key: "sk-...".to_string(),
22//!         model: "gpt-4o-mini".to_string(),
23//!         ..Default::default()
24//!     });
25//!
26//!     let mut input = use_signal(String::new);
27//!
28//!     rsx! {
29//!         div {
30//!             for msg in chat.messages().iter() {
31//!                 p { class: "{msg.role}", "{msg.content}" }
32//!             }
33//!
34//!             if chat.is_loading() {
35//!                 p { "Thinking..." }
36//!             }
37//!
38//!             input {
39//!                 value: "{input}",
40//!                 oninput: move |e| input.set(e.value().clone())
41//!             }
42//!             button {
43//!                 onclick: move |_| {
44//!                     chat.send(&input());
45//!                     input.set(String::new());
46//!                 },
47//!                 "Send"
48//!             }
49//!         }
50//!     }
51//! }
52//! ```
53
54mod error;
55mod hooks;
56mod types;
57
58pub use error::*;
59pub use hooks::*;
60pub use types::*;
61
62// Re-export useful types from llm-client
63pub use cortexai_llm_client::{Provider, Role};