Conversation
code update
There was a problem hiding this comment.
Pull request overview
Cette PR introduit une authentification simple par cookie (sessions SQLite) pour l’API FastAPI + une UI de connexion côté frontend, et bascule le LLM de Groq vers Mistral. Elle ajoute aussi un agent “avec mémoire” via LangGraph/SQLite.
Changes:
- Remplacement du provider LLM (Groq → Mistral) et ajout d’un agent “mémoire” (LangGraph + SQLite).
- Ajout d’une API FastAPI alternative avec login (cookie HttpOnly) + endpoint chat protégé.
- Ajout d’un overlay de connexion et de logique de login côté frontend.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| runIA.py | Remplace ChatGroq par ChatMistralAI et change la variable d’environnement attendue. |
| init_and_run.py | Script d’initialisation du dossier data/ et des tables d’auth. |
| api_auth.py | Nouvelle API FastAPI avec login cookie + chat protégé + static frontend. |
| db_session.py | Stockage SQLite des users/sessions + vérification d’expiration. |
| agent_memory.py | Agent LangGraph avec persistance SQLite et thread_id basé sur user_id. |
| frontend/index.html | Ajoute un overlay de connexion (email + bouton). |
| frontend/script.js | Ajoute handleLogin() et conserve l’envoi de messages vers /api/chat. |
| frontend/style.css | Ajoute les styles de l’overlay d’authentification. |
| frontend/auth.js | Nouveau fichier utilitaire auth/chat (actuellement non intégré). |
| cookies.txt | Ajout d’un fichier de cookies de session (artefact). |
| cookies_test.txt | Ajout d’un fichier de cookies de session (artefact). |
| cookies_mistral.txt | Ajout d’un fichier de cookies de session (artefact). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
5
to
14
| from dotenv import load_dotenv | ||
| from langchain_groq import ChatGroq | ||
| from langchain_mistralai import ChatMistralAI | ||
| from langchain_core.tools import tool | ||
|
|
||
| load_dotenv() | ||
|
|
||
| model = ChatGroq( | ||
| model="llama-3.1-8b-instant", | ||
| api_key=os.getenv("GROQ_API_KEY"), | ||
| model = ChatMistralAI( | ||
| model="mistral-large-latest", | ||
| api_key=os.getenv("MISTRAL_API_KEY"), | ||
| temperature=0 |
Comment on lines
+4
to
+10
| # 1. Créer le dossier data s'il n'existe pas | ||
| os.makedirs("data", exist_ok=True) | ||
|
|
||
| # 2. Initialiser la base d'authentification | ||
| print("🔧 Initialisation de la base de données auth...") | ||
| db_session.init_auth_db() | ||
| print("✅ Base de données prête.") |
Comment on lines
+16
to
+27
| <!-- Overlay d'Authentification --> | ||
| <div id="authOverlay" class="auth-overlay"> | ||
| <div class="auth-box"> | ||
| <div class="auth-header"> | ||
| <span class="auth-icon">🔑</span> | ||
| <h2>Connexion</h2> | ||
| <p>Entrez votre email pour accéder à l'agent expert</p> | ||
| </div> | ||
| <div class="auth-footer"> | ||
| <input type="email" id="emailInput" placeholder="votre@email.com" required> | ||
| <button onclick="handleLogin()" id="loginBtn">Ouvrir la session</button> | ||
| </div> |
Comment on lines
+25
to
+26
| <input type="email" id="emailInput" placeholder="votre@email.com" required> | ||
| <button onclick="handleLogin()" id="loginBtn">Ouvrir la session</button> |
Comment on lines
+50
to
+65
| try { | ||
| const response = await fetch('/api/login', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ email: email }) | ||
| }); | ||
|
|
||
| if (response.ok) { | ||
| document.getElementById('authOverlay').style.opacity = '0'; | ||
| setTimeout(() => { | ||
| document.getElementById('authOverlay').style.display = 'none'; | ||
| }, 500); | ||
| addMessage("Bienvenue ! Je suis prêt à répondre à vos questions sur l'immobilier.", false); | ||
| } else { | ||
| alert("Erreur lors de la connexion. Veuillez réessayer."); | ||
| } |
Comment on lines
+5
to
+33
| from langgraph.checkpoint.sqlite import SqliteSaver | ||
| from langgraph.prebuilt import create_react_agent | ||
| from langchain_mistralai import ChatMistralAI | ||
| from runIA import outil_dvf_historique, outil_dvf_estimation, outil_infos_ville, PROMPT_CENTRAL | ||
|
|
||
| load_dotenv() | ||
|
|
||
| model = ChatMistralAI(model="mistral-large-latest", api_key=os.getenv("MISTRAL_API_KEY"), temperature=0) | ||
|
|
||
| # On ajoute la règle de rappel | ||
| PROMPT_MEMOIRE = PROMPT_CENTRAL + ( | ||
| "\n\n6. RÈGLE DE MÉMOIRE : Tu as accès à l'historique de la discussion. " | ||
| "Si l'utilisateur pose une question répétée, mentionne poliment que c'est un rappel." | ||
| ) | ||
|
|
||
| conn = sqlite3.connect("data/memory.db", check_same_thread=False) | ||
| memory = SqliteSaver(conn) | ||
|
|
||
| dvf_tools = [outil_dvf_historique, outil_dvf_estimation, outil_infos_ville] | ||
|
|
||
| # 💡 CORRECTION : Utilisation de l'argument 'prompt' (version actuelle de langgraph) | ||
| agent_executor = create_react_agent( | ||
| model, | ||
| tools=dvf_tools, | ||
| checkpointer=memory, | ||
| prompt=PROMPT_MEMOIRE | ||
| ) | ||
|
|
||
| def interroger_agent(message_utilisateur: str, thread_id: str): |
| "\n\n6. RÈGLE DE MÉMOIRE : Tu as accès à l'historique de la discussion. " | ||
| "Si l'utilisateur pose une question répétée, mentionne poliment que c'est un rappel." | ||
| ) | ||
|
|
| # https://curl.se/docs/http-cookies.html | ||
| # This file was generated by libcurl! Edit at your own risk. | ||
|
|
||
| #HttpOnly_127.0.0.1 FALSE / FALSE 1775917241 session_id 24a446b5-499c-4555-b94a-d94de98e481e |
| # https://curl.se/docs/http-cookies.html | ||
| # This file was generated by libcurl! Edit at your own risk. | ||
|
|
||
| #HttpOnly_127.0.0.1 FALSE / FALSE 1775917150 session_id 0c68b8a4-c0ba-42f5-b6d8-7bd8252ede43 |
| # https://curl.se/docs/http-cookies.html | ||
| # This file was generated by libcurl! Edit at your own risk. | ||
|
|
||
| #HttpOnly_127.0.0.1 FALSE / FALSE 1775919227 session_id 083b53d2-fea0-4f89-ab62-676809399e3e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.