Skip to content

Commit

Permalink
install setup tools and create a setup file for utils_pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 2, 2024
1 parent 65ed0d8 commit a71e6d9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ google-cloud-storage
google-api-python-client
google-generativeai

watchdog
ruff
watchdog
setuptools
40 changes: 29 additions & 11 deletions server/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
import asyncio
import os
import sys
from pathlib import Path

import uvloop
from dotenv import load_dotenv

from services.admin_sdk import init_admin_sdk

### Begin: Add the project root to sys.path
# Calculate the path to the root of the project, assuming the script is in the 'streamlit' directory
## Begin: Add the project root to sys.path
project_root = Path(__file__).parent.parent.resolve()
# Add the project root to sys.path
sys.path.append(str(project_root))
### End: Add the project root to sys.path


asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

print("running uvloop as the event loop policy for asyncio")
print("running uvloop as event loop policy for asyncio")

load_dotenv()
# init firebase admin sdk
init_admin_sdk()


def init_shared_packages(paths: list[str]):
# Add the shared module directory to the Python path
for path in paths:
pkg_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", path))
sys.path.append(pkg_path)


def initialize():
from services.admin_sdk import init_admin_sdk

init_admin_sdk()


def print_project_meta():
print(f"Project root: {project_root}")
print(f"Python version: {sys.version}")
print(f"Current working directory: {os.getcwd()}")


init_shared_packages(["services", "utils"])

initialize()

print_project_meta()
21 changes: 13 additions & 8 deletions server/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
from time import time
from typing import Callable, Optional

from fastapi import FastAPI, HTTPException, Request
from fastapi import BackgroundTasks, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi_utilities import add_timer_middleware
from pydantic import BaseModel

from services.storage import StorageManager
from utils.audio_manager import AudioManager, AudioManagerConfig
from utils.audiocast_request import AudioScriptMaker, generate_source_content
from utils.chat_request import chat_request
from utils.chat_utils import (
from utils_pkg.audio_manager import AudioManager, AudioManagerConfig
from utils_pkg.audiocast_request import AudioScriptMaker, generate_source_content
from utils_pkg.chat_request import chat_request
from app.src.utils.chat_utils import (
SessionChatMessage,
SessionChatRequest,
content_categories,
)
from utils.session_manager import SessionManager
from app.src.utils.session_manager import SessionManager


@asynccontextmanager
Expand Down Expand Up @@ -81,14 +81,19 @@ class GenerateAudioCastResponse(BaseModel):


@app.post("/chat/{session_id}", response_model=str)
async def chat_endpoint(session_id: str, request: SessionChatRequest):
async def chat_endpoint(
session_id: str, request: SessionChatRequest, background_tasks: BackgroundTasks
):
try:
content_category = request.content_category
db = SessionManager(session_id)
db._add_chat(request.message)

def on_finish(text: str):
db._add_chat(SessionChatMessage(role="assistant", content=text))
background_tasks.add_task(
db._add_chat,
SessionChatMessage(role="assistant", content=text),
)

response = chat_request(
content_category=content_category,
Expand Down
10 changes: 10 additions & 0 deletions utils_pkg/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import find_packages, setup

setup(
name="utils_pkg",
version="1.0.0",
packages=find_packages(),
install_requires=[
# List any dependencies here
],
)

0 comments on commit a71e6d9

Please sign in to comment.