Expand description
§Dioxus AI
AI hooks for Dioxus applications - chat, completions, and streaming.
§Features
use_chat- Reactive chat with message history and streaminguse_completion- Single completion requests- Built on
llm-clientfor provider support (OpenAI, Anthropic, OpenRouter)
§Example
ⓘ
use dioxus::prelude::*;
use dioxus_ai::{use_chat, ChatOptions};
#[component]
fn Chat() -> Element {
let mut chat = use_chat(ChatOptions {
provider: "openai".to_string(),
api_key: "sk-...".to_string(),
model: "gpt-4o-mini".to_string(),
..Default::default()
});
let mut input = use_signal(String::new);
rsx! {
div {
for msg in chat.messages().iter() {
p { class: "{msg.role}", "{msg.content}" }
}
if chat.is_loading() {
p { "Thinking..." }
}
input {
value: "{input}",
oninput: move |e| input.set(e.value().clone())
}
button {
onclick: move |_| {
chat.send(&input());
input.set(String::new());
},
"Send"
}
}
}
}Structs§
- Chat
Message - A message in the chat conversation
- Chat
Options - Options for the chat hook
- Completion
Options - Options for the completion hook
- UseChat
State - State for the chat hook
- UseCompletion
State - State for the completion hook
Enums§
- Dioxus
AiError - Errors that can occur in dioxus-ai
- Provider
- Supported LLM providers.
- Role
- Role in a conversation.
Functions§
- use_
chat - Create a reactive chat interface
- use_
completion - Create a completion interface