Expand description
cetai-bevy — a Bevy plugin for
cetai, running typed prompt! AI calls from Bevy
systems on native and wasm32-unknown-unknown.
The crate provides three pieces:
BevyTransport, a cetaiTransportbuilt onehttp(ureq + rustls on native,fetchon wasm) andwasm-timer;CetaiPlugin, which installs that transport into the global cetai configuration and registers a per-frame system draining finished AI results back onto the main thread;Cetai, a system param whoseaskmethod runs an AI future onbevy_tasks::IoTaskPooland applies a callback to theWorldwhen it finishes.
§Example
use bevy_app::{App, Startup};
use cetai::prompt;
use cetai_bevy::{Cetai, CetaiPlugin};
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct NpcLine {
text: String,
}
fn ask_blacksmith(ai: Cetai) {
let mood = "grumpy";
// The output type is inferred from the callback's parameter annotation.
ai.ask(
prompt!("Describe a {mood} blacksmith in one sentence"),
|_world, result: cetai::Result<NpcLine>| {
match result {
Ok(line) => println!("blacksmith: {}", line.text),
Err(err) => eprintln!("AI call failed: {err}"),
}
},
);
}
fn main() {
App::new()
.add_plugins(CetaiPlugin::new())
.add_systems(Startup, ask_blacksmith)
.run();
}§WASM notes
Everything compiles for wasm32-unknown-unknown: requests go through the
browser’s fetch (subject to CORS, and only CORS-exposed response headers
are visible), timers through setTimeout, and tasks through bevy’s
web-task based task pools. Note that a DEEPSEEK_API_KEY baked into a
shipped web build is visible to every player — prefer routing requests
through your own backend via AiConfig::base_url.
Structs§
- Bevy
Transport - HTTP transport backed by
ehttp, usable on native andwasm32-unknown-unknown. - Cetai
- System param starting cetai AI calls from any Bevy system.
- Cetai
Plugin - Bevy plugin wiring cetai into a Bevy app.