Files
wecom_it_smart_desk/scripts/debug/test_dify_composite.py
Simon 7864ab404b feat(scripts): 收纳运维/部署/修复/调试脚本到 scripts/ 目录
**目录结构**:
- scripts/                 顶层运维/工具脚本(20 个)
- scripts/deploy/          一键部署脚本(deploy_*.py / upload_*.py / redeploy.py 等 8 个)
- scripts/fix/             一次性修复脚本(fix_*.py / fix_*.cypher / fix_*.sql 等 9 个)
- scripts/debug/           调试脚本集合(check_*.py/sql、test_*.py、debug_*.py 等 42 个)

**ops-tools/jms_ops.py**:jumpserver-ops skill 默认路径修复
- 从 'jumpserver-automation-shareable' 改为 'jumpserver-ops'
- 同步更新注释(优先 JP_SKILL_DIR 环境变量)

**典型脚本用途**:
- scripts/deploy-v1.2.ps1 / -staging.ps1:一键部署 v1.2 到生产 / staging
- scripts/init_quick_rules.sql:quick_rules 表初始数据
- scripts/gen_admin_token.py:生成 admin JWT token(调试用)
- scripts/build-and-verify.sh:v1.1 实施验证脚本
- scripts/verify_*.sh / .py:API/quick_rules 验证
- scripts/fix/*.py:环境修复(compose、env_key、itsm_bridge 等)

合计 81 文件 + 3317 行 / - 1 行
2026-08-03 18:48:02 +08:00

58 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Test Dify API with composite API key format."""
import json
import os
import httpx
# The proxy expects composite format: <dify_base_url>|<api_key>|<app_type>
# Main Dify uses: http://yw-dify.dc.servyou-it.com/v1|app-UaTWYdBSwN6VktKQlbh5YN5H|Chat
# Approval should use: http://yw-dify.dc.servyou-it.com/v1|app-JWI7u1LTn9XPVe95KL6dHzPx|Chat
PROXY_URL = "http://yw-dify.dc.servyou-it.com/dify2openai/v1/chat/completions"
APPROVAL_KEY_RAW = "app-JWI7u1LTn9XPVe95KL6dHzPx"
APPROVAL_KEY_COMPOSITE = "http://yw-dify.dc.servyou-it.com/v1|app-JWI7u1LTn9XPVe95KL6dHzPx|Chat"
body = {
"model": "dify",
"messages": [
{"role": "user", "content": "我要申请VPN"},
],
"temperature": 0,
}
# Test 1: Raw API key (current, failing)
print("=== Test 1: Raw API key (current) ===")
headers = {"Authorization": f"Bearer {APPROVAL_KEY_RAW}", "Content-Type": "application/json"}
try:
resp = httpx.post(PROXY_URL, json=body, headers=headers, timeout=15.0)
print(f" HTTP: {resp.status_code}")
print(f" Body: {resp.text[:300]}")
except Exception as e:
print(f" ERROR: {e}")
# Test 2: Composite API key
print("\n=== Test 2: Composite API key ===")
headers = {"Authorization": f"Bearer {APPROVAL_KEY_COMPOSITE}", "Content-Type": "application/json"}
try:
resp = httpx.post(PROXY_URL, json=body, headers=headers, timeout=30.0)
print(f" HTTP: {resp.status_code}")
print(f" Body: {resp.text[:500]}")
if resp.status_code == 200:
data = resp.json()
choices = data.get("choices") or []
if choices:
content = choices[0].get("message", {}).get("content", "")
print(f" Content: {content[:300]}")
try:
parsed = json.loads(content)
print(f" Parsed JSON: {json.dumps(parsed, ensure_ascii=False, indent=2)}")
except:
print(f" Content is not JSON")
except Exception as e:
print(f" ERROR: {e}")
# Test 3: Check main Dify key format
print("\n=== Test 3: Main Dify env vars ===")
print(f" DIFY_API_KEY = {os.environ.get('DIFY_API_KEY', 'NOT SET')}")
print(f" DIFY_API_URL = {os.environ.get('DIFY_API_URL', 'NOT SET')}")