Skip to content

Commit 6da9db4

Browse files
authored
fix: add optional graphrag toggle in dockerfile (#377)
* fix: toggle graphrag install in Docker build * fix: update Dockerfile * fix: remove unused logics in chat_fn * fix: disable duckduckgo test due to API limit
1 parent 3ff6af8 commit 6da9db4

File tree

5 files changed

+39
-132
lines changed

5 files changed

+39
-132
lines changed

.github/workflows/build-push-docker.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,34 @@ jobs:
8888
username: ${{ github.actor }}
8989
password: ${{ secrets.GITHUB_TOKEN }}
9090

91-
- name: Build docker image
91+
- name: Build docker image (amd64)
9292
uses: docker/build-push-action@v6
9393
with:
9494
file: Dockerfile
9595
context: .
9696
push: true
97-
platforms: linux/amd64,linux/arm64
97+
platforms: linux/amd64
9898
tags: |
9999
${{ steps.meta.outputs.tags }}
100100
labels: ${{ steps.meta.outputs.labels }}
101101
target: ${{ matrix.target }}
102102
cache-from: type=gha
103103
cache-to: type=gha,mode=max
104+
build-args: |
105+
ENABLE_GRAPHRAG=true
106+
107+
- name: Build docker image (arm64)
108+
uses: docker/build-push-action@v6
109+
with:
110+
file: Dockerfile
111+
context: .
112+
push: true
113+
platforms: linux/arm64
114+
tags: |
115+
${{ steps.meta.outputs.tags }}
116+
labels: ${{ steps.meta.outputs.labels }}
117+
target: ${{ matrix.target }}
118+
cache-from: type=gha
119+
cache-to: type=gha,mode=max
120+
build-args: |
121+
ENABLE_GRAPHRAG=false

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ RUN apt-get update -qqy && \
1414
curl \
1515
cargo
1616

17+
# Setup args
18+
ARG ENABLE_GRAPHRAG=true
19+
1720
# Set environment variables
1821
ENV PYTHONDONTWRITEBYTECODE=1
1922
ENV PYTHONUNBUFFERED=1
2023
ENV PYTHONIOENCODING=UTF-8
24+
ENV ENABLE_GRAPHRAG=${ENABLE_GRAPHRAG}
2125

2226
# Create working directory
2327
WORKDIR /app
@@ -30,15 +34,19 @@ RUN bash scripts/download_pdfjs.sh $PDFJS_PREBUILT_DIR
3034

3135
# Copy contents
3236
COPY . /app
37+
COPY .env.example /app/.env
3338

3439
# Install pip packages
3540
RUN --mount=type=ssh \
3641
--mount=type=cache,target=/root/.cache/pip \
3742
pip install -e "libs/kotaemon" \
3843
&& pip install -e "libs/ktem" \
39-
&& pip install graphrag future \
4044
&& pip install "pdfservices-sdk@git+https://github.com/niallcm/pdfservices-python-sdk.git@bump-and-unfreeze-requirements"
4145

46+
RUN --mount=type=ssh \
47+
--mount=type=cache,target=/root/.cache/pip \
48+
if [ "$ENABLE_GRAPHRAG" = "true" ]; then pip install graphrag future; fi
49+
4250
# Clean up
4351
RUN apt-get autoremove \
4452
&& apt-get clean \
@@ -66,10 +74,6 @@ RUN --mount=type=ssh \
6674
--mount=type=cache,target=/root/.cache/pip \
6775
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
6876

69-
# Copy contents
70-
COPY . /app
71-
COPY .env.example /app/.env
72-
7377
# Install additional pip packages
7478
RUN --mount=type=ssh \
7579
--mount=type=cache,target=/root/.cache/pip \

libs/kotaemon/tests/test_agent.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ def generate_chat_completion_obj(text):
9898
"Action: wikipedia\n"
9999
"Action Input: Cinnamon AI company\n"
100100
),
101-
(
102-
"The information retrieved from Wikipedia is not "
103-
"about Cinnamon AI company, but about Blue Prism, "
104-
"a British multinational software corporation. "
105-
"I need to try another source to gather information "
106-
"about Cinnamon AI company.\n"
107-
"Action: duckduckgo_search\n"
108-
"Action Input: Cinnamon AI company\n"
109-
),
101+
# (
102+
# "The information retrieved from Wikipedia is not "
103+
# "about Cinnamon AI company, but about Blue Prism, "
104+
# "a British multinational software corporation. "
105+
# "I need to try another source to gather information "
106+
# "about Cinnamon AI company.\n"
107+
# "Action: duckduckgo_search\n"
108+
# "Action Input: Cinnamon AI company\n"
109+
# ),
110110
FINAL_RESPONSE_TEXT,
111111
]
112112
]

