fix6
This commit is contained in:
29
tasks.py
29
tasks.py
@@ -362,37 +362,26 @@ def summarize_text_task(self, meeting_id):
|
||||
def preview_action_items_task(self, text_content):
|
||||
from app import app
|
||||
with app.app_context():
|
||||
from services.dify_client import extract_action_items
|
||||
try:
|
||||
self.update_progress(10, 100, "Requesting Dify for action items...")
|
||||
api_key = app.config.get("DIFY_ACTION_EXTRACTOR_API_KEY")
|
||||
|
||||
# We can reuse the logic from the summarizer to strip timestamps
|
||||
plain_text = re.sub(r'^(\s*\[.*?\])\s*', '', text_content, flags=re.MULTILINE)
|
||||
|
||||
if not plain_text.strip():
|
||||
self.update_progress(100, 100, "Preview skipped, content is empty.")
|
||||
return {'status': 'Success', 'items': []}
|
||||
|
||||
response = ask_dify(api_key, plain_text)
|
||||
answer_text = response.get("answer", "")
|
||||
self.update_progress(80, 100, "Parsing response...")
|
||||
# Use the robust client function
|
||||
parsed_items = extract_action_items(plain_text)
|
||||
|
||||
parsed_items = []
|
||||
try:
|
||||
# Find the JSON array within the response string
|
||||
match = re.search(r'\[.*\]', answer_text, re.DOTALL)
|
||||
if match:
|
||||
json_str = match.group(0)
|
||||
parsed_items = json.loads(json_str)
|
||||
|
||||
# Ensure it's a list, otherwise reset to empty
|
||||
if not isinstance(parsed_items, list):
|
||||
parsed_items = []
|
||||
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
# If parsing fails, leave it as an empty list
|
||||
parsed_items = []
|
||||
|
||||
self.update_progress(100, 100, "Action item preview generated.")
|
||||
return {'status': 'Success', 'items': parsed_items}
|
||||
except Exception as e:
|
||||
# Log the exception for better debugging
|
||||
import logging
|
||||
logging.error(f"Error in preview_action_items_task: {e}", exc_info=True)
|
||||
self.update_state(
|
||||
state='FAILURE',
|
||||
meta={'exc_type': type(e).__name__, 'exc_message': str(e)}
|
||||
|
Reference in New Issue
Block a user