fix bugs
Browse files- app/embedding.py +1 -1
- app/main.py +9 -0
- app/sheets.py +1 -0
app/embedding.py
CHANGED
|
@@ -47,7 +47,7 @@ class EmbeddingClient:
|
|
| 47 |
json={"text": text}
|
| 48 |
)
|
| 49 |
response.raise_for_status()
|
| 50 |
-
data =
|
| 51 |
logger.info(f"[DEBUG] Embedding API response: {data}")
|
| 52 |
return data["embedding"]
|
| 53 |
except Exception as e:
|
|
|
|
| 47 |
json={"text": text}
|
| 48 |
)
|
| 49 |
response.raise_for_status()
|
| 50 |
+
data = response.json()
|
| 51 |
logger.info(f"[DEBUG] Embedding API response: {data}")
|
| 52 |
return data["embedding"]
|
| 53 |
except Exception as e:
|
app/main.py
CHANGED
|
@@ -121,6 +121,15 @@ async def webhook(request: Request):
|
|
| 121 |
|
| 122 |
@timing_decorator_async
|
| 123 |
async def process_message(message_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
sender_id = message_data["sender_id"]
|
| 125 |
page_id = message_data["page_id"]
|
| 126 |
message_text = message_data["text"]
|
|
|
|
| 121 |
|
| 122 |
@timing_decorator_async
|
| 123 |
async def process_message(message_data: Dict[str, Any]):
|
| 124 |
+
# Kiểm tra message_data hợp lệ và đủ trường
|
| 125 |
+
if not message_data or not isinstance(message_data, dict):
|
| 126 |
+
logger.error(f"[ERROR] Invalid message_data: {message_data}")
|
| 127 |
+
return
|
| 128 |
+
required_fields = ["sender_id", "page_id", "text"]
|
| 129 |
+
for field in required_fields:
|
| 130 |
+
if field not in message_data:
|
| 131 |
+
logger.error(f"[ERROR] Missing field {field} in message_data: {message_data}")
|
| 132 |
+
return
|
| 133 |
sender_id = message_data["sender_id"]
|
| 134 |
page_id = message_data["page_id"]
|
| 135 |
message_text = message_data["text"]
|
app/sheets.py
CHANGED
|
@@ -92,6 +92,7 @@ class SheetsClient:
|
|
| 92 |
for row in values:
|
| 93 |
# Bổ sung cột rỗng cho đủ 9 cột
|
| 94 |
row = row + [""] * (9 - len(row))
|
|
|
|
| 95 |
if row[4] == user_id and row[5] == page_id and row[8].lower() == 'false':
|
| 96 |
history.append({
|
| 97 |
'conversation_id': row[0],
|
|
|
|
| 92 |
for row in values:
|
| 93 |
# Bổ sung cột rỗng cho đủ 9 cột
|
| 94 |
row = row + [""] * (9 - len(row))
|
| 95 |
+
logger.info(f"[DEBUG] row: {row[4]}:{user_id} - {row[5]}:{page_id} - {row[8].lower()}:false")
|
| 96 |
if row[4] == user_id and row[5] == page_id and row[8].lower() == 'false':
|
| 97 |
history.append({
|
| 98 |
'conversation_id': row[0],
|