No project description provided
Project description
Llmbda FastAPI
Add your fastapi endpoints to your Relevance Notebook for chaining.
- Install:
pip install llmbda_fastapi
- Set your Relevance Auth Token from cloud.relevanceai.com/sdk/api:
SET RELEVANCE_AUTH_TOKEN=xxx
or
export RELEVANCE_AUTH_TOKEN=xxx
- 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)
- 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_component=input_components.BaseTextArea())
#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
Release history Release notifications | RSS feed
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.6.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for llmbda_fastapi-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36a2bf14f645f5231c876f58ba28f8a3d7607c58e899ee5dadeed255b63ce339 |
|
MD5 | 375e2bcee0cc289abda8445cc7aa1427 |
|
BLAKE2b-256 | 4c19b65510a86a248ef9c48399586548bfdb74b4ee401a9ca0e196ef95b179a5 |