|
| 1 | +# AGiXT Rust SDK |
| 2 | + |
| 3 | +[](https://github.com/sponsors/Josh-XT) [](https://paypal.me/joshxt) [](https://ko-fi.com/joshxt) |
| 4 | + |
| 5 | +[](https://github.com/Josh-XT/AGiXT) [](https://github.com/AGiXT/hub) [](https://github.com/AGiXT/nextjs) [](https://github.com/AGiXT/streamlit) |
| 6 | + |
| 7 | +[](https://github.com/AGiXT/python-sdk) [](https://pypi.org/project/agixtsdk/) |
| 8 | + |
| 9 | +[](https://github.com/AGiXT/typescript-sdk) [](https://www.npmjs.com/package/agixt) |
| 10 | + |
| 11 | +[](https://github.com/AGiXT/dart-sdk) |
| 12 | + |
| 13 | +[](https://discord.gg/d3TkHRZcjD) |
| 14 | +[](https://twitter.com/Josh_XT) |
| 15 | + |
| 16 | +[](https://josh-xt.github.io/AGiXT/) |
| 17 | + |
| 18 | +This is the official Rust SDK for [AGiXT](https://github.com/AGiXT/python-sdk), providing a type-safe way to interact with the AGiXT API. |
| 19 | + |
| 20 | +## Features |
| 21 | + |
| 22 | +- Full API coverage for AGiXT |
| 23 | +- Async/await support using Tokio |
| 24 | +- Type-safe request and response handling |
| 25 | +- Comprehensive error handling |
| 26 | +- Built-in support for authentication and session management |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +Add this to your `Cargo.toml`: |
| 31 | + |
| 32 | +```toml |
| 33 | +[dependencies] |
| 34 | +agixt-sdk = "0.1.0" |
| 35 | +``` |
| 36 | + |
| 37 | +## Quick Start |
| 38 | + |
| 39 | +```rust |
| 40 | +use agixt_sdk::AGiXTSDK; |
| 41 | + |
| 42 | +#[tokio::main] |
| 43 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 44 | + // Create a new SDK instance |
| 45 | + let client = AGiXTSDK::new( |
| 46 | + Some("http://localhost:7437".to_string()), |
| 47 | + Some("your-api-key".to_string()), |
| 48 | + false, |
| 49 | + ); |
| 50 | + |
| 51 | + // Get list of available providers |
| 52 | + let providers = client.get_providers().await?; |
| 53 | + println!("Available providers: {:?}", providers); |
| 54 | + |
| 55 | + // Create a new agent |
| 56 | + let agent_name = "my_agent"; |
| 57 | + client.add_agent(agent_name, None, None, None).await?; |
| 58 | + |
| 59 | + // Start a new conversation |
| 60 | + let conversation = client.new_conversation(agent_name, "test_conversation", None).await?; |
| 61 | + println!("Created conversation: {:?}", conversation); |
| 62 | + |
| 63 | + Ok(()) |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +## Authentication |
| 68 | + |
| 69 | +```rust |
| 70 | +use agixt_sdk::AGiXTSDK; |
| 71 | + |
| 72 | +#[tokio::main] |
| 73 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 74 | + let client = AGiXTSDK::new(None, None, false); |
| 75 | + |
| 76 | + // Register a new user |
| 77 | + let otp_uri = client.register_user( |
| 78 | + "user@example.com", |
| 79 | + "John", |
| 80 | + "Doe" |
| 81 | + ).await?; |
| 82 | + println!("Registration successful. OTP URI: {}", otp_uri); |
| 83 | + |
| 84 | + // Login with email and OTP |
| 85 | + if let Some(token) = client.login("user@example.com", "123456").await? { |
| 86 | + println!("Login successful! Token: {}", token); |
| 87 | + } |
| 88 | + |
| 89 | + Ok(()) |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +## Core Features |
| 94 | + |
| 95 | +### Providers |
| 96 | + |
| 97 | +```rust |
| 98 | +// Get all available providers |
| 99 | +let providers = client.get_providers().await?; |
| 100 | + |
| 101 | +// Get providers for a specific service |
| 102 | +let chat_providers = client.get_providers_by_service("chat").await?; |
| 103 | + |
| 104 | +// Get provider settings |
| 105 | +let settings = client.get_provider_settings("gpt4free").await?; |
| 106 | +``` |
| 107 | + |
| 108 | +### Agents |
| 109 | + |
| 110 | +```rust |
| 111 | +// Create a new agent |
| 112 | +client.add_agent("my_agent", None, None, None).await?; |
| 113 | + |
| 114 | +// Get agent configuration |
| 115 | +let config = client.get_agent_config("my_agent").await?; |
| 116 | + |
| 117 | +// Update agent settings |
| 118 | +use std::collections::HashMap; |
| 119 | +let mut settings = HashMap::new(); |
| 120 | +settings.insert("setting_key".to_string(), serde_json::json!("value")); |
| 121 | +client.update_agent_settings("my_agent", settings).await?; |
| 122 | +``` |
| 123 | + |
| 124 | +### Conversations |
| 125 | + |
| 126 | +```rust |
| 127 | +// Create a new conversation |
| 128 | +let conversation = client.new_conversation("my_agent", "test_conv", None).await?; |
| 129 | + |
| 130 | +// Add a message to the conversation |
| 131 | +client.new_conversation_message("user", "Hello!", "test_conv").await?; |
| 132 | + |
| 133 | +// Get conversation history |
| 134 | +let history = client.get_conversation("my_agent", "test_conv", Some(10), Some(1)).await?; |
| 135 | +``` |
| 136 | + |
| 137 | +## Error Handling |
| 138 | + |
| 139 | +The SDK uses a custom error type that covers various error cases: |
| 140 | + |
| 141 | +```rust |
| 142 | +pub enum Error { |
| 143 | + RequestError(reqwest::Error), |
| 144 | + JsonError(serde_json::Error), |
| 145 | + ApiError { status: u16, message: String }, |
| 146 | + AuthError(String), |
| 147 | + InvalidInput(String), |
| 148 | + Other(String), |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +All methods return a `Result<T, Error>` type, allowing for proper error handling: |
| 153 | + |
| 154 | +```rust |
| 155 | +match client.get_providers().await { |
| 156 | + Ok(providers) => println!("Providers: {:?}", providers), |
| 157 | + Err(e) => eprintln!("Error: {}", e), |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +## Contributing |
| 162 | + |
| 163 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 164 | + |
| 165 | +## License |
| 166 | + |
| 167 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments