A high-performance inference engine for AI models
Examples update (#671)
Aleksandr Golokoz50532cb55f5e
diff --git a/README.md b/README.mdindex f916337f1..1a47b1df3 100644--- a/README.md+++ b/README.md@@ -34,6 +34,8 @@ uzu = { git = "https://github.com/trymirai/uzu", branch = "main", package = "uzuRun the code below:```rust+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},types::session::chat::{ChatConfig, ChatMessage, ChatReplyConfig},@@ -44,11 +46,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let session = engine.chat(model, ChatConfig::default()).await?;@@ -93,12 +97,13 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:returnasync for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()session = await engine.chat(model, ChatConfig.create())@@ -139,19 +144,22 @@ dependencies: [Run the code below:```swift+import Foundationimport Uzupublic func runQuickStart() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let session = try await engine.chat(model: model, config: .create())@@ -193,14 +201,15 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let session = await engine.chat(model, ChatConfig.create());@@ -232,7 +241,7 @@ Everything from model downloading to inference configuration is handled automati## Examples-You can run any example via `cargo tools example` \<**rust** | **python** | **swift** | **typescript**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start**\>:+You can run any example via `cargo tools example` \<**rust** | **python** | **swift** | **typescript**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:### Chat@@ -242,6 +251,8 @@ In this example, we will download a model and get a reply to a specific list of<summary>Rust</summary>```rust+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},session::chat::ChatSessionStreamChunk,@@ -253,11 +264,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let messages = vec![ChatMessage::system().with_text("You are a helpful assistant".to_string()),@@ -314,11 +327,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ChatMessage.system().with_text("You are a helpful assistant"),@@ -351,18 +365,21 @@ if __name__ == "__main__":<summary>Swift</summary>```swift+import Foundationimport Uzupublic func runChat() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withText(text: "You are a helpful assistant"),@@ -392,19 +409,28 @@ public func runChat() async throws {<summary>TypeScript</summary>```ts-import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSessionStreamChunkError, ChatSessionStreamChunkReplies, Engine, EngineConfig } from '@trymirai/uzu';+import {+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ ChatSessionStreamChunkError,+ ChatSessionStreamChunkReplies,+ Engine,+ EngineConfig+} from '@trymirai/uzu';async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ChatMessage.system().withText('You are a helpful assistant'),@@ -488,7 +514,6 @@ from uzu import ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig,async def main() -> None:engine_config = EngineConfig.create().with_openai_api_key("OPENAI_API_KEY")engine = await Engine.create(engine_config)-model = await engine.model("gpt-5")if model is None:raise RuntimeError("Model not found")@@ -522,7 +547,7 @@ public func runChatCloud() async throws {let engineConfig = EngineConfig.create().withOpenaiApiKey(openaiApiKey: "OPENAI_API_KEY")let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "gpt-5") else {return}@@ -589,6 +614,8 @@ Sometimes you want the generated output to be valid JSON with predefined fields.<summary>Rust</summary>```rust+use std::io::{self, Write};+use schemars::{JsonSchema, schema_for};use serde::{Deserialize, Serialize};use uzu::{@@ -615,11 +642,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let schema_string = serde_json::to_string(&schema_for!(CountryList))?;let messages = vec![@@ -687,11 +716,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()schema_string = json.dumps(CountryList.model_json_schema())messages = [@@ -721,6 +751,7 @@ if __name__ == "__main__":<summary>Swift</summary>```swift+import Foundationimport FoundationModelsimport Uzu@@ -734,12 +765,14 @@ public func runChatStructuredOutput() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withReasoningEffort(reasoningEffort: .disabled),@@ -786,13 +819,14 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let schema = z.toJSONSchema(CountryListType);let schemaString = JSON.stringify(schema);@@ -824,6 +858,8 @@ In this example, we will use a classification model to determine whether the use<summary>Rust</summary>```rust+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},types::session::classification::ClassificationMessage,@@ -837,8 +873,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let messages = vec![ClassificationMessage::user("Hi".to_string())];@@ -869,7 +907,8 @@ async def main() -> None:if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ClassificationMessage.user("Hi")]@@ -888,6 +927,7 @@ if __name__ == "__main__":<summary>Swift</summary>```swift+import Foundationimport Uzupublic func runClassification() async throws {@@ -897,8 +937,10 @@ public func runClassification() async throws {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ClassificationMessage.user(content: "Hi")@@ -927,8 +969,9 @@ async function main() {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ClassificationMessage.user('Hi')@@ -947,6 +990,342 @@ main().catch((error) => {</details>+### Tool calls++This example shows how to use external tools:++<details>+<summary>Rust</summary>++```rust+use std::io::{self, Write};++use nagare::tool::{func_def::ErrorFuture, uzu_tool_closure, uzu_tool_function};+use schemars::JsonSchema;+use serde::{Deserialize, Serialize};+use shoji::types::{+ basic::{SamplingMethod, SamplingPolicy},+ session::chat::{ChatConfig, ChatMessage, ChatReplyConfig},+};+use uzu::engine::{Engine, EngineConfig};++/// A geographic coordinate.+#[derive(Serialize, Deserialize, JsonSchema)]+struct Coordinate {+ /// Latitude in decimal degrees.+ latitude: f64,+ /// Longitude in decimal degrees.+ longitude: f64,+}++/// Returns current location in coordinates+#[uzu_tool_function]+fn get_current_location() -> Result<Coordinate, ErrorFuture> {+ Ok(Coordinate {+ latitude: 51.5074,+ longitude: -0.1278,+ })+}++#[tokio::main]+async fn main() -> Result<(), Box<dyn std::error::Error>> {+ let engine = Engine::new(EngineConfig::default()).await?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".to_string()).await?.ok_or("Model not found")?;+ let downloader = engine.download(&model).await?;+ while let Some(update) = downloader.next().await {+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;+ }+ println!();++ let mut session = engine.chat(model, ChatConfig::default()).await?;+ session.add_tool(get_current_location).await?;+ session+ .add_tool(uzu_tool_closure! {+ /// Returns temperature in provided location+ get_current_temperature: |+ /// Latitude in decimal degrees.+ _latitude: f64,+ /// Longitude in decimal degrees.+ _longitude: f64+ | -> Result<f64, ErrorFuture> {+ Ok(25.0)+ }+ })+ .await?;++ let messages = vec![+ ChatMessage::system().with_text("You are a helpful assistant".to_string()),+ ChatMessage::user().with_text("What temperature is it now at my location?".to_string()),+ ];++ let config = ChatReplyConfig {+ sampling_policy: SamplingPolicy::Custom {+ method: SamplingMethod::Greedy {},+ },+ ..ChatReplyConfig::default()+ };+ let replies = session.reply(messages.clone(), config).await?;+ if let Some(reply) = replies.last() {+ println!("Reasoning: {}", reply.message.reasoning().unwrap_or_default());+ println!("Text: {}", reply.message.text().unwrap_or_default());+ }++ Ok(())+}+```++</details>++<details>+<summary>Python</summary>++```python+import asyncio+from typing import Annotated++from pydantic import BaseModel++from uzu import (+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ Engine,+ EngineConfig,+ SamplingMethod,+ SamplingPolicy,+ uzu_tool_function,+)+++class Coordinate(BaseModel):+ """A geographic coordinate.++ Attributes:+ latitude: Latitude in decimal degrees.+ longitude: Longitude in decimal degrees.+ """++ latitude: float+ longitude: Annotated[float, "Longitude in decimal degrees."]+++@uzu_tool_function(name="get_location", description="Return the current location in coordinates")+def get_current_location() -> Coordinate:+ return Coordinate(latitude=51.5074, longitude=-0.1278)+++@uzu_tool_function+def get_current_temperature(+ latitude: float,+ longitude: Annotated[float, "Longitude in decimal degrees."],+) -> float:+ """Return the temperature at the provided coordinates.++ Args:+ latitude: Latitude in decimal degrees.+ longitude: This is overridden by the Annotated description.+ """+ _ = latitude, longitude+ return 25.0+++async def main() -> None:+ engine = await Engine.create(EngineConfig.create())+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")+ if model is None:+ raise RuntimeError("Model not found")+ async for update in (await engine.download(model)).iterator():+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()++ session = await engine.chat(model, ChatConfig.create())+ await session.add_tool(get_current_location)+ await session.add_tool(get_current_temperature)++ messages = [+ ChatMessage.system().with_text("You are a helpful assistant"),+ ChatMessage.user().with_text("What temperature is it now at my location?"),+ ]+ config = ChatReplyConfig.create().with_sampling_policy(SamplingPolicy.Custom(method=SamplingMethod.Greedy()))+ replies = await session.reply(messages, config)+ if replies:+ message = replies[-1].message+ print(f"Reasoning: {message.reasoning or ''}")+ print(f"Text: {message.text or ''}")+++if __name__ == "__main__":+ asyncio.run(main())+```++</details>++<details>+<summary>Swift</summary>++```swift+import Foundation+import FoundationModels+import Uzu++@Generable+private struct Coordinate: Codable, Sendable {+ @Guide(description: "Latitude in decimal degrees.")+ let latitude: Double++ @Guide(description: "Longitude in decimal degrees.")+ let longitude: Double+}++private struct GetCurrentLocation: Tool {+ let description = "Returns current location in coordinates"++ @Generable+ struct Arguments {+ }++ func call(arguments: Arguments) async throws -> Coordinate {+ Coordinate(latitude: 51.5074, longitude: -0.1278)+ }+}++private struct GetCurrentTemperature: Tool {+ let description = "Returns temperature in provided location"++ func call(arguments: Coordinate) async throws -> Double {+ _ = arguments+ return 25.0+ }+}++public func runToolCalls() async throws {+ let engine = try await Engine.create(config: .create())+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {+ throw ToolCallsExampleError.modelNotFound+ }+ for try await update in try await engine.download(model: model).iterator() {+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)+ }+ print()++ let session = try await engine.chat(model: model, config: .create())+ try await session.addTool(GetCurrentLocation())+ try await session.addTool(GetCurrentTemperature())++ let messages = [+ ChatMessage.system().withText(text: "You are a helpful assistant"),+ ChatMessage.user().withText(text: "What temperature is it now at my location?"),+ ]+ let reply_config = ChatReplyConfig.create().withSamplingMethod(samplingMethod: .greedy)+ let replies = try await session.reply(input: messages, config: reply_config)+ guard let message = replies.last?.message else {+ return+ }++ print("Reasoning: \(message.reasoning() ?? "")")+ print("Text: \(message.text() ?? "")")+}++private enum ToolCallsExampleError: Swift.Error {+ case modelNotFound+}+```++</details>++<details>+<summary>TypeScript</summary>++```ts+import {+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ Engine,+ EngineConfig,+ SamplingMethodGreedy,+ SamplingPolicyCustom,+ uzuToolFunction,+} from '@trymirai/uzu';+import * as z from 'zod';+++const Coordinate = z.object({+ latitude: z.number().describe('Latitude in decimal degrees.'),+ longitude: z.number().describe('Longitude in decimal degrees.'),+});++type Coordinate = z.infer<typeof Coordinate>;+++const getCurrentLocation = uzuToolFunction({+ name: 'get_location',+ description: 'Return the current location in coordinates',+ parameters: z.object({}),+ returns: Coordinate,+ handler: (): Coordinate => ({+ latitude: 51.5074,+ longitude: -0.1278,+ }),+});+++async function calculateCurrentTemperature({latitude, longitude}: Coordinate): Promise<number> {+ if (!Number.isFinite(Math.hypot(latitude, longitude))) {+ throw new RangeError('Coordinates must be finite');+ }+ return 25;+}++const getCurrentTemperature = uzuToolFunction({+ name: 'get_current_temperature',+ description: 'Return the temperature at the provided coordinates',+ parameters: Coordinate,+ returns: z.number(),+ handler: calculateCurrentTemperature,+});+++async function main() {+ const engine = await Engine.create(EngineConfig.create());+ const model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');+ if (!model) {+ throw new Error('Model not found');+ }+ for await (const update of await engine.download(model)) {+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);+ }+ process.stdout.write('\n');++ const session = await engine.chat(model, ChatConfig.create());+ await session.addTool(getCurrentLocation);+ await session.addTool(getCurrentTemperature);++ const messages = [+ ChatMessage.system().withText('You are a helpful assistant'),+ ChatMessage.user().withText('What temperature is it now at my location?'),+ ];+ const config = ChatReplyConfig.create().withSamplingPolicy(+ new SamplingPolicyCustom(new SamplingMethodGreedy()),+ );+ const replies = await session.reply(messages, config);+ const message = replies[replies.length - 1]?.message;+ if (message) {+ console.log('Reasoning:', message.reasoning ?? '');+ console.log('Text:', message.text ?? '');+ }+}++main().catch((error: unknown) => {+ console.error(error);+});+```++</details>++## Developmentdiff --git a/bindings/python/README.md b/bindings/python/README.mdindex 2412cb1f9..37bef54a3 100644--- a/bindings/python/README.md+++ b/bindings/python/README.md@@ -38,12 +38,13 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:returnasync for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()session = await engine.chat(model, ChatConfig.create())@@ -72,7 +73,7 @@ Everything from model downloading to inference configuration is handled automati## Examples-You can run any example via `cargo tools example` \<**python**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start**\>:+You can run any example via `cargo tools example` \<**python**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:### Chat@@ -95,11 +96,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ChatMessage.system().with_text("You are a helpful assistant"),@@ -141,7 +143,6 @@ from uzu import ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig,async def main() -> None:engine_config = EngineConfig.create().with_openai_api_key("OPENAI_API_KEY")engine = await Engine.create(engine_config)-model = await engine.model("gpt-5")if model is None:raise RuntimeError("Model not found")@@ -203,11 +204,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()schema_string = json.dumps(CountryList.model_json_schema())messages = [@@ -249,7 +251,8 @@ async def main() -> None:if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ClassificationMessage.user("Hi")]@@ -262,6 +265,89 @@ if __name__ == "__main__":asyncio.run(main())```+### Tool calls++This example shows how to use external tools:++```python+import asyncio+from typing import Annotated++from pydantic import BaseModel++from uzu import (+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ Engine,+ EngineConfig,+ SamplingMethod,+ SamplingPolicy,+ uzu_tool_function,+)+++class Coordinate(BaseModel):+ """A geographic coordinate.++ Attributes:+ latitude: Latitude in decimal degrees.+ longitude: Longitude in decimal degrees.+ """++ latitude: float+ longitude: Annotated[float, "Longitude in decimal degrees."]+++@uzu_tool_function(name="get_location", description="Return the current location in coordinates")+def get_current_location() -> Coordinate:+ return Coordinate(latitude=51.5074, longitude=-0.1278)+++@uzu_tool_function+def get_current_temperature(+ latitude: float,+ longitude: Annotated[float, "Longitude in decimal degrees."],+) -> float:+ """Return the temperature at the provided coordinates.++ Args:+ latitude: Latitude in decimal degrees.+ longitude: This is overridden by the Annotated description.+ """+ _ = latitude, longitude+ return 25.0+++async def main() -> None:+ engine = await Engine.create(EngineConfig.create())+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")+ if model is None:+ raise RuntimeError("Model not found")+ async for update in (await engine.download(model)).iterator():+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()++ session = await engine.chat(model, ChatConfig.create())+ await session.add_tool(get_current_location)+ await session.add_tool(get_current_temperature)++ messages = [+ ChatMessage.system().with_text("You are a helpful assistant"),+ ChatMessage.user().with_text("What temperature is it now at my location?"),+ ]+ config = ChatReplyConfig.create().with_sampling_policy(SamplingPolicy.Custom(method=SamplingMethod.Greedy()))+ replies = await session.reply(messages, config)+ if replies:+ message = replies[-1].message+ print(f"Reasoning: {message.reasoning or ''}")+ print(f"Text: {message.text or ''}")+++if __name__ == "__main__":+ asyncio.run(main())+```+## Troubleshootingdiff --git a/bindings/python/examples/chat.py b/bindings/python/examples/chat.pyindex 273cf75fc..bb911cf90 100644--- a/bindings/python/examples/chat.py+++ b/bindings/python/examples/chat.py@@ -14,11 +14,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ChatMessage.system().with_text("You are a helpful assistant"),diff --git a/bindings/python/examples/chat_cloud.py b/bindings/python/examples/chat_cloud.pyindex f7ba51e55..be8762030 100644--- a/bindings/python/examples/chat_cloud.py+++ b/bindings/python/examples/chat_cloud.py@@ -6,7 +6,6 @@ from uzu import ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig,async def main() -> None:engine_config = EngineConfig.create().with_openai_api_key("OPENAI_API_KEY")engine = await Engine.create(engine_config)-model = await engine.model("gpt-5")if model is None:raise RuntimeError("Model not found")diff --git a/bindings/python/examples/chat_structured_output.py b/bindings/python/examples/chat_structured_output.pyindex a1d6c1917..d4dfb0e57 100644--- a/bindings/python/examples/chat_structured_output.py+++ b/bindings/python/examples/chat_structured_output.py@@ -33,11 +33,12 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()schema_string = json.dumps(CountryList.model_json_schema())messages = [diff --git a/bindings/python/examples/classification.py b/bindings/python/examples/classification.pyindex 2dc0a9b38..1704dcad7 100644--- a/bindings/python/examples/classification.py+++ b/bindings/python/examples/classification.py@@ -11,7 +11,8 @@ async def main() -> None:if model is None:raise RuntimeError("Model not found")async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()messages = [ClassificationMessage.user("Hi")]diff --git a/bindings/python/examples/quick_start.py b/bindings/python/examples/quick_start.pyindex 9ac17880c..3c3510068 100644--- a/bindings/python/examples/quick_start.py+++ b/bindings/python/examples/quick_start.py@@ -7,12 +7,13 @@ async def main() -> None:engine_config = EngineConfig.create()engine = await Engine.create(engine_config)- model = await engine.model("Qwen/Qwen3-0.6B")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:returnasync for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()session = await engine.chat(model, ChatConfig.create())diff --git a/bindings/python/examples/tool_calls.py b/bindings/python/examples/tool_calls.pyindex 0ce68694f..3d9be4858 100644--- a/bindings/python/examples/tool_calls.py+++ b/bindings/python/examples/tool_calls.py@@ -49,12 +49,12 @@ def get_current_temperature(async def main() -> None:engine = await Engine.create(EngineConfig.create())- model = await engine.model("mlx-community/Qwen3.5-9B-MLX-8bit")+ model = await engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4")if model is None:raise RuntimeError("Model not found")-async for update in (await engine.download(model)).iterator():- print(f"Download progress: {update.progress}")+ print(f"\rDownload progress: {update.progress:.2%}", end="", flush=True)+ print()session = await engine.chat(model, ChatConfig.create())await session.add_tool(get_current_location)diff --git a/bindings/swift/README.md b/bindings/swift/README.mdindex 295f89bc7..0fe0640e4 100644--- a/bindings/swift/README.md+++ b/bindings/swift/README.md@@ -31,19 +31,22 @@ dependencies: [Run the code below:```swift+import Foundationimport Uzupublic func runQuickStart() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let session = try await engine.chat(model: model, config: .create())@@ -69,25 +72,28 @@ Everything from model downloading to inference configuration is handled automati## Examples-You can run any example via `cargo tools example` \<**swift**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start**\>:+You can run any example via `cargo tools example` \<**swift**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:### ChatIn this example, we will download a model and get a reply to a specific list of messages:```swift+import Foundationimport Uzupublic func runChat() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withText(text: "You are a helpful assistant"),@@ -124,7 +130,7 @@ public func runChatCloud() async throws {let engineConfig = EngineConfig.create().withOpenaiApiKey(openaiApiKey: "OPENAI_API_KEY")let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "gpt-5") else {return}@@ -149,6 +155,7 @@ public func runChatCloud() async throws {Sometimes you want the generated output to be valid JSON with predefined fields. You can use `Grammar` to manually specify a JSON schema for the response you want to receive:```swift+import Foundationimport FoundationModelsimport Uzu@@ -162,12 +169,14 @@ public func runChatStructuredOutput() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withReasoningEffort(reasoningEffort: .disabled),@@ -191,6 +200,7 @@ public func runChatStructuredOutput() async throws {In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:```swift+import Foundationimport Uzupublic func runClassification() async throws {@@ -200,8 +210,10 @@ public func runClassification() async throws {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ClassificationMessage.user(content: "Hi")@@ -213,6 +225,79 @@ public func runClassification() async throws {}```+### Tool calls++This example shows how to use external tools:++```swift+import Foundation+import FoundationModels+import Uzu++@Generable+private struct Coordinate: Codable, Sendable {+ @Guide(description: "Latitude in decimal degrees.")+ let latitude: Double++ @Guide(description: "Longitude in decimal degrees.")+ let longitude: Double+}++private struct GetCurrentLocation: Tool {+ let description = "Returns current location in coordinates"++ @Generable+ struct Arguments {+ }++ func call(arguments: Arguments) async throws -> Coordinate {+ Coordinate(latitude: 51.5074, longitude: -0.1278)+ }+}++private struct GetCurrentTemperature: Tool {+ let description = "Returns temperature in provided location"++ func call(arguments: Coordinate) async throws -> Double {+ _ = arguments+ return 25.0+ }+}++public func runToolCalls() async throws {+ let engine = try await Engine.create(config: .create())+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {+ throw ToolCallsExampleError.modelNotFound+ }+ for try await update in try await engine.download(model: model).iterator() {+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)+ }+ print()++ let session = try await engine.chat(model: model, config: .create())+ try await session.addTool(GetCurrentLocation())+ try await session.addTool(GetCurrentTemperature())++ let messages = [+ ChatMessage.system().withText(text: "You are a helpful assistant"),+ ChatMessage.user().withText(text: "What temperature is it now at my location?"),+ ]+ let reply_config = ChatReplyConfig.create().withSamplingMethod(samplingMethod: .greedy)+ let replies = try await session.reply(input: messages, config: reply_config)+ guard let message = replies.last?.message else {+ return+ }++ print("Reasoning: \(message.reasoning() ?? "")")+ print("Text: \(message.text() ?? "")")+}++private enum ToolCallsExampleError: Swift.Error {+ case modelNotFound+}+```+## Troubleshootingdiff --git a/bindings/swift/Sources/Examples/Chat.swift b/bindings/swift/Sources/Examples/Chat.swiftindex 6c42a9b91..d2cfcce90 100644--- a/bindings/swift/Sources/Examples/Chat.swift+++ b/bindings/swift/Sources/Examples/Chat.swift@@ -1,15 +1,18 @@+import Foundationimport Uzupublic func runChat() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withText(text: "You are a helpful assistant"),diff --git a/bindings/swift/Sources/Examples/ChatCloud.swift b/bindings/swift/Sources/Examples/ChatCloud.swiftindex 0dbb359f2..cf8a39950 100644--- a/bindings/swift/Sources/Examples/ChatCloud.swift+++ b/bindings/swift/Sources/Examples/ChatCloud.swift@@ -4,7 +4,7 @@ public func runChatCloud() async throws {let engineConfig = EngineConfig.create().withOpenaiApiKey(openaiApiKey: "OPENAI_API_KEY")let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "gpt-5") else {return}diff --git a/bindings/swift/Sources/Examples/ChatStructuredOutput.swift b/bindings/swift/Sources/Examples/ChatStructuredOutput.swiftindex d7bc33546..c8327a14f 100644--- a/bindings/swift/Sources/Examples/ChatStructuredOutput.swift+++ b/bindings/swift/Sources/Examples/ChatStructuredOutput.swift@@ -1,3 +1,4 @@+import Foundationimport FoundationModelsimport Uzu@@ -11,12 +12,14 @@ public func runChatStructuredOutput() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ChatMessage.system().withReasoningEffort(reasoningEffort: .disabled),diff --git a/bindings/swift/Sources/Examples/Classification.swift b/bindings/swift/Sources/Examples/Classification.swiftindex 0a0b92bb4..47a03a3b6 100644--- a/bindings/swift/Sources/Examples/Classification.swift+++ b/bindings/swift/Sources/Examples/Classification.swift@@ -1,3 +1,4 @@+import Foundationimport Uzupublic func runClassification() async throws {@@ -7,8 +8,10 @@ public func runClassification() async throws {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let messages = [ClassificationMessage.user(content: "Hi")diff --git a/bindings/swift/Sources/Examples/QuickStart.swift b/bindings/swift/Sources/Examples/QuickStart.swiftindex ec233d3f4..e89d46363 100644--- a/bindings/swift/Sources/Examples/QuickStart.swift+++ b/bindings/swift/Sources/Examples/QuickStart.swift@@ -1,16 +1,19 @@+import Foundationimport Uzupublic func runQuickStart() async throws {let engineConfig = EngineConfig.create()let engine = try await Engine.create(config: engineConfig)- guard let model = try await engine.model(identifier: "Qwen/Qwen3-0.6B") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {return}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let session = try await engine.chat(model: model, config: .create())diff --git a/bindings/swift/Sources/Examples/ToolCalls.swift b/bindings/swift/Sources/Examples/ToolCalls.swiftindex c66b32b67..066f68c2c 100644--- a/bindings/swift/Sources/Examples/ToolCalls.swift+++ b/bindings/swift/Sources/Examples/ToolCalls.swift@@ -1,3 +1,4 @@+import Foundationimport FoundationModelsimport Uzu@@ -10,19 +11,20 @@ private struct Coordinate: Codable, Sendable {let longitude: Double}-private struct GetCurrentLocationTool: Tool {- let description = "Return the current location in coordinates."+private struct GetCurrentLocation: Tool {+ let description = "Returns current location in coordinates"@Generable- struct Arguments {}+ struct Arguments {+ }func call(arguments: Arguments) async throws -> Coordinate {Coordinate(latitude: 51.5074, longitude: -0.1278)}}-private struct GetCurrentTemperatureTool: Tool {- let description = "Return the temperature at the provided coordinates."+private struct GetCurrentTemperature: Tool {+ let description = "Returns temperature in provided location"func call(arguments: Coordinate) async throws -> Double {_ = arguments@@ -32,22 +34,25 @@ private struct GetCurrentTemperatureTool: Tool {public func runToolCalls() async throws {let engine = try await Engine.create(config: .create())- guard let model = try await engine.model(identifier: "mlx-community/Qwen3.5-9B-MLX-8bit") else {+ guard let model = try await engine.model(identifier: "alibaba:qwen3.5:0.8b:mirai:mirai-m:4") else {throw ToolCallsExampleError.modelNotFound}for try await update in try await engine.download(model: model).iterator() {- print("Download progress: \(update.progress())")+ print(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")+ fflush(stdout)}+ print()let session = try await engine.chat(model: model, config: .create())- try await session.addTool(GetCurrentLocationTool())- try await session.addTool(GetCurrentTemperatureTool())+ try await session.addTool(GetCurrentLocation())+ try await session.addTool(GetCurrentTemperature())let messages = [ChatMessage.system().withText(text: "You are a helpful assistant"),ChatMessage.user().withText(text: "What temperature is it now at my location?"),]- let replies = try await session.reply(input: messages, config: .create())+ let reply_config = ChatReplyConfig.create().withSamplingMethod(samplingMethod: .greedy)+ let replies = try await session.reply(input: messages, config: reply_config)guard let message = replies.last?.message else {return}diff --git a/bindings/typescript/README.md b/bindings/typescript/README.mdindex 44551abfd..167270948 100644--- a/bindings/typescript/README.md+++ b/bindings/typescript/README.md@@ -35,14 +35,15 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let session = await engine.chat(model, ChatConfig.create());@@ -72,26 +73,35 @@ Everything from model downloading to inference configuration is handled automati## Examples-You can run any example via `cargo tools example` \<**typescript**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start**\>:+You can run any example via `cargo tools example` \<**typescript**\> \<**chat** | **chat-cloud** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:### ChatIn this example, we will download a model and get a reply to a specific list of messages:```ts-import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSessionStreamChunkError, ChatSessionStreamChunkReplies, Engine, EngineConfig } from '@trymirai/uzu';+import {+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ ChatSessionStreamChunkError,+ ChatSessionStreamChunkReplies,+ Engine,+ EngineConfig+} from '@trymirai/uzu';async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ChatMessage.system().withText('You are a helpful assistant'),@@ -181,13 +191,14 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let schema = z.toJSONSchema(CountryListType);let schemaString = JSON.stringify(schema);@@ -224,8 +235,9 @@ async function main() {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ClassificationMessage.user('Hi')@@ -241,6 +253,95 @@ main().catch((error) => {});```+### Tool calls++This example shows how to use external tools:++```ts+import {+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ Engine,+ EngineConfig,+ SamplingMethodGreedy,+ SamplingPolicyCustom,+ uzuToolFunction,+} from '@trymirai/uzu';+import * as z from 'zod';+++const Coordinate = z.object({+ latitude: z.number().describe('Latitude in decimal degrees.'),+ longitude: z.number().describe('Longitude in decimal degrees.'),+});++type Coordinate = z.infer<typeof Coordinate>;+++const getCurrentLocation = uzuToolFunction({+ name: 'get_location',+ description: 'Return the current location in coordinates',+ parameters: z.object({}),+ returns: Coordinate,+ handler: (): Coordinate => ({+ latitude: 51.5074,+ longitude: -0.1278,+ }),+});+++async function calculateCurrentTemperature({latitude, longitude}: Coordinate): Promise<number> {+ if (!Number.isFinite(Math.hypot(latitude, longitude))) {+ throw new RangeError('Coordinates must be finite');+ }+ return 25;+}++const getCurrentTemperature = uzuToolFunction({+ name: 'get_current_temperature',+ description: 'Return the temperature at the provided coordinates',+ parameters: Coordinate,+ returns: z.number(),+ handler: calculateCurrentTemperature,+});+++async function main() {+ const engine = await Engine.create(EngineConfig.create());+ const model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');+ if (!model) {+ throw new Error('Model not found');+ }+ for await (const update of await engine.download(model)) {+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);+ }+ process.stdout.write('\n');++ const session = await engine.chat(model, ChatConfig.create());+ await session.addTool(getCurrentLocation);+ await session.addTool(getCurrentTemperature);++ const messages = [+ ChatMessage.system().withText('You are a helpful assistant'),+ ChatMessage.user().withText('What temperature is it now at my location?'),+ ];+ const config = ChatReplyConfig.create().withSamplingPolicy(+ new SamplingPolicyCustom(new SamplingMethodGreedy()),+ );+ const replies = await session.reply(messages, config);+ const message = replies[replies.length - 1]?.message;+ if (message) {+ console.log('Reasoning:', message.reasoning ?? '');+ console.log('Text:', message.text ?? '');+ }+}++main().catch((error: unknown) => {+ console.error(error);+});+```+## Troubleshootingdiff --git a/bindings/typescript/examples/chat.ts b/bindings/typescript/examples/chat.tsindex 7a7e37ddd..0f83fc7df 100644--- a/bindings/typescript/examples/chat.ts+++ b/bindings/typescript/examples/chat.ts@@ -1,16 +1,25 @@-import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSessionStreamChunkError, ChatSessionStreamChunkReplies, Engine, EngineConfig } from '@trymirai/uzu';+import {+ ChatConfig,+ ChatMessage,+ ChatReplyConfig,+ ChatSessionStreamChunkError,+ ChatSessionStreamChunkReplies,+ Engine,+ EngineConfig+} from '@trymirai/uzu';async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ChatMessage.system().withText('You are a helpful assistant'),diff --git a/bindings/typescript/examples/chatStructuredOutput.ts b/bindings/typescript/examples/chatStructuredOutput.tsindex 3b0514d68..b8894cbf1 100644--- a/bindings/typescript/examples/chatStructuredOutput.ts+++ b/bindings/typescript/examples/chatStructuredOutput.ts@@ -20,13 +20,14 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let schema = z.toJSONSchema(CountryListType);let schemaString = JSON.stringify(schema);diff --git a/bindings/typescript/examples/classification.ts b/bindings/typescript/examples/classification.tsindex fa2141fc5..761496e01 100644--- a/bindings/typescript/examples/classification.ts+++ b/bindings/typescript/examples/classification.ts@@ -9,8 +9,9 @@ async function main() {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let messages = [ClassificationMessage.user('Hi')diff --git a/bindings/typescript/examples/quickStart.ts b/bindings/typescript/examples/quickStart.tsindex 4b740566e..29597908c 100644--- a/bindings/typescript/examples/quickStart.ts+++ b/bindings/typescript/examples/quickStart.ts@@ -4,14 +4,15 @@ async function main() {let engineConfig = EngineConfig.create();let engine = await Engine.create(engineConfig);- let model = await engine.model('Qwen/Qwen3-0.6B');+ let model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ console.log();let session = await engine.chat(model, ChatConfig.create());diff --git a/bindings/typescript/examples/toolCalls.ts b/bindings/typescript/examples/toolCalls.tsindex d209c4d7c..e84f97a3b 100644--- a/bindings/typescript/examples/toolCalls.ts+++ b/bindings/typescript/examples/toolCalls.ts@@ -49,14 +49,14 @@ const getCurrentTemperature = uzuToolFunction({async function main() {const engine = await Engine.create(EngineConfig.create());- const model = await engine.model('mlx-community/Qwen3.5-9B-MLX-8bit');+ const model = await engine.model('alibaba:qwen3.5:0.8b:mirai:mirai-m:4');if (!model) {throw new Error('Model not found');}-for await (const update of await engine.download(model)) {- console.log('Download progress:', update.progress);+ process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);}+ process.stdout.write('\n');const session = await engine.chat(model, ChatConfig.create());await session.addTool(getCurrentLocation);diff --git a/crates/uzu/examples/chat.rs b/crates/uzu/examples/chat.rsindex 059d0ecef..3fafb4441 100644--- a/crates/uzu/examples/chat.rs+++ b/crates/uzu/examples/chat.rs@@ -1,3 +1,5 @@+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},session::chat::ChatSessionStreamChunk,@@ -9,11 +11,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let messages = vec![ChatMessage::system().with_text("You are a helpful assistant".to_string()),diff --git a/crates/uzu/examples/chat_structured_output.rs b/crates/uzu/examples/chat_structured_output.rsindex 0247a5a8f..41269f92b 100644--- a/crates/uzu/examples/chat_structured_output.rs+++ b/crates/uzu/examples/chat_structured_output.rs@@ -1,3 +1,5 @@+use std::io::{self, Write};+use schemars::{JsonSchema, schema_for};use serde::{Deserialize, Serialize};use uzu::{@@ -24,11 +26,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let schema_string = serde_json::to_string(&schema_for!(CountryList))?;let messages = vec![diff --git a/crates/uzu/examples/classification.rs b/crates/uzu/examples/classification.rsindex f7926bcc9..01060f351 100644--- a/crates/uzu/examples/classification.rs+++ b/crates/uzu/examples/classification.rs@@ -1,3 +1,5 @@+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},types::session::classification::ClassificationMessage,@@ -11,8 +13,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let messages = vec![ClassificationMessage::user("Hi".to_string())];diff --git a/crates/uzu/examples/quick_start.rs b/crates/uzu/examples/quick_start.rsindex 917877cd8..cfabedc56 100644--- a/crates/uzu/examples/quick_start.rs+++ b/crates/uzu/examples/quick_start.rs@@ -1,3 +1,5 @@+use std::io::{self, Write};+use uzu::{engine::{Engine, EngineConfig},types::session::chat::{ChatConfig, ChatMessage, ChatReplyConfig},@@ -8,11 +10,13 @@ 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("Qwen/Qwen3-0.6B".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let session = engine.chat(model, ChatConfig::default()).await?;diff --git a/crates/uzu/examples/tool_calls.rs b/crates/uzu/examples/tool_calls.rsindex 367ab609e..d41009775 100644--- a/crates/uzu/examples/tool_calls.rs+++ b/crates/uzu/examples/tool_calls.rs@@ -1,3 +1,5 @@+use std::io::{self, Write};+use nagare::tool::{func_def::ErrorFuture, uzu_tool_closure, uzu_tool_function};use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -28,11 +30,13 @@ fn get_current_location() -> Result<Coordinate, ErrorFuture> {#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {let engine = Engine::new(EngineConfig::default()).await?;- let model = engine.model("mlx-community/Qwen3.5-9B-MLX-8bit".to_string()).await?.ok_or("Model not found")?;+ let model = engine.model("alibaba:qwen3.5:0.8b:mirai:mirai-m:4".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());+ print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);+ io::stdout().flush()?;}+ println!();let mut session = engine.chat(model, ChatConfig::default()).await?;session.add_tool(get_current_location).await?;diff --git a/platforms.toml b/platforms.tomlindex 63428c789..e5c3166ec 100644--- a/platforms.toml+++ b/platforms.toml@@ -177,3 +177,4 @@ chat = { title = "Chat", description = "In this example, we will download a modechat-cloud = { title = "Chat with the cloud model", description = "In this example, we will get a reply to a specific list of messages from a cloud model:" }chat-structured-output = { title = "Chat with structured output", description = "Sometimes you want the generated output to be valid JSON with predefined fields. You can use `Grammar` to manually specify a JSON schema for the response you want to receive:" }classification = { title = "Classification", description = "In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:" }+tool-calls = { title = "Tool calls", description = "This example shows how to use external tools:" }