### Run Quick Start Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Executes the quick start example to demonstrate basic Siumai usage with OpenAI, Anthropic, and Ollama providers. It covers client creation, message handling, and environment setup. ```Bash cargo run --example quick_start ``` -------------------------------- ### Run Convenience Methods Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Executes the convenience methods example to showcase simplified APIs for common tasks in Siumai, such as quick client creation, preset configurations, message macros, and common patterns. ```Bash cargo run --example convenience_methods ``` -------------------------------- ### Run Provider Comparison Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Executes the provider comparison example to help understand and compare the performance, costs, and capabilities of different AI providers. It highlights provider strengths, weaknesses, and use case recommendations. ```Bash cargo run --example provider_comparison ``` -------------------------------- ### Run Basic Usage Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Executes the basic usage example to dive into Siumai's fundamental concepts, including message types (system, user, assistant), multimodal messages, parameter configuration, and error handling. ```Bash cargo run --example basic_usage ``` -------------------------------- ### Siumai OpenAI Provider Creation Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Shows how to create an OpenAI client using Siumai's LlmBuilder, configuring it with an API key, model name, and temperature. ```Rust // OpenAI let client = LlmBuilder::new() .openai() .api_key("your-key") .model("gpt-4o-mini") .temperature(0.7) .build() .await?; ``` -------------------------------- ### Set API Keys for Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Sets environment variables for API keys required by Siumai to authenticate with various AI providers like OpenAI and Anthropic. Also includes instructions for starting Ollama and pulling models. ```Bash # Choose one or more providers export OPENAI_API_KEY="your-openai-key" export ANTHROPIC_API_KEY="your-anthropic-key" export GROQ_API_KEY="your-groq-key" # For Ollama (local) ollama serve ollama pull llama3.2 ``` -------------------------------- ### Rust: Run Quick Start Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Executes the 'quick_start' example for Siumai, providing a 5-minute introduction to the library and its multi-provider capabilities. ```bash cargo run --example quick_start ``` -------------------------------- ### Run Ollama Basic Setup Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/ollama/README.md This command executes the basic setup example for Ollama using Cargo, demonstrating initial integration and functionality. ```bash # Run the basic setup example cargo run --example ollama_basic_setup ``` -------------------------------- ### Siumai Basic Chat Interaction Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Demonstrates a basic chat interaction with a Siumai client, sending a user message and printing the AI's text response. ```Rust let messages = vec![user!("What is Rust?")]; let response = client.chat(messages).await?; if let Some(text) = response.content_text() { println!("AI: {}", text); } ``` -------------------------------- ### Siumai Message Types Source: https://github.com/yumchalabs/siumai/blob/main/examples/01_getting_started/README.md Demonstrates the creation of different message types in Siumai: system messages to define AI behavior, user messages for input, and assistant messages for conversation history. ```Rust use siumai::prelude::*; // System message - sets AI behavior let system_msg = system!("You are a helpful assistant"); // User message - human input let user_msg = user!("Hello!"); // Assistant message - AI response (for conversation history) let assistant_msg = assistant!("Hi there!"); ``` -------------------------------- ### Run Stdio MCP Client Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Launches the Stdio MCP client example. The client automatically starts the Stdio MCP server as a child process, simplifying the setup for process-based communication. ```bash # The client will automatically start the server as a child process cargo run --example stdio_mcp_client ``` -------------------------------- ### Rust Quick Start: Get First AI Response Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md This snippet demonstrates how to get your first AI response using the Siumai Rust library. It serves as a basic entry point for new users. ```Rust fn main() { // Example usage for quick_start.rs println!("This is a placeholder for quick_start.rs"); } ``` -------------------------------- ### Siumai API Key Setup Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Configure your API keys for Siumai to interact with AI providers like OpenAI and Anthropic, or set up local development with Ollama. ```bash export OPENAI_API_KEY="your-key" export ANTHROPIC_API_KEY="your-key" # or for local development ollama serve && ollama pull llama3.2 ``` -------------------------------- ### Build Siumai Examples Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/google/README.md Command to build all examples for the Siumai library, ensuring all dependencies are met before running specific examples. ```bash cargo build --examples ``` -------------------------------- ### Run Basic Gemini Usage Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/google/README.md Demonstrates how to run the basic usage example for Google Gemini through the Siumai library. This involves setting up the environment and executing the cargo command. ```bash # Run the basic usage example cargo run --example google_basic_usage ``` -------------------------------- ### Build Siumai Examples Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md Command to build all examples for the Siumai library, ensuring all dependencies are met before running. ```bash cargo build --examples ``` -------------------------------- ### Install Ollama Locally Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/ollama/README.md Provides commands for installing Ollama on macOS using Homebrew and on Linux using a script. It also includes instructions to start the Ollama service. ```bash # Visit https://ollama.ai for installation instructions # Or use package managers: # macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh ``` ```bash ollama serve ``` -------------------------------- ### Run Thinking Showcase Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md Shows how to execute the thinking showcase example for Anthropic Claude with Siumai, highlighting advanced reasoning capabilities. ```bash # Run the thinking showcase cargo run --example anthropic_thinking_showcase ``` -------------------------------- ### Run Basic Example Source: https://github.com/yumchalabs/siumai/blob/main/README.md This command demonstrates how to run a basic example of the project's functionality using Cargo, the Rust build tool and package manager. ```rust cargo run --example basic_usage ``` -------------------------------- ### Build Siumai Examples Source: https://github.com/yumchalabs/siumai/blob/main/examples/05_use_cases/README.md Compiles the Siumai examples, ensuring all necessary dependencies are downloaded and built. ```bash cargo build --examples ``` -------------------------------- ### Rust: Run API Integration Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Executes the 'api_integration' example for Siumai, illustrating how to build a REST API service that leverages AI capabilities. ```bash cargo run --example api_integration ``` -------------------------------- ### Run HTTP MCP Server Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Starts the HTTP MCP server using Cargo. The server listens on http://127.0.0.1:3000/mcp and exposes tools like 'add' and 'get_time'. ```bash cargo run --example http_mcp_server ``` -------------------------------- ### Rust Simple Chatbot: Build First AI Application Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md This snippet guides users through building their first simple chatbot application using the Siumai Rust library. It's a practical example for beginners. ```Rust fn main() { // Example usage for simple_chatbot.rs println!("This is a placeholder for simple_chatbot.rs"); } ``` -------------------------------- ### Rust: Run Chat Basics Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Executes the 'chat_basics' example for Siumai, demonstrating the fundamental aspects of AI interactions and basic chat functionality. ```bash cargo run --example chat_basics ``` -------------------------------- ### Rust Stdio MCP Client Methods Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Demonstrates the core methods for orchestrating LLM interactions within the Stdio MCP Client. It includes functions for running a general demo, a non-streaming example with tool execution, and a streaming example with delta processing and tool execution. ```rust impl StdioMcpLlmDemo { // Main demo orchestrator pub async fn run_demo(&mut self) -> Result<(), LlmError> // Non-streaming approach: chat_with_tools() → tool execution → final response async fn run_non_streaming_example( &mut self, tools: &[Tool], ) -> Result<(), LlmError> // Streaming approach: chat_stream() → delta processing → tool execution → final response async fn run_streaming_example( &mut self, tools: &[Tool], ) -> Result<(), LlmError> } ``` -------------------------------- ### Bash: Install and Pull Ollama Model Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Installs Ollama from its official website and pulls the 'llama3.2' model for local LLM usage. ```bash # Install Ollama from https://ollama.ai ollama serve ollama pull llama3.2 ``` -------------------------------- ### Siumai Prerequisites Setup Source: https://github.com/yumchalabs/siumai/blob/main/examples/03_advanced_features/README.md Provides necessary setup instructions for advanced Siumai features, including exporting API keys for services like OpenAI and Anthropic, and optionally for ElevenLabs. It also includes commands for serving and pulling models with Ollama for local processing. ```bash # API keys for advanced features export OPENAI_API_KEY="your-key" export ANTHROPIC_API_KEY="your-key" # For multimodal examples export ELEVENLABS_API_KEY="your-key" # Optional for audio # For local processing ollama serve ollama pull llama3.2 ollama pull llava # For vision tasks ``` -------------------------------- ### Siumai OpenAI Client Configuration for Function Calling Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Sets up the Siumai OpenAI client for function calling by defining tools with their names, descriptions, and parameters. ```rust let tools = vec![ Tool::function("get_weather", "Get weather information") .parameter("location", "string", "City name") .required(&["location"]) ]; let response = client.chat_with_tools(messages, tools).await?; ``` -------------------------------- ### HttpMcpLlmDemo Structure (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Illustrates the structure of the HttpMcpLlmDemo in Rust, detailing methods for orchestrating the demo, handling non-streaming examples using chat_with_tools, and managing streaming examples with chat_stream. ```rust impl HttpMcpLlmDemo { // Main demo orchestrator pub async fn run_demo(&self) -> Result<(), LlmError> // Non-streaming approach: chat_with_tools() → tool execution → final response async fn run_non_streaming_example( &self, llm_client: &dyn ChatCapability, tools: &[ Tool ], ) -> Result<(), LlmError> // Streaming approach: chat_stream() → delta processing → tool execution → final response async fn run_streaming_example( &self, llm_client: &dyn ChatCapability, tools: &[ Tool ], ) -> Result<(), LlmError> } ``` -------------------------------- ### Build Stdio MCP Server Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Compiles the Stdio MCP server example using Cargo. This prepares the server for process-based communication. ```bash cargo build --example stdio_mcp_server ``` -------------------------------- ### Rust: Run Simple Chatbot Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Executes the 'simple_chatbot' example for Siumai, demonstrating the creation of an interactive chatbot with conversation memory management. ```bash cargo run --example simple_chatbot ``` -------------------------------- ### Run Basic Chat Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md Demonstrates how to run the basic chat example for Anthropic Claude using the Siumai library. This involves setting up the model and sending a user message. ```bash # Run the basic chat example cargo run --example anthropic_basic_chat ``` -------------------------------- ### Run Gemini Embedding Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/google/README.md Shows how to execute the advanced embedding example for Google Gemini using the Siumai library. This includes running the cargo command to test embedding capabilities with task type optimization. ```bash # Run the embedding example cargo run --example google_embedding_task_types ``` -------------------------------- ### Run HTTP MCP Client Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Executes the HTTP MCP client example. It optionally requires the OPENAI_API_KEY environment variable for full LLM integration. This client demonstrates communication with the MCP server. ```bash # Set OpenAI API key (optional, for full LLM integration) export OPENAI_API_KEY=your-api-key # Run the client cargo run --example http_mcp_client ``` -------------------------------- ### Setting OpenAI API Key Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Instructions on how to set the OpenAI API key as an environment variable for authentication. ```bash export OPENAI_API_KEY="your-openai-api-key" ``` -------------------------------- ### Test Stdio MCP Server with Inspector Source: https://github.com/yumchalabs/siumai/blob/main/examples/06_mcp_integration/README.md Tests the Stdio MCP server using the Model Context Protocol Inspector. This command requires Node.js and npm to be installed. ```bash npx @modelcontextprotocol/inspector cargo run --example stdio_mcp_server ``` -------------------------------- ### Rust: Run Streaming Chat Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Executes the 'streaming_chat' example for Siumai, showcasing how to handle real-time response streaming from AI models. ```bash cargo run --example streaming_chat ``` -------------------------------- ### Siumai OpenAI Client Configuration for Cost Optimization Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Configures the Siumai OpenAI client with cost optimization parameters, including model selection, maximum tokens, and temperature. ```rust let client = LlmBuilder::new() .openai() .model("gpt-4o-mini") .max_tokens(500) // Limit response length .temperature(0.1) // Lower for consistency .build() .await?; ``` -------------------------------- ### Siumai Quick Start with DeepSeek and OpenRouter Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai_compatible/README.md Demonstrates a quick start using the Siumai library to interact with AI models. It shows how to build and configure clients for DeepSeek (cost-effective chat) and OpenRouter (access to multiple models like GPT-4 and Claude), and then perform a chat operation. ```rust use siumai::prelude::*; #[tokio::main] async fn main() -> Result<(), Box> { // DeepSeek - cost-effective let deepseek = LlmBuilder::new() .deepseek() .api_key(&std::env::var("DEEPSEEK_API_KEY")?) .model("deepseek-chat") .build() .await?; // OpenRouter - access to multiple models let openrouter = LlmBuilder::new() .openrouter() .api_key(&std::env::var("OPENROUTER_API_KEY")?) .model("openai/gpt-4") .build() .await?; let messages = vec![user!("Explain the benefits of AI")]; let response = deepseek.chat(messages.clone()).await?; println!("DeepSeek: {}", response.content_text().unwrap_or_default()); Ok(()) } ``` -------------------------------- ### Files API and Assistants Integration with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Demonstrates file management and processing for the Assistants API, covering file upload, document processing, and conversation integration. ```bash # Note: This example is not yet implemented # cargo run --example openai_files_api ``` -------------------------------- ### Secure API Key Authentication Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Shows how to authenticate using an API key, prioritizing environment variables for security. It also illustrates building an LLM client with the provided API key. ```rust // Use environment variables let api_key = std::env::var("OPENAI_API_KEY")?; // Or use a secure configuration system let client = LlmBuilder::new() .openai() .api_key(&api_key) .build() .await?; ``` -------------------------------- ### Siumai Parameter Mapping Between Providers (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Understand parameter conversion and mapping between different AI providers using Siumai. This example covers common vs. provider-specific parameters, validation, default values, and custom mapping. ```bash cargo run --example parameter_mapping ``` -------------------------------- ### Stream LLM Responses with Progress Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Explains how to stream responses from the LLM in real-time, processing content deltas as they arrive and displaying them progressively. ```rust use futures_util::StreamExt; let mut stream = client.chat_stream(messages, None).await?; let mut response_text = String::new(); while let Some(event) = stream.next().await { match event? { ChatStreamEvent::ContentDelta { delta, .. } => { response_text.push_str(&delta); print!("{}", delta); // Real-time display } ChatStreamEvent::StreamEnd { .. } => break, _ => {} } } ``` -------------------------------- ### Siumai Provider-Agnostic Interface (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Utilize a unified interface with Siumai to write code that works across different AI providers. This example demonstrates provider abstraction, dynamic switching, capability detection, and fallback strategies. ```bash cargo run --example unified_interface ``` -------------------------------- ### Advanced OpenAI Features with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Highlights advanced OpenAI capabilities such as JSON mode for structured responses, function calling, tool usage, system fingerprints, and response format control. ```bash cargo run --example openai_enhanced_features ``` -------------------------------- ### Bash: Set Groq API Key Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Sets the GROQ_API_KEY environment variable for authenticating with Groq services. ```bash export GROQ_API_KEY="your-groq-key" ``` -------------------------------- ### Rust Unified Interface: Provider-Agnostic Programming Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md This snippet demonstrates the unified interface of the Siumai library, enabling provider-agnostic programming. Write code once and use it with any supported LLM provider. ```Rust fn main() { // Example usage for unified_interface.rs println!("This is a placeholder for unified_interface.rs"); } ``` -------------------------------- ### Generate Structured JSON Output Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Shows how to configure the LLM client to ensure responses are in valid JSON format, using the `response_format` option and providing system instructions for the output structure. ```rust let messages = vec![ system!("Respond in valid JSON format with 'answer' and 'confidence' fields"), user!("What is the capital of France?") ]; let client = LlmBuilder::new() .openai() .response_format("json_object") .build() .await?; ``` -------------------------------- ### Optimize Vision Detail Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Demonstrates how to set the detail level for image processing in a chat message. Using 'low' detail is recommended for simpler images and can reduce costs. ```rust let message = ChatMessage::user("Describe this image") .with_image("image.jpg", Some("low")) // Costs less .build(); ``` -------------------------------- ### OpenAI Responses API with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Showcases the usage of the OpenAI Responses API for stateful conversations, background processing, and conversation chaining. It requires an OPENAI_API_KEY and optionally an OPENAI_SESSION_KEY for listing responses. ```bash cargo run --example openai_responses_api ``` -------------------------------- ### Configure LLM Client with Custom Parameters (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/03_advanced_features/README.md Provides an example of building a custom LLM client configuration, including setting the model, temperature, max tokens, and custom parameters for fine-tuning behavior. ```rust let client = LlmBuilder::new() .openai() .model("gpt-4") .temperature(0.1) // Low for consistency .max_tokens(2000) .custom_parameter("reasoning_effort", "high") .build() .await?; ``` -------------------------------- ### Analyze Thinking Process in Rust Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md Defines prompts for step-by-step reasoning and complex problem analysis. These prompts guide the AI model to provide detailed explanations and consider various factors. The code defines string templates for thinking and analysis prompts. ```Rust // Request step-by-step reasoning let thinking_prompt = "Think through this step by step:\n\ Show your reasoning process for: {}"; // Analyze complex problems let analysis_prompt = "Analyze this problem considering:\n\ 1. Key factors and constraints\n\ 2. Potential solutions\n\ 3. Trade-offs and implications\n\ 4. Recommended approach"; ``` -------------------------------- ### Run Adapter System Showcase Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai_compatible/README.md Showcases the comprehensive OpenAI-compatible adapter system, demonstrating provider adapter architecture, parameter transformation (e.g., thinking_budget to reasoning_effort), field mapping, model-specific configurations, and real API integration with DeepSeek. It covers the workflow from architecture to production usage, emphasizing automatic parameter transformation and real-world integration patterns. ```bash # Run the adapter system showcase cargo run --example adapter_system_showcase # With API key for real integration testing SILICONFLOW_API_KEY="your-key" cargo run --example adapter_system_showcase ``` -------------------------------- ### Running Siumai Tests Source: https://github.com/yumchalabs/siumai/blob/main/README.md Provides instructions for running tests within the Siumai project. It covers standard unit tests, mock integration tests, and real LLM integration tests, including setup for API keys and command-line execution. ```bash cargo test ``` ```bash cargo test --test integration_tests ``` ```bash export OPENAI_API_KEY="your-key" export ANTHROPIC_API_KEY="your-key" export GEMINI_API_KEY="your-key" # ... other providers ``` ```bash # Test all available providers cargo test test_all_available_providers -- --ignored --nocapture # Test specific provider cargo test test_openai_integration -- --ignored --nocapture ``` -------------------------------- ### Basic OpenAI Chat with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Demonstrates essential OpenAI chat features, including model selection (GPT-4, GPT-4o, GPT-3.5), parameter tuning (temperature), token usage optimization, and response format options. ```bash cargo run --example openai_basic_chat ``` -------------------------------- ### Siumai Feature Detection (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Dynamically detect and utilize provider capabilities with Siumai. This example focuses on capability checking, feature availability, graceful degradation, and provider metadata. ```bash cargo run --example capability_detection ``` -------------------------------- ### Handle LLM API Errors Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Provides an example of robust error handling for LLM API calls, specifically addressing rate limit errors with backoff strategies and authentication errors. ```rust match client.chat(messages).await { Ok(response) => { // Handle success } Err(LlmError::RateLimitError(_)) => { // Implement backoff tokio::time::sleep(Duration::from_secs(60)).await; } Err(LlmError::AuthenticationError(_)) => { // Check API key } Err(e) => { // Handle other errors } } ``` -------------------------------- ### Rust Provider Comparison: Understand LLM Providers Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md This snippet helps users understand and compare different LLM providers supported by the Siumai library. It's useful for choosing the right provider for specific needs. ```Rust fn main() { // Example usage for provider_comparison.rs println!("This is a placeholder for provider_comparison.rs"); } ``` -------------------------------- ### DALL-E Image Generation Showcase with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai/README.md Provides a comprehensive demonstration of OpenAI's DALL-E image generation capabilities, including different DALL-E versions, image sizes, quality settings, prompt optimization, and error handling. ```bash cargo run --example image_generation_showcase ``` -------------------------------- ### Siumai Production-Ready Error Handling (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Implement production-ready error management in your Siumai applications. This example covers error types, retry strategies, rate limit handling, and graceful degradation. ```bash cargo run --example error_handling ``` -------------------------------- ### Siumai Chat Basics (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Master the fundamentals of chat-based AI interactions using Siumai. This example covers message types, conversation management, response metadata, context strategies, and conversation history. ```bash cargo run --example chat_basics ``` -------------------------------- ### Siumai Response Caching for Performance (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Dramatically improve performance and reduce costs with intelligent response caching in Siumai. This example covers cache implementation patterns, optimization strategies, cost reduction, and thread-safe management. ```bash cargo run --example response_cache ``` -------------------------------- ### Run Integration Tests Source: https://github.com/yumchalabs/siumai/blob/main/README.md This snippet shows how to execute integration tests for the project. It includes commands for Linux/macOS and Windows environments, assuming a template .env file is present. ```bash cp .env.example .env ./scripts/run_integration_tests.sh ``` ```bat cp .env.example .env scripts\run_integration_tests.bat ``` -------------------------------- ### Siumai Real-time Response Streaming (Rust) Source: https://github.com/yumchalabs/siumai/blob/main/examples/02_core_features/README.md Learn to handle streaming responses for an improved user experience with Siumai. This example focuses on processing stream events, displaying content in real-time, performance optimization, and error handling within streams. ```bash cargo run --example streaming_chat ``` -------------------------------- ### Basic Anthropic Claude Chat with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md A Rust example demonstrating a basic chat interaction with Anthropic Claude using the Siumai library. It shows how to build the AI client, set parameters like model and temperature, and send a user message. ```rust use siumai::prelude::*; #[tokio::main] async fn main() -> Result<(), Box> { let ai = SiumaiBuilder::new() .provider(Provider::Anthropic) .api_key(&std::env::var("ANTHROPIC_API_KEY")?) .model("claude-3-sonnet") .temperature(0.3) .max_tokens(1000) .build() .await?; let messages = vec![ ChatMessage::user("Explain quantum computing in simple terms") ]; let response = ai.chat(&messages).await?; println!("Claude: {}", response.text().unwrap_or_default()); Ok(()) } ``` -------------------------------- ### Run SiliconFlow Example Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/openai_compatible/README.md Demonstrates the complete showcase of SiliconFlow's AI capabilities, including chat with DeepSeek and Qwen models, text embeddings with BGE models, document reranking, and a full RAG workflow. It highlights how to use reranking, build RAG systems, and combine chat, embeddings, and reranking for advanced document relevance scoring. ```bash # Run the SiliconFlow example cargo run --example siliconflow ``` -------------------------------- ### Bash: Set Anthropic API Key Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Sets the ANTHROPIC_API_KEY environment variable for authenticating with Anthropic services. ```bash export ANTHROPIC_API_KEY="your-anthropic-key" ``` -------------------------------- ### Basic Gemini Chat with Siumai Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/google/README.md A Rust code snippet demonstrating basic chat functionality with Google Gemini using the Siumai library. It shows how to build the AI client, send a message, and print the response. ```rust use siumai::prelude::*; #[tokio::main] async fn main() -> Result<(), Box> { let ai = LlmBuilder::new() .google() .api_key(&std::env::var("GEMINI_API_KEY")?) .model("gemini-1.5-flash") .temperature(0.7) .build() .await?; let messages = vec![ user!("Explain quantum computing in simple terms") ]; let response = ai.chat(messages).await?; println!("Gemini: {}", response.content_text().unwrap_or_default()); Ok(()) } ``` -------------------------------- ### Gemini Model Selection for Cost Optimization Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/google/README.md Illustrates how to select different Gemini models (Flash and Pro) for cost optimization in Rust using the Siumai library. It shows configuring models based on task complexity and token limits. ```rust // Use Flash for most tasks let fast_ai = LlmBuilder::new() .google() .model("gemini-1.5-flash") .max_tokens(500) .build().await?; // Use Pro for complex tasks let advanced_ai = LlmBuilder::new() .google() .model("gemini-1.5-pro") .max_tokens(1000) .build().await?; ``` -------------------------------- ### Bash: Set OpenAI API Key Source: https://github.com/yumchalabs/siumai/blob/main/examples/README.md Sets the OPENAI_API_KEY environment variable for authenticating with OpenAI services. ```bash export OPENAI_API_KEY="your-openai-key" ``` -------------------------------- ### Set Anthropic API Key Source: https://github.com/yumchalabs/siumai/blob/main/examples/04_providers/anthropic/README.md Instructions on how to set the ANTHROPIC_API_KEY environment variable, which is required to authenticate with the Anthropic API. ```bash export ANTHROPIC_API_KEY="your-anthropic-key" ```