Giter VIP home page Giter VIP logo

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 ->

๐Ÿง  Documentation

Type Link
Home Page Home Page
Platform Platform
Developer Documentation Documentation

Getting Started

1. Installation:

pip install relevanceai

This example uses fastapi and uvicorn so lets install that too: pip install fastapi pip install uvicorn[standard]

2. Create your FastAPI app - skip if you already have one

Here is a quick example of a FastAPI app:

from fastapi import FastAPI
app = FastAPI()

class HelloWorldParams(BaseModel):
    message : str = Query(..., title="Message", description="message from user")

class HelloWorldResponse(BaseModel):
    reply : str

def hello_world(prompt):
    return {"reply" : "hello world"}

@app.post("/hello_world", name="Hello World", description="Reply always with hello world", response_model=HelloWorldResponse)
def hello_world_api(commons: HelloWorldParams):
    return hello_world(commons.message)

3. 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 a title and description for the inputs of your tool, explaining what they are and what kind of value to provide:

class HelloWorldParams(BaseModel):
    message : str = Query(..., description="message from user")

Add a name and description about 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.

4. Lets connect it live to Relevance AI

In short all it takes to connect is to add the following lines to your app:

from relevanceai.connect.fastapi import connect_fastapi_to_rai

connect_fastapi_to_rai(app.routes, PUBLIC_URL)

Where PUBLIC_URL is the public url of your app. For example https://myapp.com.

If you are working locally and dont have a public url you can use ngrok to create a public url for your app.

from pyngrok import ngrok
PUBLIC_URL = ngrok.connect(8000).public_url

Full code to copy and paste

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi import APIRouter, Query
from pydantic import BaseModel
from typing import List

#create FastAPI app
app = FastAPI()
#add cors middleware to allow all origins
app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*'],
)

class HelloWorldParams(BaseModel):
    message : str = Query(..., description="message from user")

class HelloWorldResponse(BaseModel):
    reply : str

def hello_world(prompt):
    return {"reply" : "hello world"}

@app.post(
        "/hello_world", name="Hello World", description="Reply always with hello world", response_model=HelloWorldResponse
    )
def hello_world_api(commons: HelloWorldParams):
    return hello_world(commons.message)

#If you are deploying the api from a local computer use ngrok to expose a public url.
from pyngrok import ngrok
PUBLIC_URL = ngrok.connect(8000).public_url

#This will create a Tool in Relevance AI that will call your API endpoint
from relevanceai.connect.fastapi import connect_fastapi_to_rai
connect_fastapi_to_rai(app.routes, PUBLIC_URL)

Roadmap & Contribution

More examples and api connectors coming soon. Feel free to contribute to this repo.

Relevance AI's Projects

flowchartgpt icon flowchartgpt

Turn descriptions into flowcharts in seconds ๐Ÿช„

llmcache.com icon llmcache.com

llmcache.com - how to build a cache for LLMs with Relevance AI

og icon og

Open Graph image generator for Relevance AI

python-doc-utils icon python-doc-utils

Utilies for documents including accessing, writing and bulk editing in Python

relevance-js-sdk icon relevance-js-sdk

Vector Database by Relevance AI. Fast and simple with support for chaining.

relevanceai icon relevanceai

Home of the AI workforce - Multi-agent system, AI agents & tools

sagemaker-run-notebook icon sagemaker-run-notebook

Tools to run Jupyter notebooks as jobs in Amazon SageMaker - ad hoc, on a schedule, or in response to events

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.