Skip to content

Commit 4fb7cd9

Browse files
authored
Merge pull request #2 from mafzaal/dev
Dev
2 parents a35a0a6 + 7899a77 commit 4fb7cd9

7 files changed

Lines changed: 190 additions & 45 deletions

File tree

.github/dependabot.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# .github/dependabot.yml
2+
version: 2
3+
updates:
4+
# Frontend dependencies
5+
- package-ecosystem: "npm"
6+
directory: "/frontend"
7+
schedule:
8+
interval: "weekly"
9+
versioning-strategy: "auto"
10+
labels:
11+
- "dependencies"
12+
- "frontend"
13+
open-pull-requests-limit: 10
14+
groups:
15+
svelte-packages:
16+
patterns:
17+
- "svelte*"
18+
- "@sveltejs*"
19+
20+
# Backend Python dependencies
21+
- package-ecosystem: "uv"
22+
directory: "/backend"
23+
schedule:
24+
interval: "weekly"
25+
labels:
26+
- "dependencies"
27+
- "backend"
28+
open-pull-requests-limit: 10
29+
30+
# Docker dependencies
31+
- package-ecosystem: "docker"
32+
directory: "/"
33+
schedule:
34+
interval: "monthly"
35+
labels:
36+
- "dependencies"
37+
- "docker"
38+
39+
# GitHub Actions
40+
- package-ecosystem: "github-actions"
41+
directory: "/"
42+
schedule:
43+
interval: "monthly"
44+
labels:
45+
- "dependencies"
46+
- "ci"

