Skip to content

Commit

Permalink
chainlit updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkersigirci committed Feb 5, 2025
1 parent 21c0043 commit dc6feec
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 149 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ services:
- "traefik.enable=true"
## HTTP Routers
- "traefik.http.routers.localstack-rtr.entrypoints=websecure"
- "traefik.http.routers.localstack-rtr.rule=Host(`s3.$DOMAIN_NAME`)"
- "traefik.http.routers.localstack-rtr.rule=Host(`s3-podflix.$DOMAIN_NAME`)"
## HTTP Services
- "traefik.http.routers.localstack-rtr.service=localstack-svc"
- "traefik.http.services.localstack-svc.loadbalancer.server.port=4566"
2 changes: 1 addition & 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.1.0",
"chainlit>=2.1.2",
"huggingface-hub>=0.27.0",
"langchain>=0.3.13",
"langchain-community>=0.3.13",
Expand Down
17 changes: 0 additions & 17 deletions src/podflix/gui/fasthtml_ui/copilot.py

This file was deleted.

20 changes: 20 additions & 0 deletions src/podflix/gui/fasthtml_ui/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from fasthtml.common import (
H1,
H2,
Expand All @@ -8,13 +10,17 @@
Div,
Grid,
P,
Script,
Style,
Title,
Titled,
fast_app,
)

app, rt = fast_app()

CHAINLIT_APP_ROOT = os.environ.get("CHAINLIT_APP_ROOT", "")


def get_style() -> Style:
return Style("""
Expand Down Expand Up @@ -149,3 +155,17 @@ def get():
styles = get_style()

return Title("PodFlix - Chat with your Podcasts"), styles, content


@rt("/copilot")
def get(): # noqa: F811
return Titled(
"Chainlit Copilot Demo",
Script(src="http://localhost:5000/chat/copilot/index.js"),
Script("""
window.mountChainlitWidget({
chainlitServer: "http://localhost:5000/chat",
customCssUrl: /public/copilot.css',
});
"""),
)
21 changes: 9 additions & 12 deletions src/podflix/gui/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,18 @@ async def on_action(action: cl.Action):
# await action.remove()


@cl.step(name="Mock Tool", type="tool")
async def mock_tool():
step_message = cl.Message(content="")
await step_message.stream_token("Streaming inside the mock tool.")


@cl.on_chat_start
async def on_chat_start():
set_extra_user_session_params()

await cl.context.emitter.set_commands(mock_commands)

sidebar_mock_elements = [
cl.Text(content="Here is a side text document", name="text1"),
cl.Image(
path=f"{env_settings.library_base_path}/configs/chainlit/public/banner.png",
name="banner",
),
]

await cl.ElementSidebar.set_elements(sidebar_mock_elements)
await cl.ElementSidebar.set_title("Sidebar Mock Title")


@cl.on_chat_resume
def setup_chat_resume(thread: ThreadDict):
Expand All @@ -102,6 +97,8 @@ async def on_message(msg: cl.Message):
# NOTE: Removes commands from the UI
# await cl.context.emitter.set_commands([])

# await mock_tool()

assistant_message = cl.Message(
content=" ",
author="Assistant",
Expand Down Expand Up @@ -145,7 +142,7 @@ async def on_message(msg: cl.Message):
assistant_message.actions.extend(actions)

assistant_message.content += " DUMMY_ELEMENT_NAME"
await assistant_message.send()
await assistant_message.update()

message_history.add_user_message(msg.content)
message_history.add_ai_message(assistant_message.content)
16 changes: 16 additions & 0 deletions src/podflix/utils/chainlit_utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def create_message_history_from_db_thread(
message_history.add_user_message(steps_message["output"])
elif steps_message["type"] == "assistant_message":
message_history.add_ai_message(steps_message["output"])
else:
logger.warning(f"Unknown message type: {steps_message['type']}")

return message_history

Expand Down Expand Up @@ -129,3 +131,17 @@ def set_extra_user_session_params(
def get_current_chainlit_thread_id() -> str:
"""Get the current Chainlit thread ID."""
return cl.context.session.thread_id


async def set_mock_elements():
"""Set mock elements for the sidebar."""
sidebar_mock_elements = [
cl.Text(content="Here is a side text document", name="text1"),
cl.Image(
path=f"{env_settings.library_base_path}/configs/chainlit/public/banner.png",
name="banner",
),
]

await cl.ElementSidebar.set_elements(sidebar_mock_elements)
await cl.ElementSidebar.set_title("Sidebar Mock Title")
7 changes: 6 additions & 1 deletion src/podflix/utils/hf_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ def download_gguf_hf(
# repo_id=repo_id, revision=revision, ignore_patterns=ignore_patterns
# )

# Example GGUF download
# Example GGUF Qwen download
repo_id = "Qwen/Qwen2-0.5B-Instruct-GGUF"
filename = "qwen2-0_5b-instruct-fp16.gguf"
revision = "main"

# Example GGUF Deepseek download
repo_id = "bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF"
filename = "DeepSeek-R1-Distill-Qwen-1.5B-Q8_0.gguf"
revision = "main"

gguf_path = download_gguf_hf(
repo_id=repo_id,
filename=filename,
Expand Down
Loading

0 comments on commit dc6feec

Please sign in to comment.