-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
8dded5f
commit 84c0f47
Showing
26 changed files
with
232 additions
and
352 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
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.10 | ||
|
||
# Install Poetry | ||
RUN pip install --no-cache-dir poetry | ||
|
||
# Set the working directory in the container | ||
WORKDIR /usr/src/app | ||
|
||
# Copy only pyproject.toml and poetry.lock (if available) to cache dependencies installation | ||
COPY pyproject.toml poetry.lock* /usr/src/app/ | ||
|
||
# Install dependencies from pyproject.toml using Poetry | ||
# Note: The `--no-root` option is used to prevent Poetry from installing the project package at this stage. | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --no-dev --no-interaction --no-ansi | ||
|
||
# Copy the current directory contents into the container at /usr/src/app | ||
COPY . /usr/src/app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Make port 8000 available to the world outside this container | ||
# Make port 8003 available to the world outside this container | ||
EXPOSE 8000 | ||
|
||
|
||
# Run app.py when the container launches | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--reload"] | ||
# Run app.py when the container launches using Poetry | ||
CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--reload"] |
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
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
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 |
---|---|---|
@@ -1,36 +1,47 @@ | ||
from fastapi import APIRouter, HTTPException, Body, Depends, Request | ||
|
||
from .model import ListenerCreateRequest | ||
from .model import ConnectionInformation | ||
from .service import ListenerAsyncService | ||
|
||
router = APIRouter() | ||
|
||
connection_info = { | ||
"db": "postgres", | ||
"user": "postgres.ajbmxtlpktvtcbtxxikl", | ||
"password": "qQbj2eAbTXHAfzOQ", | ||
"host": "aws-0-us-east-1.pooler.supabase.com", | ||
"table_name": "documents", | ||
# "port": 5434, | ||
} | ||
|
||
listener_id = "123" | ||
|
||
listener_info = { | ||
"table_name": "my_table_name", | ||
"filters": {"status": "processing"}, | ||
"embedding": { | ||
"model": "sentence-transformers/all-MiniLM-L6-v2", | ||
"field": "file_url", | ||
"embed_type": "url", # url or in-place | ||
}, | ||
} | ||
|
||
|
||
@router.post("/") | ||
async def create_listener( | ||
request: Request, | ||
listener: ListenerCreateRequest = Body(...), | ||
# connection_info: ConnectionInformation = Body(...), | ||
): | ||
# init listener service | ||
listener_service = ListenerAsyncService(request.index_id) | ||
listener_service.init_client(request.api_key) | ||
|
||
if await listener_service.get_listener( | ||
listener.provider_id, listener.listener_name | ||
): | ||
raise HTTPException( | ||
status_code=400, | ||
detail="Listener with this provider and name already exists", | ||
) | ||
|
||
resp = await listener_service.create_listener(listener.model_dump(by_alias=True)) | ||
resp = await listener_service.create_listener(connection_info) | ||
|
||
return {"message": "Listener created", "data": resp} | ||
|
||
|
||
@router.post("/{provider_id}") | ||
def receive_payload(request: Request): | ||
# check if the provider_id exists in index_id | ||
# if not, return 404 | ||
# check if provider_id has a serverless function | ||
# if it does, run it | ||
# if it doesn't return 404 | ||
print(request) | ||
return {"message": "received"} |
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
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 |
---|---|---|
@@ -1,57 +1,27 @@ | ||
from fastapi import HTTPException | ||
from db_internal.service import BaseAsyncDBService | ||
|
||
from utilities.helpers import unique_name, generate_function_name | ||
from utilities.zipper import PackageZipper | ||
from config import parser_url | ||
from utilities.internal_requests import AsyncHttpClient | ||
|
||
from config import listener_url | ||
|
||
|
||
class ListenerAsyncService(BaseAsyncDBService): | ||
def __init__(self, index_id): | ||
super().__init__("listeners", index_id) | ||
self.package_creator_url = parser_url + "/process/package" | ||
self.listener_url = listener_url | ||
|
||
async def get_listener(self, provider_id, listener_name): | ||
result = await self.get_one( | ||
{"provider_id": provider_id, "listener_name": listener_name} | ||
def init_client(self, api_key): | ||
self.http_client = AsyncHttpClient( | ||
url=self.listener_url, | ||
headers={"Authorization": f"Bearer {api_key}"}, | ||
) | ||
return result | ||
|
||
async def create_listener(self, listener_dict): | ||
async def create_listener(self, connection_info): | ||
try: | ||
# create package name | ||
code_function_name = generate_function_name( | ||
self.index_id, | ||
listener_dict["provider_id"], | ||
listener_dict["listener_name"], | ||
) | ||
# create package | ||
new_package = self._create_new_package( | ||
code_function_name, | ||
listener_dict["code_as_string"], | ||
listener_dict["settings"].get("requirements", []), | ||
listener_dict["settings"].get("python_version", "python3.10"), | ||
) | ||
# store in db | ||
# await self.create_one( | ||
|
||
# ) | ||
|
||
return await self.http_client.post(connection_info) | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=str(e)) | ||
|
||
async def process_payload(self): | ||
# queue | ||
async def get_listener_status(self, connection_info): | ||
pass | ||
|
||
def _create_new_package( | ||
self, code_function_name, code_input, requirements, python_version | ||
): | ||
obj = { | ||
"function_name": code_function_name, | ||
"code_as_string": code_input, | ||
"requirements": requirements, | ||
"python_version": python_version, | ||
} | ||
zipper = PackageZipper(obj, self.package_creator_url) | ||
return zipper.get_s3_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
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
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
from pydantic import BaseModel | ||
from typing import List, Union | ||
from pydantic import BaseModel, validator, ValidationError | ||
from typing import List, Union, Optional | ||
from enum import Enum | ||
|
||
|
||
class SupportedModalities(str, Enum): | ||
text = "text" | ||
image = "image" | ||
audio = "audio" | ||
video = "video" | ||
|
||
|
||
class ParseFileRequest(BaseModel): | ||
file_url: str | ||
file_url: Optional[str] = None | ||
contents: Optional[str] = None | ||
|
||
@validator("contents", pre=True, always=True) | ||
def check_file_data(cls, v, values, **kwargs): | ||
file_url = values.get("file_url") if "file_url" in values else None | ||
contents = v | ||
if file_url is None and contents is None: | ||
raise ValueError("Either 'file_url' or 'contents' must be provided.") | ||
if file_url is not None and contents is not None: | ||
raise ValueError("Only one of 'file_url' or 'contents' can be provided.") | ||
return v |
Oops, something went wrong.