1. Create an account and install Relevance AI
Before you get started, make sure you create an account and install Relevance AI:- Sign up for a free account at https://app.relevanceai.com and then login to your Relevance AI account.
- Install the Relevance AI library in a Python 3 environment
2. Log in to Relevance AI
Python
rai.login()
you can also set environmental variables to automatically login:
3. Connect FastAPI
3.1 Connect
The main function to connect your fastapi endpoints to Relevance AI isconnect_tools
:
- the
PUBLIC_URL
is the public url to connect to your fastapi. - the
app.routes
is the FastAPI’sapp = FastAPI()
Python
Python
pip install pyngrok
Python
nest_asyncio
if you are in a notebook environment. pip install nest-asyncio
Python
3.2 Defining the endpoint and tool
@app.post(name=..., description=...)
. Thename
anddescription
of the endpoint becomes the samename
anddescription
of the Tool. This is crucial when a tool is equipped to an agent since its used in the prompt for agents.message : str = Query(..., description="message from user")
The typing and description of endpoint parameters is automatically used when setting the user inputs for the Tool.
Python
3.3 Deploy
Once you deploy your FastAPI endpoint. You should be able to see the end point show up as a Tool in your Tools list. It should also have a “SDK” badge on it.Example of a full code:
Python