Package: relevanceai
Relevance AI - The home of your AI Workforce🔥 Use Relevance to build AI agents for your AI workforce:⚡ Connect your python api's to tools for Agents or custom actions for GPTs.🚀 Share your tools as AI web apps with your team to use.Sign up for a free account ->🧠 DocumentationTypeLinkHome PageHome PagePlatformPlatformDeveloper DocumentationDocumentationGetting StartedInstallation:pip install relevanceaiThis example uses fastapi and uvicorn so lets install that too:pip install fastapipip install uvicorn[standard]Create your FastAPI app -skip if you already have oneHere is a quick example of a FastAPI app:fromfastapiimportFastAPIapp=FastAPI()classHelloWorldParams(BaseModel):message:str=Query(...,title="Message",description="message from user")classHelloWorldResponse(BaseModel):reply:strdefhello_world(prompt):return{"reply":"hello world"}@app.post("/hello_world",name="Hello World",description="Reply always with hello world",response_model=HelloWorldResponse)defhello_world_api(commons:HelloWorldParams):returnhello_world(commons.message)Describe for your tools
Make sure to give your FastAPI endpoints as much descrition as possible. These provided descriptions are utilized in the agent prompt so that the Agent can better understand your tools.For example:
Add atitleanddescriptionfor the inputs of your tool, explaining what they are and what kind of value to provide:classHelloWorldParams(BaseModel):message:str=Query(...,description="message from user")Add anameanddescriptionabout the tool explaining when to use it and what it does:@app.post("/hello_world",name="Hello World",description="Reply always with hello world",response_model=HelloWorldResponse)Relevance AI will automatically take these values from your fastapi app and use it to create a prompt for the agent.Lets connect it live to Relevance AI
In short all it takes to connect is to add the following lines to your app:fromrelevanceai.connect.fastapiimportconnect_fastapi_to_raiconnect_fastapi_to_rai(app.routes,PUBLIC_URL)WherePUBLIC_URLis the public url of your app. For examplehttps://myapp.com.If you are working locally and dont have a public url you can usengrokto create a public url for your app.All togetherfrompyngrokimportngrokPUBLIC_URL=ngrok.connect(8000).public_urlPutting this all togetherfromfastapiimportFastAPIfromfastapi.middleware.corsimportCORSMiddlewarefromfastapiimportAPIRouter,QueryfrompydanticimportBaseModelfromtypingimportList#create FastAPI appapp=FastAPI()#add cors middleware to allow all originsapp.add_middleware(CORSMiddleware,allow_origins=['*'],allow_credentials=True,allow_methods=['*'],allow_headers=['*'],)classHelloWorldParams(BaseModel):message:str=Query(...,description="message from user")classHelloWorldResponse(BaseModel):reply:strdefhello_world(prompt):return{"reply":"hello world"}@app.post("/hello_world",name="Hello World",description="Reply always with hello world",response_model=HelloWorldResponse)defhello_world_api(commons:HelloWorldParams):returnhello_world(commons.message)#If you are deploying the api from a local computer use ngrok to expose a public url.frompyngrokimportngrokPUBLIC_URL=ngrok.connect(8000).public_url#This will create a Tool in Relevance AI that will call your API endpointfromrelevanceai.connect.fastapiimportconnect_fastapi_to_raiconnect_fastapi_to_rai(app.routes,PUBLIC_URL)Roadmap & ContributionMore examples and api connectors coming soon. Feel free to contribute to this repo.