Update app.py
Browse files
app.py
CHANGED
|
@@ -32,17 +32,48 @@ from agent_collaboratif_avid import (
|
|
| 32 |
SIMILARITY_TOP_K,
|
| 33 |
MAX_VALIDATION_LOOPS
|
| 34 |
)
|
|
|
|
| 35 |
from chainlit.data.sql_alchemy import SQLAlchemyDataLayer
|
| 36 |
-
from supabase import Client
|
|
|
|
| 37 |
|
| 38 |
SUPABASE_URL = os.environ.get("SUPABASE_URL")
|
| 39 |
SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY")
|
| 40 |
CONNINFO = os.environ.get("CONNINFO")
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
@cl.data_layer
|
| 44 |
def get_data_layer():
|
| 45 |
-
return SQLAlchemyDataLayer(conninfo=CONNINFO, storage_provider=
|
| 46 |
|
| 47 |
# =============================================================================
|
| 48 |
# CONFIGURATION LANGSMITH
|
|
@@ -425,24 +456,6 @@ Merci d'avoir utilisé l'agent collaboratif !
|
|
| 425 |
|
| 426 |
await cl.Message(content=end_msg).send()
|
| 427 |
|
| 428 |
-
# =============================================================================
|
| 429 |
-
# CONFIGURATION DE L'AUTHENTIFICATION (Optionnel)
|
| 430 |
-
# =============================================================================
|
| 431 |
-
|
| 432 |
-
@cl.password_auth_callback
|
| 433 |
-
def auth_callback(username: str, password: str) -> Optional[cl.User]:
|
| 434 |
-
"""
|
| 435 |
-
Callback d'authentification (optionnel).
|
| 436 |
-
À configurer selon vos besoins.
|
| 437 |
-
"""
|
| 438 |
-
# Exemple simple (à remplacer par votre logique)
|
| 439 |
-
if username == "admin" and password == "password":
|
| 440 |
-
return cl.User(
|
| 441 |
-
identifier=username,
|
| 442 |
-
metadata={"role": "admin", "provider": "credentials"}
|
| 443 |
-
)
|
| 444 |
-
return None
|
| 445 |
-
|
| 446 |
# =============================================================================
|
| 447 |
# CONFIGURATION DU DATA LAYER (Supabase/PostgreSQL)
|
| 448 |
# =============================================================================
|
|
|
|
| 32 |
SIMILARITY_TOP_K,
|
| 33 |
MAX_VALIDATION_LOOPS
|
| 34 |
)
|
| 35 |
+
import bcrypt
|
| 36 |
from chainlit.data.sql_alchemy import SQLAlchemyDataLayer
|
| 37 |
+
from supabase import create_client, Client
|
| 38 |
+
from supabase.lib.client_options import ClientOptions
|
| 39 |
|
| 40 |
SUPABASE_URL = os.environ.get("SUPABASE_URL")
|
| 41 |
SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY")
|
| 42 |
CONNINFO = os.environ.get("CONNINFO")
|
| 43 |
|
| 44 |
+
url: str = SUPABASE_URL
|
| 45 |
+
key: str = SUPABASE_ANON_KEY
|
| 46 |
+
supabase: Client = create_client(url, key, options=ClientOptions(auto_refresh_token=False,persist_session=True))
|
| 47 |
+
|
| 48 |
+
# =============================================================================
|
| 49 |
+
# CONFIGURATION DE L'AUTHENTIFICATION (Optionnel)
|
| 50 |
+
# =============================================================================
|
| 51 |
+
|
| 52 |
+
@cl.password_auth_callback
|
| 53 |
+
def auth_callback(username: str, password: str) -> Optional[cl.User]:
|
| 54 |
+
"""
|
| 55 |
+
Callback d'authentification (optionnel).
|
| 56 |
+
À configurer selon vos besoins.
|
| 57 |
+
"""
|
| 58 |
+
# Exemple simple (à remplacer par votre logique)
|
| 59 |
+
auth = json.loads(os.environ.get("CHAINLIT_AUTH_LOGIN"))
|
| 60 |
+
ident = auth[0]['ident']
|
| 61 |
+
pwd = auth[0]['pwd']
|
| 62 |
+
resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(ident.encode('utf-8'), bcrypt.gensalt()))
|
| 63 |
+
resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(pwd.encode('utf-8'), bcrypt.gensalt()))
|
| 64 |
+
resultRole = auth[0]['role']
|
| 65 |
+
|
| 66 |
+
if resultLogAdmin == True and resultPwdAdmin == True and resultRole == "adminavid":
|
| 67 |
+
return cl.User(
|
| 68 |
+
identifier=auth[0]['ident'],
|
| 69 |
+
metadata={"role": "adminavid", "provider": "credentials"}
|
| 70 |
+
)
|
| 71 |
+
else:
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
@cl.data_layer
|
| 75 |
def get_data_layer():
|
| 76 |
+
return SQLAlchemyDataLayer(conninfo=CONNINFO, storage_provider=supabase)
|
| 77 |
|
| 78 |
# =============================================================================
|
| 79 |
# CONFIGURATION LANGSMITH
|
|
|
|
| 456 |
|
| 457 |
await cl.Message(content=end_msg).send()
|
| 458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
# =============================================================================
|
| 460 |
# CONFIGURATION DU DATA LAYER (Supabase/PostgreSQL)
|
| 461 |
# =============================================================================
|