libs/ktem/ktem/pages/chat/__init__.py

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import asyncio
2-
import csv
32
import json
43
import re
54
from copy import deepcopy
6-
from datetime import datetime
7-
from pathlib import Path
85
from typing import Optional
96

107
import gradio as gr
11-
from filelock import FileLock
128
from ktem.app import BasePage
139
from ktem.components import reasonings
1410
from ktem.db.models import Conversation, engine
@@ -269,10 +265,6 @@ def on_register_events(self):
269265
self._suggestion_updated,
270266
self._app.user_id,
271267
],
272-
outputs=[
273-
self.chat_control.conversation,
274-
self.chat_control.conversation,
275-
],
276268
show_progress="hidden",
277269
)
278270

@@ -372,10 +364,6 @@ def on_register_events(self):
372364
self._suggestion_updated,
373365
self._app.user_id,
374366
],
375-
outputs=[
376-
self.chat_control.conversation,
377-
self.chat_control.conversation,
378-
],
379367
show_progress="hidden",
380368
)
381369

@@ -995,96 +983,3 @@ def suggest_chat_conv(self, settings, chat_history):
995983
pass
996984

997985
return suggested_ques, updated
998-
999-
def backup_original_info(
1000-
self, chat_history, settings, info_pannel, original_chat_history
1001-
):
1002-
original_chat_history.append(chat_history[-1])
1003-
return original_chat_history, settings, info_pannel
1004-
1005-
def save_log(
1006-
self,
1007-
conversation_id,
1008-
chat_history,
1009-
settings,
1010-
info_panel,
1011-
original_chat_history,
1012-
original_settings,
1013-
original_info_panel,
1014-
log_dir,
1015-
):
1016-
if not Path(log_dir).exists():
1017-
Path(log_dir).mkdir(parents=True)
1018-
1019-
lock = FileLock(Path(log_dir) / ".lock")
1020-
# get current date
1021-
today = datetime.now()
1022-
formatted_date = today.strftime("%d%m%Y_%H")
1023-
1024-
with Session(engine) as session:
1025-
statement = select(Conversation).where(Conversation.id == conversation_id)
1026-
result = session.exec(statement).one()
1027-
1028-
data_source = deepcopy(result.data_source)
1029-
likes = data_source.get("likes", [])
1030-
if not likes:
1031-
return
1032-
1033-
feedback = likes[-1][-1]
1034-
message_index = likes[-1][0]
1035-
1036-
current_message = chat_history[message_index[0]]
1037-
original_message = original_chat_history[message_index[0]]
1038-
is_original = all(
1039-
[
1040-
current_item == original_item
1041-
for current_item, original_item in zip(
1042-
current_message, original_message
1043-
)
1044-
]
1045-
)
1046-
1047-
dataframe = [
1048-
[
1049-
conversation_id,
1050-
message_index,
1051-
current_message[0],
1052-
current_message[1],
1053-
chat_history,
1054-
settings,
1055-
info_panel,
1056-
feedback,
1057-
is_original,
1058-
original_message[1],
1059-
original_chat_history,
1060-
original_settings,
1061-
original_info_panel,
1062-
]
1063-
]
1064-
1065-
with lock:
1066-
log_file = Path(log_dir) / f"{formatted_date}_log.csv"
1067-
is_log_file_exist = log_file.is_file()
1068-
with open(log_file, "a") as f:
1069-
writer = csv.writer(f)
1070-
# write headers
1071-
if not is_log_file_exist:
1072-
writer.writerow(
1073-
[
1074-
"Conversation ID",
1075-
"Message ID",
1076-
"Question",
1077-
"Answer",
1078-
"Chat History",
1079-
"Settings",
1080-
"Evidences",
1081-
"Feedback",
1082-
"Original/ Rewritten",
1083-
"Original Answer",
1084-
"Original Chat History",
1085-
"Original Settings",
1086-
"Original Evidences",
1087-
]
1088-
)
1089-
1090-
writer.writerows(dataframe)

libs/ktem/ktem/pages/chat/control.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,7 @@ def persist_chat_suggestions(
326326
):
327327
"""Update the conversation's chat suggestions"""
328328
if not is_updated:
329-
return (
330-
gr.update(),
331-
conversation_id,
332-
gr.update(visible=False),
333-
)
329+
return
334330

335331
if user_id is None:
336332
gr.Warning("Please sign in first (Settings → User Settings)")
@@ -353,13 +349,7 @@ def persist_chat_suggestions(
353349
session.add(result)
354350
session.commit()
355351

356-
history = self.load_chat_history(user_id)
357352
gr.Info("Chat suggestions updated.")
358-
return (
359-
gr.update(choices=history),
360-
conversation_id,
361-
gr.update(visible=False),
362-
)
363353

364354
def _on_app_created(self):
365355
"""Reload the conversation once the app is created"""

0 commit comments

Comments
 (0)