OpenAI
Integrate Asteroid supervision into OpenAI-powered applications
Integrating Asteroid SDK with OpenAI
In this guide, we’ll explore how to integrate the Asteroid SDK with the OpenAI SDK to build AI applications that are not only powerful but also supervised and controllable. Integration with Asteroid is possible with a few lines of code.
Introduction
This guide demonstrates how to use the Asteroid SDK with OpenAI, including how to create supervised tools, manage supervision contexts, and build assistant agents that interact with OpenAI’s GPT models.
Creating Supervised Tools
Supervised tools are functions wrapped with the @supervise
decorator, allowing you to enforce policies, validations, and involve human supervisors when necessary.
The @supervise
Decorator
The @supervise
decorator adds supervision capabilities to your functions. Place the supervisor decorator above the tool definition that you provide to OpenAI.
Interacting with OpenAI Models
Use the OpenAI Chat Completion API with the Asteroid-wrapped client to interact with the model. Example code:
This example shows how to:
- Initialize the OpenAI client with Asteroid supervision
- Use the wrapped client to make chat completion requests
- Pass tools (instead of functions) to the API
Example Application
Let’s put everything together in an example where an assistant searches the internet, creates calendar events, and sends emails, all under supervision. Full example code is implemented in examples/openai/run.ipynb
with more details in the Quickstart guide example.
Conclusion
Integrating the Asteroid SDK with OpenAI models allows you to build AI applications with robust supervision capabilities. By defining supervised tools and managing the supervision context, you can ensure that your AI assistant operates within defined policies and involves human oversight when necessary.
Key takeaways:
- Define supervisors to enforce policies or require human approval.
- Use the
@supervise
decorator to add supervision to your functions. - Wrap your OpenAI client with
asteroid_openai_client
to register all supervised functions and enable supervision.