Spaces:
Running
Running
Commit ·
6a8fc80
1
Parent(s): c820ac8
feat : upgrade sys prompt and keyword
Browse files- services/agents.py +41 -24
services/agents.py
CHANGED
|
@@ -226,11 +226,20 @@ def deblur_image_from_url(
|
|
| 226 |
def classify_intent(user_input: str) -> str:
|
| 227 |
"""
|
| 228 |
判斷使用者輸入意圖:
|
| 229 |
-
- "deblur" -> 去模糊
|
| 230 |
-
- "qa" -> 一般問題或
|
| 231 |
"""
|
| 232 |
-
deblur_keywords = [
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
return "deblur"
|
| 235 |
else:
|
| 236 |
return "qa"
|
|
@@ -256,26 +265,34 @@ llm = ChatGoogleGenerativeAI(
|
|
| 256 |
|
| 257 |
# ✅ 建立 Prompt (新版語法)
|
| 258 |
sys_prompt = """
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
# --- 4. 建立代理人與執行器 ---
|
| 281 |
# 建立工具調用代理人 (Tool Calling Agent)
|
|
|
|
| 226 |
def classify_intent(user_input: str) -> str:
|
| 227 |
"""
|
| 228 |
判斷使用者輸入意圖:
|
| 229 |
+
- "deblur" -> 去模糊 / 修復 / 影像清晰化
|
| 230 |
+
- "qa" -> 一般問題或圖片分析
|
| 231 |
"""
|
| 232 |
+
deblur_keywords = [
|
| 233 |
+
# 中文
|
| 234 |
+
"去模糊", "清晰", "清楚", "修復", "模糊", "變清楚", "提高清晰度",
|
| 235 |
+
"還原", "去噪", "降噪", "去霧", "增強", "超解析", "超分辨",
|
| 236 |
+
# 英文/拼音
|
| 237 |
+
"deblur", "restore", "restoration", "denoise", "noise", "enhance",
|
| 238 |
+
"enhancement", "super resolution", "sr", "defog", "dehaze",
|
| 239 |
+
"sharpen", "blurry", "blurred", "fix blur"
|
| 240 |
+
]
|
| 241 |
+
text = user_input.lower()
|
| 242 |
+
if any(k in text for k in deblur_keywords):
|
| 243 |
return "deblur"
|
| 244 |
else:
|
| 245 |
return "qa"
|
|
|
|
| 265 |
|
| 266 |
# ✅ 建立 Prompt (新版語法)
|
| 267 |
sys_prompt = """
|
| 268 |
+
你是一個圖像生成、去模糊與圖片問答助理,請依流程使用工具。
|
| 269 |
+
|
| 270 |
+
【可用工具】
|
| 271 |
+
1. classify_intent(user_input) → 回傳 "deblur" 或 "qa"
|
| 272 |
+
2. deblur_image_from_url(file_url, user_text) → 圖片去模糊/修復
|
| 273 |
+
3. analyze_image_with_text(image_path, user_text) → 圖片理解與問答
|
| 274 |
+
4. generate_and_upload_image(prompt) → 生成圖像
|
| 275 |
+
|
| 276 |
+
【流程】
|
| 277 |
+
- 先呼叫 classify_intent 判斷意圖
|
| 278 |
+
- 若為 "deblur" → 呼叫 deblur_image_from_url
|
| 279 |
+
- 若為 "qa":
|
| 280 |
+
- 若與圖片內容有關 → analyze_image_with_text
|
| 281 |
+
- 若需生成新圖 → generate_and_upload_image
|
| 282 |
+
|
| 283 |
+
【回覆規則】
|
| 284 |
+
- 若工具成功輸出圖片 → 回覆必須包含:
|
| 285 |
+
- 圖片完整 URL
|
| 286 |
+
- 簡要說明(如:已完成去模糊/生成圖片)
|
| 287 |
+
- 若工具失敗 → 用自然語言說明錯誤,不輸出技術錯誤碼或 traceback
|
| 288 |
+
|
| 289 |
+
【判斷原則】
|
| 290 |
+
- 有「去模糊、清晰、修復」等語意 → deblur
|
| 291 |
+
- 有提問或描述圖片 → qa
|
| 292 |
+
- 有「生成、畫、幫我做一張圖」→ generate_and_upload_image
|
| 293 |
+
|
| 294 |
+
請嚴格遵循流程,不要跳步。
|
| 295 |
+
"""
|
| 296 |
|
| 297 |
# --- 4. 建立代理人與執行器 ---
|
| 298 |
# 建立工具調用代理人 (Tool Calling Agent)
|