Documentation Index
Fetch the complete documentation index at: https://docs.trymirai.com/llms.txt
Use this file to discover all available pages before exploring further.
In this example, we will use a classification model to determine whether the user’s input is safe from a moderation perspective.
- Python
- Swift
- TypeScript
- Rust
Paste into main.py
import asyncio
from uzu import ClassificationMessage, Engine, EngineConfig
async def main() -> None:
engine_config = EngineConfig.create()
engine = await Engine.create(engine_config)
model = await engine.model("trymirai/chat-moderation-router")
if model is None:
raise RuntimeError("Model not found")
async for update in (await engine.download(model)).iterator():
print(f"Download progress: {update.progress}")
messages = [ClassificationMessage.user("Hi")]
session = await engine.classification(model)
output = await session.classify(messages)
print(f"Output: {output.probabilities.values}")
if __name__ == "__main__":
asyncio.run(main())
Paste the snippet
import Uzu
public func runClassification() async throws {
let engine = try await Engine.create(config: .create())
guard let model = try await engine.model(identifier: "trymirai/chat-moderation-router") else {
return
}
for try await update in try await engine.download(model: model).iterator() {
print("Download progress: \(update.progress())")
}
let messages = [
ClassificationMessage.user(content: "Hi")
]
let session = try await engine.classification(model: model)
let output = try await session.classify(input: messages)
print("Output: \(output.probabilities.values)")
}
Initialize a tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"types": [
"node"
]
},
"include": [
"*.ts"
]
}
Create main.ts
import { ClassificationMessage, Engine, EngineConfig } from '@trymirai/uzu';
async function main() {
let engineConfig = EngineConfig.create();
let engine = await Engine.create(engineConfig);
let model = await engine.model('trymirai/chat-moderation-router');
if (!model) {
throw new Error('Model not found');
}
for await (const update of await engine.download(model)) {
console.log('Download progress:', update.progress);
}
let messages = [
ClassificationMessage.user('Hi')
];
let session = await engine.classification(model);
let output = await session.classify(messages);
console.log('Output: ', output.probabilities.values);
}
main().catch((error) => {
console.error(error);
});
Install dependencies
cargo add uzu --git https://github.com/trymirai/uzu
cargo add tokio --features full
Paste into src/main.rs
use uzu::{
engine::{Engine, EngineConfig},
types::session::classification::ClassificationMessage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine_config = EngineConfig::default();
let engine = Engine::new(engine_config).await?;
let model = engine.model("trymirai/chat-moderation-router".to_string()).await?.ok_or("Model not found")?;
let downloader = engine.download(&model).await?;
while let Some(update) = downloader.next().await {
println!("Download progress: {}", update.progress());
}
let messages = vec![ClassificationMessage::user("Hi".to_string())];
let session = engine.classification(model).await?;
let output = session.classify(messages).await?;
println!("Output: {:?}", output.probabilities.values);
Ok(())
}
