Skip to content

Commit caf9976

Browse files
authored
Merge pull request #39 from carlosmada22/15-web-app
Added web interface
2 parents 32f2f67 + 3d14784 commit caf9976

File tree

8 files changed

+574
-658
lines changed

8 files changed

+574
-658
lines changed

desi_vectordb/chroma.sqlite3

0 Bytes
Binary file not shown.

main.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,41 @@ def run_query_interface(config: DesiConfig) -> None:
154154

155155

156156
def run_web_interface(config: DesiConfig) -> None:
157-
"""Run the web interface (placeholder - not implemented yet)."""
158-
logger.info("🌐 Web interface not implemented yet, starting CLI interface...")
159-
run_query_interface(config)
157+
"""Run the web interface using FastAPI and Gradio."""
158+
logger.info("🌐 Starting web interface...")
159+
try:
160+
import uvicorn
161+
162+
# Update the global API base URL in the app module
163+
import desi.web.app as app_module
164+
165+
app_module.api_base_url = f"http://{config.web_host}:{config.web_port}"
166+
167+
logger.info(
168+
f"Web interface will be available at: http://{config.web_host}:{config.web_port}"
169+
)
170+
logger.info("Press Ctrl+C to stop the server")
171+
172+
# Run the server
173+
uvicorn.run(
174+
"desi.web.app:app",
175+
host=config.web_host,
176+
port=config.web_port,
177+
reload=config.web_debug,
178+
log_level="info",
179+
)
180+
181+
except ImportError as e:
182+
logger.error(f"Failed to import required packages: {e}")
183+
logger.error(
184+
"Please install required packages: pip install fastapi uvicorn gradio"
185+
)
186+
logger.info("Falling back to CLI interface...")
187+
run_query_interface(config)
188+
except Exception as e:
189+
logger.error(f"Failed to start web interface: {e}")
190+
logger.info("Falling back to CLI interface...")
191+
run_query_interface(config)
160192

161193

162194
def main():
@@ -242,8 +274,7 @@ def main():
242274

243275
# Step 4: Start the interface
244276
if args.web:
245-
logger.info("🌐 Web interface not implemented yet, starting CLI interface...")
246-
run_query_interface(config)
277+
run_web_interface(config)
247278
else:
248279
run_query_interface(config)
249280

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ dependencies = [
3838
"PyYAML",
3939
"requests",
4040
"scikit-learn",
41-
"flask",
42-
"flask-cors",
41+
"fastapi",
42+
"uvicorn[standard]",
43+
"gradio",
4344
"chromadb",
4445
]
4546

src/desi/query/conversation_engine.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import logging
11+
import re
1112
import sqlite3
1213
import uuid
1314
from typing import Dict, List, Tuple, TypedDict
@@ -153,27 +154,28 @@ def rewrite_query_node(self, state: GraphState) -> Dict:
153154

154155
history_str = "\n".join([f"{msg['role']}: {msg['content']}" for msg in history])
155156

156-
rewrite_prompt = f"""
157-
Given the following conversation history and a user's follow-up question, rewrite the user's question to be a standalone question that can be understood without the context of the chat history.
158-
159-
This standalone question will be used to search a knowledge base.
160-
161-
If the user's question is already a good standalone question, simply return it as is.
157+
rewrite_prompt = f"""Based on the chat history below, rewrite the user's follow-up question into a single, self-contained question ideal for a vector search. DO NOT add any commentary or explanation.
162158
163159
<Conversation History>
164160
{history_str}
165161
</Conversation History>
166162
167163
User's Follow-up Question: "{user_query}"
168164
169-
Standalone Question:
170-
"""
165+
Standalone Question:"""
166+
167+
# Get the raw output from the LLM
168+
raw_output = self.rewrite_llm.invoke(rewrite_prompt)
169+
170+
# Clean the output to remove any "thought" blocks
171+
cleaned_query = re.sub(
172+
r"<think>.*?</think>", "", str(raw_output.content), flags=re.DOTALL
173+
).strip()
171174

172-
rewritten_query = self.rewrite_llm.invoke(rewrite_prompt).content
173175
logger.info(
174-
f"Original query: '{user_query}' -> Rewritten query: '{rewritten_query}'"
176+
f"Original query: '{user_query}' -> Rewritten query: '{cleaned_query}'"
175177
)
176-
return {"rewritten_query": rewritten_query}
178+
return {"rewritten_query": cleaned_query}
177179

178180
# --- Node Definitions for the Graph ---
179181

@@ -325,9 +327,9 @@ def start_chat_session(self):
325327
SQLITE_DB_PATH = "./data/conversation_memory.db"
326328
CONVERSATION_HISTORY_LIMIT = 20
327329
# Value for boosting dswiki chunks
328-
DSWIKI_BOOST_VALUE = 0.2
330+
DSWIKI_BOOST_VALUE = 0.1
329331
# A score of 0.7 means we discard any chunk with less than 70% similarity.
330-
RELEVANCE_THRESHOLD = 0.7
332+
RELEVANCE_THRESHOLD = 0.4
331333
# The model used by your RAG engine
332334
LLM_MODEL = "qwen3"
333335

src/desi/query/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def query(
287287
# --- Standalone Execution Example ---
288288
CHROMA_PERSIST_DIRECTORY = "./desi_vectordb"
289289
# Value for boosting dswiki chunks
290-
DSWIKI_BOOST_VALUE = 0.15
290+
DSWIKI_BOOST_VALUE = 0.1
291291
# A score of 0.3 means we discard any chunk with less than 30% similarity.
292-
RELEVANCE_THRESHOLD = 0.7
292+
RELEVANCE_THRESHOLD = 0.4
293293
# Path to the prompt template
294294
PROMPT_TEMPLATE_PATH = "./prompts/desi_query_prompt.md"
295295

0 commit comments

Comments
 (0)