This commit is contained in:
beabigegg
2025-08-17 18:34:38 +08:00
parent 9a263b6afb
commit 788e2409df
7 changed files with 35 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
# services/dify_client.py
import os, json, re, requests
from dotenv import load_dotenv
from flask import current_app
load_dotenv()
@@ -19,12 +20,13 @@ def _post_request(endpoint: str, api_key: str, payload: dict):
}
# For debugging the exact payload sent to the API
print(f"Sending Dify request to {url}: {json.dumps(payload, indent=2, ensure_ascii=False)}")
current_app.logger.debug(f"Sending Dify request to {url}: {json.dumps(payload, indent=2, ensure_ascii=False)}")
resp = requests.post(url, headers=headers, json=payload, timeout=TIMEOUT)
current_app.logger.debug(f"Dify API Response ({resp.status_code}): {resp.text}")
if resp.status_code != 200:
print(f"Dify API Error Response: {resp.text}")
resp.raise_for_status()
data = resp.json()
@@ -59,11 +61,14 @@ def summarize_text(text: str, user_id: str = "system") -> str:
def extract_action_items(text: str, user_id: str = "system") -> list[dict]:
api_key = os.getenv("DIFY_ACTION_EXTRACTOR_API_KEY")
query = f"請從以下會議記錄中,提取所有行動項目(action items)並嚴格以JSON格式返回。會議記錄如下\n\n{text}"
payload = {
"inputs": {},
"response_mode": "blocking",
"user": user_id,
"query": text,
"query": query,
}
raw = _post_request("/chat-messages", api_key, payload)
@@ -90,4 +95,4 @@ def extract_action_items(text: str, user_id: str = "system") -> list[dict]:
"owner": i["owner"],
"due_date": i["duedate"],
})
return normalized
return normalized