Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Remove classification examples (#735)

Aleksandr Golokoz8a13fd78f543
diff --git a/README.md b/README.md
index 480954a92..d89116c75 100644
--- a/README.md
+++ b/README.md
@@ -241,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-shared-instance** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:
+You can run any example via `cargo tools example` \<**rust** | **python** | **swift** | **typescript**\> \<**chat** | **chat-cloud** | **chat-shared-instance** | **chat-structured-output** | **quick-start** | **tool-calls**\>:
### Chat
@@ -1066,146 +1066,6 @@ main().catch((error) => {
</details>
-### Classification
-
-In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:
-
-<details>
-<summary>Rust</summary>
-
-```rust
-use std::io::{self, Write};
-
-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 {
- print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);
- io::stdout().flush()?;
- }
- println!();
-
- 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(())
-}
-```
-
-</details>
-
-<details>
-<summary>Python</summary>
-
-```python
-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"\rDownload progress: {update.progress:.2%}", end="", flush=True)
- print()
-
- 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())
-```
-
-</details>
-
-<details>
-<summary>Swift</summary>
-
-```swift
-import Foundation
-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(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")
- fflush(stdout)
- }
- print()
-
- 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)")
-}
-```
-
-</details>
-
-<details>
-<summary>TypeScript</summary>
-
-```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)) {
- process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);
- }
- console.log();
-
- 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);
-});
-```
-
-</details>
-
-
### Tool calls
This example shows how to use external tools:
diff --git a/bindings/python/README.md b/bindings/python/README.md
index 90550e0cb..496e7cb35 100644
--- a/bindings/python/README.md
+++ b/bindings/python/README.md
@@ -73,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-shared-instance** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:
+You can run any example via `cargo tools example` \<**python**\> \<**chat** | **chat-cloud** | **chat-shared-instance** | **chat-structured-output** | **quick-start** | **tool-calls**\>:
### Chat
@@ -280,38 +280,6 @@ async def main() -> None:
print(countries)
-if __name__ == "__main__":
- asyncio.run(main())
-```
-
-### Classification
-
-In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:
-
-```python
-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"\rDownload progress: {update.progress:.2%}", end="", flush=True)
- print()
-
- 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())
```
diff --git a/bindings/python/examples/classification.py b/bindings/python/examples/classification.py
deleted file mode 100644
index 1704dcad7..000000000
--- a/bindings/python/examples/classification.py
+++ /dev/null
@@ -1,25 +0,0 @@
-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"\rDownload progress: {update.progress:.2%}", end="", flush=True)
- print()
-
- 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())
diff --git a/bindings/swift/README.md b/bindings/swift/README.md
index cd87a5342..b5332e13a 100644
--- a/bindings/swift/README.md
+++ b/bindings/swift/README.md
@@ -72,7 +72,7 @@ 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-shared-instance** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:
+You can run any example via `cargo tools example` \<**swift**\> \<**chat** | **chat-cloud** | **chat-shared-instance** | **chat-structured-output** | **quick-start** | **tool-calls**\>:
### Chat
@@ -242,36 +242,6 @@ public func runChatStructuredOutput() async throws {
}
```
-### Classification
-
-In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:
-
-```swift
-import Foundation
-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(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")
- fflush(stdout)
- }
- print()
-
- 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)")
-}
-```
-
### Tool calls
This example shows how to use external tools:
diff --git a/bindings/swift/Sources/Examples/CLI.swift b/bindings/swift/Sources/Examples/CLI.swift
index be33c4640..daa4ac81f 100644
--- a/bindings/swift/Sources/Examples/CLI.swift
+++ b/bindings/swift/Sources/Examples/CLI.swift
@@ -10,10 +10,8 @@ struct Example: AsyncParsableCommand {
version: "1.0.0"
)
- @Argument(
- help:
- "Mode: chat | chat-cloud | chat-shared-instance | chat-structured-output | classification | quick-start | tool-calls",
- transform: { $0.lowercased() })
+ @Argument(help: "Mode: chat | chat-cloud | chat-shared-instance | chat-structured-output | quick-start | tool-calls",
+ transform: { $0.lowercased() })
var mode: String = "chat"
mutating func run() async throws {
@@ -28,8 +26,6 @@ struct Example: AsyncParsableCommand {
try await runChatSharedInstance()
case "chat-structured-output":
try await runChatStructuredOutput()
- case "classification":
- try await runClassification()
case "tool-calls":
try await runToolCalls()
default:
diff --git a/bindings/swift/Sources/Examples/Classification.swift b/bindings/swift/Sources/Examples/Classification.swift
deleted file mode 100644
index 47a03a3b6..000000000
--- a/bindings/swift/Sources/Examples/Classification.swift
+++ /dev/null
@@ -1,23 +0,0 @@
-import Foundation
-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(String(format: "\r\u{001B}[2KDownload progress: %.2f%%", update.progress() * 100), terminator: "")
- fflush(stdout)
- }
- print()
-
- 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)")
-}
diff --git a/bindings/typescript/README.md b/bindings/typescript/README.md
index 40c9f48d8..10f6488b4 100644
--- a/bindings/typescript/README.md
+++ b/bindings/typescript/README.md
@@ -73,7 +73,7 @@ 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-shared-instance** | **chat-structured-output** | **classification** | **quick-start** | **tool-calls**\>:
+You can run any example via `cargo tools example` \<**typescript**\> \<**chat** | **chat-cloud** | **chat-shared-instance** | **chat-structured-output** | **quick-start** | **tool-calls**\>:
### Chat
@@ -271,40 +271,6 @@ main().catch((error) => {
});
```
-### Classification
-
-In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:
-
-```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)) {
- process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);
- }
- console.log();
-
- 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);
-});
-```
-
### Tool calls
This example shows how to use external tools:
diff --git a/bindings/typescript/examples/classification.ts b/bindings/typescript/examples/classification.ts
deleted file mode 100644
index 761496e01..000000000
--- a/bindings/typescript/examples/classification.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-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)) {
- process.stdout.write(`\rDownload progress: ${(update.progress * 100).toFixed(2)}%`);
- }
- console.log();
-
- 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);
-});
diff --git a/crates/uzu/examples/classification.rs b/crates/uzu/examples/classification.rs
deleted file mode 100644
index 01060f351..000000000
--- a/crates/uzu/examples/classification.rs
+++ /dev/null
@@ -1,28 +0,0 @@
-use std::io::{self, Write};
-
-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 {
- print!("\r\u{001B}[2KDownload progress: {:.2}%", update.progress() * 100.0);
- io::stdout().flush()?;
- }
- println!();
-
- 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(())
-}
diff --git a/platforms.toml b/platforms.toml
index 46280bedb..907b4543f 100644
--- a/platforms.toml
+++ b/platforms.toml
@@ -177,5 +177,4 @@ chat = { title = "Chat", description = "In this example, we will download a mode
chat-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-shared-instance = { title = "Chat with shared instance", description = "This example shows how to reuse chat instance without reloading model into memory:" }
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:" }