-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
3,557 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.git | ||
.DS_Store | ||
.gitignore | ||
.dockerignore | ||
|
||
# PyCharm specific folder | ||
|
||
.idea | ||
|
||
# Environments | ||
|
||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
|
||
# UI | ||
ui/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DATABASE_URL= | ||
DATABASE_MIGRATION_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[flake8] | ||
exclude = | ||
venv | ||
.venv | ||
__pycache__ | ||
notebooks | ||
# Recommend matching the black line length (default 88), | ||
# rather than using the flake8 default of 79: | ||
max-line-length = 88 | ||
extend-ignore = | ||
# See https://github.com/PyCQA/pycodestyle/issues/373 | ||
E203, | ||
E501, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: lint | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
env: | ||
POETRY_VERSION: "1.4.2" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install poetry | ||
run: | | ||
pipx install poetry==$POETRY_VERSION | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: poetry | ||
- name: Install dependencies | ||
run: | | ||
cd libs/superagent | ||
poetry install | ||
- name: Analysing the code with our lint | ||
run: | | ||
cd libs/superagent | ||
make lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
__pycache__ | ||
*.pyc | ||
.env | ||
.env*.local | ||
.venv | ||
superenv/ | ||
.DS_Store | ||
venv/ | ||
/.vscode | ||
/.codesandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM python:3.11 AS builder | ||
# Use the python latest image | ||
|
||
RUN pip install poetry | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
WORKDIR /app | ||
|
||
# Copy only dependency files for layer caching | ||
COPY pyproject.toml poetry.lock ./ | ||
|
||
# Install the required packages of the application into .venv | ||
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR | ||
|
||
FROM python:3.11 AS runtime | ||
|
||
ENV PATH="/app/.venv/bin:$PATH" | ||
ENV PORT="8080" | ||
|
||
COPY --from=builder /app/.venv /app/.venv | ||
|
||
COPY . ./ | ||
|
||
RUN prisma generate | ||
|
||
# Bind the port and refer to the app.py app | ||
CMD exec gunicorn --bind :$PORT --workers 2 --timeout 0 --worker-class uvicorn.workers.UvicornWorker --threads 8 lib.main:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
format: | ||
poetry run black . | ||
poetry run ruff --select I --fix . | ||
poetry run vulture . | ||
|
||
PYTHON_FILES=. | ||
lint: PYTHON_FILES=. | ||
lint_diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d master | grep -E '\.py$$') | ||
|
||
lint lint_diff: | ||
poetry run black $(PYTHON_FILES) --check | ||
poetry run ruff . | ||
poetry run vulture . |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from fastapi import APIRouter | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post( | ||
"/ingest", | ||
name="ingest", | ||
description="Ingest data", | ||
) | ||
async def ingest(): | ||
"""Endpoint for ingesting data""" | ||
return {"success": True, "data": None} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from fastapi import APIRouter | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post( | ||
"/invoke", | ||
name="invoke", | ||
description="Invoke model", | ||
) | ||
async def invoke(): | ||
"""Endpoint for invoking model""" | ||
return {"success": True, "data": None} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logging | ||
import time | ||
|
||
import colorlog | ||
from fastapi import FastAPI, Request | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
from lib.routers import router | ||
from lib.utils.prisma import prisma | ||
|
||
# Create a color formatter | ||
formatter = colorlog.ColoredFormatter( | ||
"%(log_color)s%(levelname)s: %(message)s", | ||
log_colors={ | ||
"DEBUG": "cyan", | ||
"INFO": "green", | ||
"WARNING": "yellow", | ||
"ERROR": "red", | ||
"CRITICAL": "bold_red", | ||
}, | ||
secondary_log_colors={}, | ||
style="%", | ||
) # Create a console handler and set the formatter | ||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="%(levelname)s: %(message)s", | ||
handlers=[console_handler], | ||
force=True, | ||
) | ||
|
||
app = FastAPI( | ||
title="Superagent", | ||
docs_url="/", | ||
description="Build, manage and deploy LLM-powered Agents", | ||
version="0.1.0", | ||
) | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
|
||
@app.middleware("http") | ||
async def add_process_time_header(request: Request, call_next): | ||
start_time = time.time() | ||
response = await call_next(request) | ||
process_time = time.time() - start_time | ||
print(f"Total request time: {process_time} secs") | ||
return response | ||
|
||
|
||
@app.on_event("startup") | ||
async def startup(): | ||
await prisma.connect() | ||
|
||
|
||
@app.on_event("shutdown") | ||
async def shutdown(): | ||
await prisma.disconnect() | ||
|
||
|
||
app.include_router(router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generator client { | ||
provider = "prisma-client-py" | ||
interface = "asyncio" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
shadowDatabaseUrl = env("DATABASE_SHADOW_URL") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from fastapi import APIRouter | ||
|
||
from lib.api import ingest, invoke | ||
|
||
router = APIRouter() | ||
api_prefix = "/api/v1" | ||
|
||
router.include_router(ingest.router, tags=["Ingest"], prefix=api_prefix) | ||
router.include_router(invoke.router, tags=["Invoke"], prefix=api_prefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from prisma import Prisma | ||
|
||
prisma = Prisma() |
Empty file.
Oops, something went wrong.