diff --git a/core/ai_service.py b/core/ai_service.py index f7cbb5f..7c87445 100644 --- a/core/ai_service.py +++ b/core/ai_service.py @@ -3,6 +3,7 @@ import logging import random import hashlib from django.utils import timezone +from django.utils.dateparse import parse_datetime from datetime import timedelta from .models import AIConfiguration, AIChatHistory, SyncHistoryLog from .utils import decrypt_value @@ -128,7 +129,7 @@ def fetch_merlin_history(api_key): item['id'] = _generate_stable_id(item['title'], 'merlin') return data - def fetch_poe_history(api_key): +def fetch_poe_history(api_key): if api_key == "YOUR_MOCK_KEY_OR_EMPTY": # For now, it's returning mock data: data = [ @@ -143,11 +144,13 @@ def fetch_merlin_history(api_key): 'last_date': timezone.now() - timedelta(hours=8) } ] - return data # or return [] Or handle as error + for item in data: + item['id'] = _generate_stable_id(item['title'], 'poe') + return data # Calling an API endpoint (Replace URL with the actual Poe API you use) response = httpx.get( - "https://api.poe.com/v1/chats", + "https://api.poe.com/v1", headers={"Authorization": f"Bearer {api_key}"} ) response.raise_for_status() @@ -157,7 +160,7 @@ def fetch_merlin_history(api_key): 'id': item['chatId'], 'title': item['title'], 'content': item['snippet'], - 'last_date': parse_date(item['updatedAt']) + 'last_date': parse_datetime(item['updatedAt']) or timezone.now() } for item in data['chats']] def fetch_openrouter_history(api_key): @@ -170,4 +173,4 @@ def fetch_openrouter_history(api_key): ] for item in data: item['id'] = _generate_stable_id(item['title'], 'openrouter') - return data + return data \ No newline at end of file