Metadata-Version: 2.1
Name: llmbda-fastapi
Version: 0.0.15
Home-page: https://relevanceai.com/
Author: Relevance AI
Author-email: jacky@relevanceai.com
Description-Content-Type: text/markdown
Requires-Dist: anyio (==3.6.2)
Requires-Dist: charset-normalizer (==3.1.0)
Requires-Dist: click (==8.1.3)
Requires-Dist: colorama (==0.4.6)
Requires-Dist: fastapi (==0.95.0)
Requires-Dist: h11 (==0.14.0)
Requires-Dist: idna (==3.4)
Requires-Dist: pydantic (==1.10.7)
Requires-Dist: python-dateutil (==2.8.2)
Requires-Dist: pytz (==2023.3)
Requires-Dist: PyYAML (==6.0)
Requires-Dist: requests (==2.28.2)
Requires-Dist: six (==1.16.0)
Requires-Dist: sniffio (==1.3.0)
Requires-Dist: starlette (==0.26.1)
Requires-Dist: tqdm (==4.65.0)
Requires-Dist: typing-extensions (==4.5.0)
Requires-Dist: tzdata (==2023.3)
Requires-Dist: urllib3 (==1.26.15)
Requires-Dist: uvicorn (==0.21.1)
Requires-Dist: wincertstore (==0.2)

# Llmbda FastAPI

## Add your fastapi endpoints to your Relevance Notebook for chaining.
1. Install:
```
pip install llmbda_fastapi
```

2. Set your Relevance Auth Token from cloud.relevanceai.com/sdk/api:
```
SET RELEVANCE_AUTH_TOKEN=xxx
```
or
```
export RELEVANCE_AUTH_TOKEN=xxx
```

3. 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)
```

4. 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)
```