.github/workflows/docker-build.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- v*
10+
11+
permissions:
12+
contents: write
13+
packages: write
14+
id-token: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4.2.2
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3.10.0
30+
31+
- name: Extract metadata (tags, labels) for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
labels: |
37+
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
38+
org.opencontainers.image.description="This is a Docker image for the ${{ env.IMAGE_NAME }} project"
39+
org.opencontainers.image.url=${{ github.repositoryUrl }}
40+
org.opencontainers.image.source=${{ github.repositoryUrl }}
41+
org.opencontainers.image.version=${{ github.sha }}
42+
org.opencontainers.image.created=${{ github.event.repository.updated_at }}
43+
44+
- name: Login to GitHub Container Registry
45+
uses: docker/login-action@v3.4.0
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v6.18.0
53+
with:
54+
context: .
55+
push: true
56+
tags: |
57+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
58+
${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
1+
FROM langchain/langgraph-api:3.13
12

2-
# Get a distribution that has uv already installed
3-
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
43

5-
# Add user - this is the user that will run the app
6-
# If you do not set user, the app will run as root (undesirable)
7-
RUN useradd -m -u 1000 user
8-
USER user
94

10-
# Set the home directory and path
11-
ENV HOME=/home/user \
12-
PATH=/home/user/.local/bin:$PATH
5+
# -- Adding local package . --
6+
ADD . /deps/lets-talk
7+
# -- End of local package . --
138

14-
ENV UVICORN_WS_PROTOCOL=websockets
9+
# -- Installing all local dependencies --
10+
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/*
11+
# -- End of local dependencies install --
12+
ENV LANGGRAPH_HTTP='{"disable_meta": true, "disable_store": true}'
13+
ENV LANGSERVE_GRAPHS='{"the_data_guy_chat": "/deps/lets-talk/py-src/lets_talk/agent_v2.py:agent"}'
1514

1615

17-
# Set the working directory
18-
WORKDIR $HOME/app
1916

20-
COPY --chown=user ./pyproject.toml $HOME/app
21-
COPY --chown=user ./uv.lock $HOME/app
17+
# -- Ensure user deps didn't inadvertently overwrite langgraph-api
18+
RUN mkdir -p /api/langgraph_api /api/langgraph_runtime /api/langgraph_license && touch /api/langgraph_api/__init__.py /api/langgraph_runtime/__init__.py /api/langgraph_license/__init__.py
19+
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir --no-deps -e /api
20+
# -- End of ensuring user deps didn't inadvertently overwrite langgraph-api --
21+
# -- Removing pip from the final image ~<:===~~~ --
22+
RUN pip uninstall -y pip setuptools wheel && rm -rf /usr/local/lib/python*/site-packages/pip* /usr/local/lib/python*/site-packages/setuptools* /usr/local/lib/python*/site-packages/wheel* && find /usr/local/bin -name "pip*" -delete
23+
# -- End of pip removal --
2224

23-
# Install the dependencies
24-
# RUN uv sync --frozen
25-
RUN uv sync
26-
27-
# Copy the app to the container
28-
COPY --chown=user ./py-src/ $HOME/app
29-
COPY --chown=user ./.chainlit/ $HOME/app
30-
COPY --chown=user ./chainlit.md $HOME/app
31-
32-
#TODO: Fix this to download
33-
#copy posts to container
34-
COPY --chown=user ./data/ $HOME/app/data
35-
36-
# Expose the port
37-
EXPOSE 7860
38-
39-
# Run the app
40-
CMD ["uv", "run", "chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
25+
WORKDIR /deps/lets-talk

Dockerfile.chainlit

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Get a distribution that has uv already installed
3+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
4+
5+
# Add user - this is the user that will run the app
6+
# If you do not set user, the app will run as root (undesirable)
7+
RUN useradd -m -u 1000 user
8+
USER user
9+
10+
# Set the home directory and path
11+
ENV HOME=/home/user \
12+
PATH=/home/user/.local/bin:$PATH
13+
14+
ENV UVICORN_WS_PROTOCOL=websockets
15+
16+
17+
# Set the working directory
18+
WORKDIR $HOME/app
19+
20+
COPY --chown=user ./pyproject.toml $HOME/app
21+
COPY --chown=user ./uv.lock $HOME/app
22+
23+
# Install the dependencies
24+
# RUN uv sync --frozen
25+
RUN uv sync
26+
27+
# Copy the app to the container
28+
COPY --chown=user ./py-src/ $HOME/app
29+
COPY --chown=user ./.chainlit/ $HOME/app
30+
COPY --chown=user ./chainlit.md $HOME/app
31+
32+
#TODO: Fix this to download
33+
#copy posts to container
34+
COPY --chown=user ./data/ $HOME/app/data
35+
36+
# Expose the port
37+
EXPOSE 7860
38+
39+
# Run the app
40+
CMD ["uv", "run", "chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]

frontend/src/lib/ChatWidget.svelte

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,38 @@
9191
inputMessages.push(userMsg.toJSON());
9292
const streamResponse = client.runs.stream(thread_id, assistant_id, {
9393
input: { messages: inputMessages },
94-
streamMode: 'messages-tuple'
94+
streamMode: 'events',
9595
});
9696
9797
userInput = '';
9898
9999
let aiMsg = new Message('ai', '');
100100
messages.push(aiMsg);
101101
for await (const chunk of streamResponse) {
102-
if (chunk?.event === 'messages') {
103-
// Handle the message event
104-
const [msg, _] = chunk.data;
102+
103+
console.log(chunk);
105104
106-
//@ts-ignore
107-
if (msg.type === 'AIMessageChunk') {
108-
//@ts-ignore
109-
aiMsg.content += msg.content;
110-
}
105+
if(chunk?.data?.event === 'on_chat_model_stream')
106+
{
107+
108+
aiMsg.content += chunk?.data?.data?.chunk?.content || '';
109+
// Handle the message event
110+
111111
}
112-
scrollToBottom();
112+
113+
114+
115+
// if (chunk?.event === 'messages') {
116+
// // Handle the message event
117+
// const [msg, _] = chunk.data;
118+
119+
// //@ts-ignore
120+
// if (msg.type === 'AIMessageChunk') {
121+
// //@ts-ignore
122+
// aiMsg.content += msg.content;
123+
// }
124+
// }
125+
// scrollToBottom();
113126
}
114127
} catch (err) {
115128
console.error(err);

py-src/lets_talk/agent_v2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from langchain_core.tools import tool
44
from langchain.chat_models import init_chat_model
55
import lets_talk.rag as rag
6+
from lets_talk.tools.datetime_tool import get_current_datetime
67
from lets_talk.utils import format_docs
78
from lets_talk.tools import RSSFeedTool
89
from lets_talk.config import AGENT_PROMPT, AGENT_PROMPT_FILE, BASE_URL, BLOG_BASE_URL, LLM_MODEL,LLM_TEMPERATURE
@@ -12,7 +13,7 @@
1213

1314

1415
@tool
15-
def retrive_documents(query: str) -> str:
16+
def retrieve_documents(query: str) -> str:
1617
"""Retrieve relevant documents from the knowledge base to answer user questions.
1718
1819
Use this tool when you need to search for specific information, facts, or content
@@ -65,7 +66,7 @@ def retrieve_page_by_url(url: str) -> str:
6566

6667

6768
from lets_talk.config import (RSS_URL)
68-
tools =[retrive_documents, retrieve_page_by_url]
69+
tools =[retrieve_documents, retrieve_page_by_url, get_current_datetime]
6970

7071
if RSS_URL:
7172
logger.info(f"RSS URL is set to: {RSS_URL}")

py-src/lets_talk/rag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def build_retriever(
156156
logger.info("No additional retrievers added. Returning base retriever.")
157157
return retriever
158158

159-
retriever_list.append(retriever) # type: ignore
159+
#retriever_list.append(retriever) # type: ignore
160+
160161
equal_weighting = [1/len(retriever_list)] * len(retriever_list)
161162
logger.info("Creating EnsembleRetriever with %d retrievers", len(retriever_list))
162163
ensemble_retriever = EnsembleRetriever(

0 commit comments

Comments
 (0)