Skip to content

Commit

Permalink
move all python code into api
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 7, 2024
1 parent c30cad8 commit c459075
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 35 deletions.
10 changes: 5 additions & 5 deletions api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions services/storage.py → api/src/services/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion api/src/utils/audiocast_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
7 changes: 3 additions & 4 deletions api/src/utils/chat_request.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -57,4 +57,3 @@ def generator():
on_finish(text)

return generator()

File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions api/src/utils/generate_audiocast.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/generate_speech_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
8 changes: 3 additions & 5 deletions api/src/utils/get_audiocast.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/prompt_templates/source_content_prompt.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions api/src/utils/prompt_templates/tts_prompt.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
arrayUnion,
collections,
)
from shared_utils_pkg.chat_utils import SessionChatMessage
from utils.chat_utils import SessionChatMessage


@dataclass
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions shared_utils_pkg/__init__.py

This file was deleted.

0 comments on commit c459075

Please sign in to comment.