Skip to main content

No project description provided

Project description

Llmbda FastAPI

Add your fastapi endpoints to your Relevance Notebook for chaining.

  1. Install:
pip install llmbda_fastapi
  1. Set your Relevance Auth Token from cloud.relevanceai.com/sdk/api:
SET RELEVANCE_AUTH_TOKEN=xxx

or

export RELEVANCE_AUTH_TOKEN=xxx
  1. Include these 2 lines of code:
PUBLIC_URL = "https://whereyourapiishosted.com/"

from fastapi import FastAPI
app = FastAPI()

from llmbda_fastapi import create_transformations
create_transformations(app.routes, PUBLIC_URL)

If you are working off a local computer you can use ngrok to create a public url:

pip install pyngrok
from fastapi import FastAPI
app = FastAPI()

#add this for ngrok
from pyngrok import ngrok
PUBLIC_URL = ngrok.connect(8000).public_url

#add this
from llmbda_fastapi import create_transformations
create_transformations(app.routes, PUBLIC_URL)
  1. Add these options to your existing api endpoints, for example this is a endpoint to "Run code in your local environment"
from fastapi import APIRouter, Query
from pydantic import BaseModel
from llmbda_fastapi.frontend import input_components

router = APIRouter()

#Optionally specify frontend_component to make this input be displayed as a specific frontend component
class ExecuteCodeParams(BaseModel):
    code : str = Query(..., description="Code to run", frontend=input_components.LongText())
    #the name and description of this will be automatically picked up and displayed in the notebook

class ExecuteCodeResponseParams(BaseModel):
    results : str = Query(" ", description="Return whats printed by the code")

# This is the actual transformation
def evaluate_code(code):
    print("Executing code: " + code)
    output = eval(code)
    print(output)
    return {"results" : str(output)}

# This is the API endpoint for the transformation
# The name and description of this will be automatically picked up and displayed in the notebook. Make sure to set response_model and query parameters if they are required.
@router.post("/run_code", name="Run Code", description="Run Code Locally - Test", tags=["coding"], response_model=ExecuteCodeResponseParams)
def run_code_api(commons: ExecuteCodeParams):
    return evaluate_code(commons.code)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmbda_fastapi-0.0.18.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

llmbda_fastapi-0.0.18-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file llmbda_fastapi-0.0.18.tar.gz.

File metadata

  • Download URL: llmbda_fastapi-0.0.18.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for llmbda_fastapi-0.0.18.tar.gz
Algorithm Hash digest
SHA256 3d8774eb9d33a992075e6c74da3c43faec52d81306d230289b3cad9ae8029f77
MD5 26e725dce2853815eab1058316f19ddd
BLAKE2b-256 4d06d349b1c87a2ed2c19c672d2858590c9617b0562f86da32f08c8a1b1d8107

See more details on using hashes here.

File details

Details for the file llmbda_fastapi-0.0.18-py3-none-any.whl.

File metadata

File hashes

Hashes for llmbda_fastapi-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 2ffd2572e76b510a98f5f9b4ab1874f21ccef3a1dac817f7573dfee68ffcb49f
MD5 c6fdb9884250681b4758453df0a11f56
BLAKE2b-256 7537414e7d715a0d3255a28c2b6c58f66ff937ae1f68217e8fd3c2812fb5b18f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page