Skip to content

blaxel-templates/template-openai-py

Repository files navigation

Blaxel OpenAI Agent

Blaxel

License: MIT Python 3.10+ OpenAI GPT-4

A template implementation of a conversational agent using OpenAI Assistants API and GPT-4. This agent demonstrates the power of OpenAI Assistants for building interactive AI agents with advanced tool integration capabilities and streaming responses.

📑 Table of Contents

✨ Features

  • Interactive conversational interface using OpenAI Assistants API
  • Tool integration support (including weather and search capabilities)
  • Streaming responses for real-time interaction
  • Built on OpenAI Assistants for sophisticated agent orchestration
  • Function calling capabilities with custom tools
  • Easy deployment and integration with Blaxel platform

🚀 Quick Start

For those who want to get up and running quickly:

# Clone the repository
git clone https://github.com/blaxel-ai/template-openai-py.git

# Navigate to the project directory
cd template-openai-py

# Install dependencies
uv sync

# Start the server
bl serve --hotreload

# In another terminal, test the agent
bl chat --local blaxel-agent

📋 Prerequisites

  • Python: 3.10 or later
  • UV: An extremely fast Python package and project manager, written in Rust
  • Blaxel Platform Setup: Complete Blaxel setup by following the quickstart guide
    • Blaxel CLI: Ensure you have the Blaxel CLI installed. If not, install it globally:
      curl -fsSL https://raw.githubusercontent.com/blaxel-ai/toolkit/main/install.sh | BINDIR=/usr/local/bin sudo -E sh
    • Blaxel login: Login to Blaxel platform
      bl login YOUR-WORKSPACE

💻 Installation

Clone the repository and install dependencies:

git clone https://github.com/blaxel-ai/template-openai-py.git
cd template-openai-py
uv sync

🔧 Usage

Running Locally

Start the development server with hot reloading:

bl serve --hotreload

For production run:

bl serve

Note: The development server automatically restarts when you make changes to the source code.

Testing

You can test your OpenAI agent locally:

# Using the Blaxel CLI chat interface
bl chat --local blaxel-agent

Example queries you can test:

What is the weather in Paris?
Help me analyze some data
Can you assist with writing a summary?

You can also run it directly with specific input:

bl run agent blaxel-agent --local --data '{"input": "What is the weather in Paris?"}'

Deployment

When you are ready to deploy your agent:

bl deploy

This command uses your code and the configuration files under the .blaxel directory to deploy your OpenAI agent on the Blaxel platform.

📁 Project Structure

  • src/main.py - Application entry point and FastAPI server setup
  • src/agent.py - Core agent implementation with OpenAI Assistants integration
  • src/server/ - Server implementation and routing
    • router.py - API route definitions
    • middleware.py - Request/response middleware
  • pyproject.toml - UV package manager configuration with dependencies
  • blaxel.toml - Blaxel deployment configuration
  • .env.example - Environment variables template
  • LICENSE - MIT license file

❓ Troubleshooting

Common Issues

  1. Blaxel Platform Issues:

    • Ensure you're logged in to your workspace: bl login MY-WORKSPACE
    • Verify models are available: bl get models
    • Check that functions exist: bl get functions
  2. OpenAI API Connection Issues:

    • Verify your OpenAI API key is valid and has sufficient credits
    • Check API rate limits and usage quotas
    • Ensure network connectivity to OpenAI endpoints
    • Test API access with a simple request
  3. Assistant Configuration Issues:

    • Verify assistant creation and configuration in the code
    • Check assistant permissions and capabilities
    • Ensure tools are properly registered with the assistant
    • Monitor assistant usage and performance
  4. Function Calling Problems:

    • Verify tool function definitions and schemas
    • Check function parameter validation
    • Ensure function execution permissions
    • Review function response formats
  5. Python Environment Issues:

    • Make sure you have Python 3.10+
    • Try uv sync --upgrade to update dependencies
    • Check for conflicting package versions
    • Verify virtual environment activation with UV

For more help, please submit an issue on GitHub.

👥 Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/amazing-feature
  3. Commit your changes:
    git commit -m 'Add amazing feature'
  4. Push to the branch:
    git push origin feature/amazing-feature
  5. Submit a Pull Request

Please make sure to update tests as appropriate and follow the code style of the project.

🆘 Support

If you need help with this template:

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

A production-ready TypeScript template for building AI agents using OpenAI Agents in Blaxel.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages