|
| 1 | +# Gradient Python SDK Examples |
| 2 | + |
| 3 | +This directory contains examples demonstrating how to use the Gradient Python SDK with various frameworks and for different use cases. |
| 4 | + |
| 5 | +## Available Examples |
| 6 | + |
| 7 | +### Framework Integrations |
| 8 | + |
| 9 | +- **[Django Integration](django_integration.py)** - Complete Django web app with chat completions, image generation, agent management, and knowledge bases |
| 10 | +- **[Flask Integration](flask_integration.py)** - Full Flask application with REST API endpoints for all Gradient features |
| 11 | +- **[FastAPI Integration](fastapi_integration.py)** - Modern async FastAPI app with Pydantic models and comprehensive endpoints |
| 12 | +- **[Streamlit Integration](streamlit_integration.py)** - Interactive web UI for chat and image generation |
| 13 | +- **[Gradio Integration](gradio_integration.py)** - User-friendly interface with tabs for chat, images, and model management |
| 14 | +- **[CLI Example](cli_example.py)** - Command-line tool for all Gradient operations |
| 15 | + |
| 16 | +### Utility Examples |
| 17 | + |
| 18 | +- **[Agent Wait Until Ready](agent_wait_until_ready.py)** - How to wait for agent deployment to be ready |
| 19 | +- **[Knowledge Base Indexing Wait](knowledge_base_indexing_wait.py)** - How to wait for knowledge base indexing to complete |
| 20 | +- **[Wait for Knowledge Base](wait_for_knowledge_base.py)** - How to wait for knowledge base creation |
| 21 | + |
| 22 | +## Running Examples |
| 23 | + |
| 24 | +Each example is a standalone Python script that can be run directly: |
| 25 | + |
| 26 | +```bash |
| 27 | +# Make sure you have the required environment variables set |
| 28 | +export DIGITALOCEAN_ACCESS_TOKEN="your_token_here" |
| 29 | +export GRADIENT_MODEL_ACCESS_KEY="your_model_key_here" |
| 30 | +export GRADIENT_AGENT_ACCESS_KEY="your_agent_key_here" |
| 31 | +export GRADIENT_AGENT_ENDPOINT="https://your-agent.agents.do-ai.run" |
| 32 | + |
| 33 | +# Run an example |
| 34 | +python examples/django_integration.py |
| 35 | +``` |
| 36 | + |
| 37 | +## Framework-Specific Setup |
| 38 | + |
| 39 | +### Django |
| 40 | +The Django example shows how to create a Django view that uses the Gradient SDK for AI-powered responses. |
| 41 | + |
| 42 | +### Flask |
| 43 | +The Flask example demonstrates integrating Gradient SDK with Flask routes for web applications. |
| 44 | + |
| 45 | +### FastAPI |
| 46 | +The FastAPI example shows how to create async endpoints that leverage the Gradient SDK's async capabilities. |
| 47 | + |
| 48 | +## Environment Variables |
| 49 | + |
| 50 | +All examples require proper authentication setup: |
| 51 | + |
| 52 | +- `DIGITALOCEAN_ACCESS_TOKEN` - For DigitalOcean API operations |
| 53 | +- `GRADIENT_MODEL_ACCESS_KEY` - For serverless inference |
| 54 | +- `GRADIENT_AGENT_ACCESS_KEY` - For agent-specific operations |
| 55 | +- `GRADIENT_AGENT_ENDPOINT` - Your deployed agent endpoint |
| 56 | + |
| 57 | +## Contributing |
| 58 | + |
| 59 | +When adding new examples: |
| 60 | + |
| 61 | +1. Follow the existing naming convention |
| 62 | +2. Include comprehensive comments |
| 63 | +3. Handle errors appropriately |
| 64 | +4. Use environment variables for configuration |
| 65 | +5. Add the example to this README |
0 commit comments