🛠️ Serving Tools Over Endpoint
Learn how to create a REST API endpoint that processes natural language requests into tool actions using Composio, OpenAI and FastAPI
Install Required Packages
First, install all necessary packages:
Set Up Environment Variables
Configure your API keys:
Replace the API keys with your actual Composio and OpenAI API keys.
Authenticate GitHub Account
If you haven’t authenticated your GitHub account, complete the authentication process.
Set up FastAPI Imports
Create a new file main.py
and add the necessary imports:
Create Request Model
Define the Pydantic model for request validation:
Pydantic ensures that incoming requests contain a valid task
field.
Initialize API Clients
Set up the OpenAI and Composio clients:
This step prepares the tools needed for GitHub interactions.
Create API Endpoint
Add the endpoint that will process tasks:
This endpoint combines OpenAI’s language understanding with Composio’s GitHub tools to process natural language requests.
Run the Server
Start your FastAPI server:
The --reload
flag enables auto-reload during development. Remove it in production.
Test the Endpoint
Test your endpoint using curl:
Use specific actions (Optional)
You can use specific actions by passing the action IDs while fetching tools. It’s recommended to limit the number of actions to 20 or fewer for optimal performance and clearer AI responses:
Was this page helpful?