From c45907503eb755b617cd685a50e09ef1a21e9da8 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Thu, 7 Nov 2024 12:24:06 +0000 Subject: [PATCH] move all python code into api --- api/src/main.py | 10 +++++----- {services => api/src/services}/__init__.py | 0 {services => api/src/services}/admin_sdk.py | 0 {services => api/src/services}/anthropic_client.py | 0 {services => api/src/services}/elevenlabs_client.py | 0 {services => api/src/services}/firestore_sdk.py | 0 {services => api/src/services}/gemini_client.py | 4 +--- {services => api/src/services}/openai_client.py | 0 {services => api/src/services}/setup.py | 0 {services => api/src/services}/storage.py | 4 +--- api/src/utils/audiocast_request.py | 3 ++- {shared_utils_pkg => api/src/utils}/audiocast_utils.py | 3 +-- api/src/utils/chat_request.py | 7 +++---- {shared_utils_pkg => api/src/utils}/chat_utils.py | 0 {shared_utils_pkg => api/src/utils}/decorators.py | 0 api/src/utils/generate_audiocast.py | 8 ++++---- api/src/utils/generate_speech_utils.py | 2 +- api/src/utils/get_audiocast.py | 8 +++----- .../utils/prompt_templates/source_content_prompt.py | 2 +- api/src/utils/prompt_templates/tts_prompt.py | 4 ++-- {shared_utils_pkg => api/src/utils}/session_manager.py | 2 +- {shared_utils_pkg => api/src/utils}/setup.py | 0 {shared_utils_pkg => api/src/utils}/waveform_utils.py | 0 shared_utils_pkg/__init__.py | 3 --- 24 files changed, 25 insertions(+), 35 deletions(-) rename {services => api/src/services}/__init__.py (100%) rename {services => api/src/services}/admin_sdk.py (100%) rename {services => api/src/services}/anthropic_client.py (100%) rename {services => api/src/services}/elevenlabs_client.py (100%) rename {services => api/src/services}/firestore_sdk.py (100%) rename {services => api/src/services}/gemini_client.py (91%) rename {services => api/src/services}/openai_client.py (100%) rename {services => api/src/services}/setup.py (100%) rename {services => api/src/services}/storage.py (96%) rename {shared_utils_pkg => api/src/utils}/audiocast_utils.py (88%) rename {shared_utils_pkg => api/src/utils}/chat_utils.py (100%) rename {shared_utils_pkg => api/src/utils}/decorators.py (100%) rename {shared_utils_pkg => api/src/utils}/session_manager.py (98%) rename {shared_utils_pkg => api/src/utils}/setup.py (100%) rename {shared_utils_pkg => api/src/utils}/waveform_utils.py (100%) delete mode 100644 shared_utils_pkg/__init__.py diff --git a/api/src/main.py b/api/src/main.py index 610bd5d..9b9ec08 100644 --- a/api/src/main.py +++ b/api/src/main.py @@ -4,6 +4,11 @@ from fastapi import BackgroundTasks, FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi_utilities import add_timer_middleware +from utils.chat_utils import ( + SessionChatMessage, + SessionChatRequest, +) +from utils.session_manager import SessionManager from src.utils.chat_request import chat_request from src.utils.generate_audiocast import ( @@ -12,11 +17,6 @@ generate_audiocast, ) from src.utils.get_audiocast import get_audiocast -from shared_utils_pkg.chat_utils import ( - SessionChatMessage, - SessionChatRequest, -) -from shared_utils_pkg.session_manager import SessionManager app = FastAPI(title="Audiora", version="1.0.0") diff --git a/services/__init__.py b/api/src/services/__init__.py similarity index 100% rename from services/__init__.py rename to api/src/services/__init__.py diff --git a/services/admin_sdk.py b/api/src/services/admin_sdk.py similarity index 100% rename from services/admin_sdk.py rename to api/src/services/admin_sdk.py diff --git a/services/anthropic_client.py b/api/src/services/anthropic_client.py similarity index 100% rename from services/anthropic_client.py rename to api/src/services/anthropic_client.py diff --git a/services/elevenlabs_client.py b/api/src/services/elevenlabs_client.py similarity index 100% rename from services/elevenlabs_client.py rename to api/src/services/elevenlabs_client.py diff --git a/services/firestore_sdk.py b/api/src/services/firestore_sdk.py similarity index 100% rename from services/firestore_sdk.py rename to api/src/services/firestore_sdk.py diff --git a/services/gemini_client.py b/api/src/services/gemini_client.py similarity index 91% rename from services/gemini_client.py rename to api/src/services/gemini_client.py index f90ecd7..e4f0aed 100644 --- a/services/gemini_client.py +++ b/api/src/services/gemini_client.py @@ -11,9 +11,7 @@ def get_gemini(): return genai -ModelName = Literal[ - "gemini-1.5-flash-002", "gemini-1.5-pro-002", "gemini-1.5-pro-latest" -] +ModelName = Literal["gemini-1.5-flash-002", "gemini-1.5-pro-002", "gemini-1.5-pro-latest"] @dataclass diff --git a/services/openai_client.py b/api/src/services/openai_client.py similarity index 100% rename from services/openai_client.py rename to api/src/services/openai_client.py diff --git a/services/setup.py b/api/src/services/setup.py similarity index 100% rename from services/setup.py rename to api/src/services/setup.py diff --git a/services/storage.py b/api/src/services/storage.py similarity index 96% rename from services/storage.py rename to api/src/services/storage.py index c2411c0..bb8c661 100644 --- a/services/storage.py +++ b/api/src/services/storage.py @@ -34,9 +34,7 @@ def check_blob_exists(self, root_path: str, filename: str): blobs = listBlobs(prefix=root_path) return any(blob.name == blobname for blob in blobs) - def upload_to_gcs( - self, item: str | Path | BytesIO, blobname: str, params: UploadItemParams - ): + def upload_to_gcs(self, item: str | Path | BytesIO, blobname: str, params: UploadItemParams): """upload item to GCS""" blob = bucket.blob(blobname) blob.content_type = params.content_type diff --git a/api/src/utils/audiocast_request.py b/api/src/utils/audiocast_request.py index 9ad52c9..e529539 100644 --- a/api/src/utils/audiocast_request.py +++ b/api/src/utils/audiocast_request.py @@ -4,10 +4,11 @@ from services.anthropic_client import get_anthropic_sync from services.gemini_client import GeminiConfig, generate_content from services.openai_client import get_openai +from utils.chat_utils import ContentCategory + from src.utils.prompt_templates.source_content_prompt import get_content_source_prompt from src.utils.prompt_templates.streamline_audio import streamline_audio_script_prompt from src.utils.prompt_templates.tts_prompt import Metadata, TTSPromptMaker -from shared_utils_pkg.chat_utils import ContentCategory def generate_source_content(category: ContentCategory, summary: str): diff --git a/shared_utils_pkg/audiocast_utils.py b/api/src/utils/audiocast_utils.py similarity index 88% rename from shared_utils_pkg/audiocast_utils.py rename to api/src/utils/audiocast_utils.py index 77a4f52..d99ffe3 100644 --- a/shared_utils_pkg/audiocast_utils.py +++ b/api/src/utils/audiocast_utils.py @@ -1,8 +1,7 @@ from typing import TypedDict from pydantic import BaseModel - -from shared_utils_pkg.chat_utils import ContentCategory +from utils.chat_utils import ContentCategory class GenerateAudioCastRequest(BaseModel): diff --git a/api/src/utils/chat_request.py b/api/src/utils/chat_request.py index 5aea5cf..fcfda8e 100644 --- a/api/src/utils/chat_request.py +++ b/api/src/utils/chat_request.py @@ -1,7 +1,7 @@ from typing import Any, Callable, List, Optional from services.openai_client import get_openai -from shared_utils_pkg.chat_utils import ContentCategory, SessionChatMessage +from utils.chat_utils import ContentCategory, SessionChatMessage def get_system_message(content_category: ContentCategory): @@ -15,9 +15,9 @@ def get_system_message(content_category: ContentCategory): GENERAL IDEA AND WORKFLOW: 1. A user comes to you with a request for an audiocast of type {content_category}. - 2. You need to ask the user questions (elicitation) to understand what kind of audiocast they want to listen to. + 2. You need to ask the user questions (elicitation) to understand what kind of audiocast they want to listen to. 3. Once you have enough context, within 3-5 exchanges, you should terminate the conversation. - + IMPORTANT NOTES: 1. Your task is to understand the user's request only by eliciting questions. 2. Do not generate the audiocast or any other content yourself. @@ -57,4 +57,3 @@ def generator(): on_finish(text) return generator() - diff --git a/shared_utils_pkg/chat_utils.py b/api/src/utils/chat_utils.py similarity index 100% rename from shared_utils_pkg/chat_utils.py rename to api/src/utils/chat_utils.py diff --git a/shared_utils_pkg/decorators.py b/api/src/utils/decorators.py similarity index 100% rename from shared_utils_pkg/decorators.py rename to api/src/utils/decorators.py diff --git a/api/src/utils/generate_audiocast.py b/api/src/utils/generate_audiocast.py index 98ba363..20f845f 100644 --- a/api/src/utils/generate_audiocast.py +++ b/api/src/utils/generate_audiocast.py @@ -1,14 +1,14 @@ from datetime import datetime from fastapi import BackgroundTasks, HTTPException - from services.storage import StorageManager -from shared_utils_pkg.audiocast_utils import ( +from utils.audiocast_utils import ( GenerateAudioCastRequest, GenerateAudioCastResponse, ) -from shared_utils_pkg.session_manager import SessionManager -from shared_utils_pkg.waveform_utils import WaveformUtils +from utils.session_manager import SessionManager +from utils.waveform_utils import WaveformUtils + from src.utils.audio_manager import AudioManager, AudioManagerConfig from src.utils.audiocast_request import AudioScriptMaker, generate_source_content diff --git a/api/src/utils/generate_speech_utils.py b/api/src/utils/generate_speech_utils.py index 430ac05..dfc0d14 100644 --- a/api/src/utils/generate_speech_utils.py +++ b/api/src/utils/generate_speech_utils.py @@ -4,7 +4,7 @@ from services.elevenlabs_client import get_elevenlabs_client from services.openai_client import get_openai -from shared_utils_pkg.decorators import process_time +from utils.decorators import process_time TTSProvider = Literal["openai", "elevenlabs"] diff --git a/api/src/utils/get_audiocast.py b/api/src/utils/get_audiocast.py index 246827e..8405b59 100644 --- a/api/src/utils/get_audiocast.py +++ b/api/src/utils/get_audiocast.py @@ -1,12 +1,12 @@ from datetime import datetime from fastapi import HTTPException - from services.storage import StorageManager +from utils.session_manager import SessionManager + from src.utils.generate_audiocast import ( GenerateAudioCastResponse, ) -from shared_utils_pkg.session_manager import SessionManager def get_audiocast(session_id: str): @@ -29,9 +29,7 @@ def get_audiocast(session_id: str): created_at = None if session_data.created_at: - created_at = datetime.fromisoformat(session_data.created_at).strftime( - "%Y-%m-%d %H:%M" - ) + created_at = datetime.fromisoformat(session_data.created_at).strftime("%Y-%m-%d %H:%M") return GenerateAudioCastResponse( url=filepath, diff --git a/api/src/utils/prompt_templates/source_content_prompt.py b/api/src/utils/prompt_templates/source_content_prompt.py index 6c431aa..a660c16 100644 --- a/api/src/utils/prompt_templates/source_content_prompt.py +++ b/api/src/utils/prompt_templates/source_content_prompt.py @@ -1,4 +1,4 @@ -from shared_utils_pkg.chat_utils import ContentCategory, category_qualifiers +from utils.chat_utils import ContentCategory, category_qualifiers def get_content_source_prompt(category: ContentCategory, summary: str): diff --git a/api/src/utils/prompt_templates/tts_prompt.py b/api/src/utils/prompt_templates/tts_prompt.py index 161aa40..f1ad508 100644 --- a/api/src/utils/prompt_templates/tts_prompt.py +++ b/api/src/utils/prompt_templates/tts_prompt.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from shared_utils_pkg.chat_utils import ContentCategory, category_qualifiers +from utils.chat_utils import ContentCategory, category_qualifiers @dataclass @@ -24,7 +24,7 @@ def get_system_prompt(self, source_content: str) -> str: Generate an optimized system prompt for converting a source content into the appropriate format. """ return f"""You're a super-intelligent AI who generates different forms, styles and genres of audiocast script. - + Your task is to transform the following source content into an engaging {self.category} TTS-optimized audiocast script. Source Content: {source_content} diff --git a/shared_utils_pkg/session_manager.py b/api/src/utils/session_manager.py similarity index 98% rename from shared_utils_pkg/session_manager.py rename to api/src/utils/session_manager.py index 4fc7251..3dd96da 100644 --- a/shared_utils_pkg/session_manager.py +++ b/api/src/utils/session_manager.py @@ -8,7 +8,7 @@ arrayUnion, collections, ) -from shared_utils_pkg.chat_utils import SessionChatMessage +from utils.chat_utils import SessionChatMessage @dataclass diff --git a/shared_utils_pkg/setup.py b/api/src/utils/setup.py similarity index 100% rename from shared_utils_pkg/setup.py rename to api/src/utils/setup.py diff --git a/shared_utils_pkg/waveform_utils.py b/api/src/utils/waveform_utils.py similarity index 100% rename from shared_utils_pkg/waveform_utils.py rename to api/src/utils/waveform_utils.py diff --git a/shared_utils_pkg/__init__.py b/shared_utils_pkg/__init__.py deleted file mode 100644 index bf6bd6c..0000000 --- a/shared_utils_pkg/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from dotenv import load_dotenv - -load_dotenv()