Skip to content

Commit 5676e08

Browse files
fix history chat
1 parent 1b40288 commit 5676e08

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

app/routers/admin.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def upload_json_faq(
180180
faq_items = await IngestionService.parse_json_faq(file)
181181
count = 0
182182
for item in faq_items:
183-
# Check for duplicates
183+
# Vérification des doublons
184184
existing = db.exec(select(FAQItem).where(FAQItem.question == item["question"])).first()
185185
if not existing:
186186
new_faq = FAQItem(
@@ -210,7 +210,7 @@ async def upload_pdf_doc(
210210
chunks = await IngestionService.parse_pdf_document(file)
211211
count = 0
212212
for item in chunks:
213-
# Check for duplicates
213+
# Vérification des doublons
214214
existing = db.exec(select(FAQItem).where(FAQItem.question == item["question"])).first()
215215
if not existing:
216216
new_faq = FAQItem(
@@ -235,8 +235,7 @@ async def list_documents(
235235
db: Session = Depends(get_session),
236236
current_user = Depends(get_current_admin_user)
237237
):
238-
"""Display list of source documents"""
239-
# SQLite doesn't support DISTINCT ON, so we group by source
238+
"""Affiche la liste des documents sources"""
240239
results = db.exec(
241240
select(FAQItem.source, func.count(FAQItem.id))
242241
.where(FAQItem.source != None)
@@ -258,10 +257,10 @@ async def delete_document(
258257
db: Session = Depends(get_session),
259258
current_user = Depends(get_current_admin_user)
260259
):
261-
"""Delete all items linked to a document"""
260+
"""Supprime toutes les questions liées à un document"""
262261
items = db.exec(select(FAQItem).where(FAQItem.source == filename)).all()
263262

264-
# Delete from ChromaDB and database
263+
# Suppression de ChromaDB et de la base de données
265264
service = RAGService()
266265
for item in items:
267266
await service.remove_faq_item(item.id)

app/routers/chat.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ async def feedback_endpoint(
6767
db.commit()
6868
return {"message": "Feedback enregistré"}
6969

70+
@router.get("/chat/history/{user_id}")
71+
async def get_history_endpoint(
72+
user_id: str,
73+
db: Session = Depends(get_session)
74+
):
75+
"""Récupère l'historique complet des interactions pour un utilisateur"""
76+
interactions = db.exec(
77+
select(ChatInteraction)
78+
.where(ChatInteraction.user_session_id == user_id)
79+
.order_by(ChatInteraction.timestamp)
80+
).all()
81+
82+
history_data = [
83+
{
84+
"user_message": i.message,
85+
"bot_response": i.response,
86+
"timestamp": i.timestamp.isoformat(),
87+
"provider": i.provider
88+
}
89+
for i in interactions
90+
]
91+
92+
return {"history": history_data}
93+
7094
@router.post("/chat")
7195
async def chat_endpoint(request: ChatRequest, db: Session = Depends(get_session)):
7296
"""Endpoint principal pour le chat avec streaming"""

app/services/ingestion.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ async def parse_pdf_document(file: UploadFile) -> List[Dict[str, str]]:
3333
for i, page in enumerate(reader.pages):
3434
# Extraction with "layout" mode which preserves spaces better
3535
text = page.extract_text(extraction_mode="layout")
36-
3736
if not text or not text.strip():
3837
continue
39-
4038
# Cleanup
4139
text = text.replace("\n", " ")
4240
text = re.sub(r"([a-z])([A-Z])", r"\1 \2", text)

app/services/llm_factory.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,12 @@ async def generate_response(self, prompt: str) -> dict:
105105

106106
async def generate_stream(self, prompt: str):
107107
"""Attempts to stream with the first available provider."""
108-
# Note: For streaming, we simplify by trying the first provider without complex fallback
109-
# or we could implement similar logic
110108
for provider in self.providers:
111109
try:
112110
logger.info(f"Start streaming with {provider.name}")
113111
async for chunk in provider.generate_stream(prompt):
114112
yield {"chunk": chunk, "provider": provider.name}
115-
return # Success
113+
return
116114
except Exception as e:
117115
logger.error(f"Stream error {provider.name}: {e}")
118116
continue

static/js/chatbot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ async function handleSendMessage() {
445445
hideTypingIndicator();
446446
console.error(error);
447447
showToast("Erreur de connexion", "error");
448-
addMessage("Erreur de connexion", false, { isError: true }, Date.now().toString());
448+
addMessage("Erreur de connexion", false, { isError: true }, Date.now().toString());
449449
} finally {
450450
input.disabled = false;
451451
sendBtn.disabled = false;

0 commit comments

Comments
 (0)