Skip to content

Commit

Permalink
fixed uploaded audio file id for s3
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkersigirci committed Jan 17, 2025
1 parent ec55f2c commit 5ec509f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"aiosqlite>=0.20.0",
"asyncpg>=0.30.0",
"boto3>=1.35.92",
"chainlit>=2.0.2",
"chainlit>=2.0.3",
"huggingface-hub>=0.27.0",
"langchain>=0.3.13",
"langchain-community>=0.3.13",
Expand All @@ -46,11 +46,15 @@ dependencies = [
"prisma>=0.15.0",
"psycopg2-binary>=2.9.10",
"pydantic-settings>=2.7.0",
"yt-dlp>=2025.1.12",
]

[tool.uv]
default-groups = ["dev", "doc", "test"]

[tool.uv.sources]
chainlit = { git = "https://github.com/Chainlit/chainlit.git", subdirectory = "backend" }


[tool.pytest.ini_options]
minversion = "7.0.0"
Expand Down
12 changes: 9 additions & 3 deletions src/podflix/gui/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from langchain_community.chat_message_histories import ChatMessageHistory
from langfuse.callback import CallbackHandler as LangfuseCallbackHandler
from literalai.helper import utc_now
from loguru import logger # noqa: F401

from podflix.env_settings import env_settings
from podflix.graph.podcast_rag import compiled_graph
Expand Down Expand Up @@ -61,13 +62,18 @@ async def on_chat_start():

# Wait for the user to upload a file
while files is None:
files = await cl.AskFileMessage(
ask_file_message = cl.AskFileMessage(
content="Please upload a audio file to start the conversation",
accept=["audio/*"],
max_files=1,
max_size_mb=50,
timeout=360,
).send()
)
files = await ask_file_message.send()

# await ask_file_message.remove()
# ask_file_message.content = "DUMMY"
# await ask_file_message.update()

file = files[0]

Expand All @@ -80,7 +86,7 @@ async def on_chat_start():

# NOTE: Workaround to get s3 url of the uploaded file in the current thread
thread_id = get_current_chainlit_thread_id()
audio_url = await get_read_url_of_file(thread_id=thread_id, file_name=file.name)
audio_url = await get_read_url_of_file(thread_id=thread_id, file_id=file.id)

# Create audio element with transcript and segments
audio_element = cl.CustomElement(
Expand Down
6 changes: 3 additions & 3 deletions src/podflix/utils/chainlit_utils/data_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def get_element_url(
return element_dict.url


async def get_read_url_of_file(thread_id: str, file_name: str) -> str:
async def get_read_url_of_file(thread_id: str, file_id: str) -> str:
"""Retrieve the URL for accessing an file in a thread.
Examples:
Expand All @@ -165,7 +165,7 @@ async def get_read_url_of_file(thread_id: str, file_name: str) -> str:
Args:
thread_id: The unique identifier of the thread containing the file.
file_name: The full name of the the file to retrieve, included the file extension.
file_id: The file id of the file to retrieve.
Returns:
str: The S3 URL string of the file.
Expand All @@ -178,7 +178,7 @@ async def get_read_url_of_file(thread_id: str, file_name: str) -> str:
if cl_data_layer.storage_client is None:
raise ValueError("S3 storage client not set in data layer.")

object_key = f"threads/{thread_id}/files/{file_name}"
object_key = f"threads/{thread_id}/files/{file_id}"

return await cl_data_layer.storage_client.get_read_url(object_key=object_key)

Expand Down
21 changes: 14 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ec509f

Please sign in to comment.