55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Test multiple Dify API keys to find a working one"""
|
||
|
|
import httpx
|
||
|
|
import json
|
||
|
|
import time
|
||
|
|
|
||
|
|
base_url = "http://yw-dify.dc.servyou-it.com"
|
||
|
|
|
||
|
|
# Test multiple API keys
|
||
|
|
api_keys = [
|
||
|
|
("app-7jkRkAzvX4QM9v9SM3P8mMEO", "审批意图副本"),
|
||
|
|
("app-J3s8sHarZQ2SCaNF3xCppliL", "自建应用"),
|
||
|
|
("app-z3S9AEUUAVPbtR2rioxpiIvp", "分诊应用"),
|
||
|
|
]
|
||
|
|
|
||
|
|
for api_key, name in api_keys:
|
||
|
|
url = f"{base_url}/v1/chat-messages"
|
||
|
|
headers = {
|
||
|
|
"Authorization": f"Bearer {api_key}",
|
||
|
|
"Content-Type": "application/json"
|
||
|
|
}
|
||
|
|
payload = {
|
||
|
|
"inputs": {},
|
||
|
|
"query": "密码忘记了怎么办",
|
||
|
|
"response_mode": "blocking",
|
||
|
|
"user": "test_verify"
|
||
|
|
}
|
||
|
|
|
||
|
|
print(f"=== Testing: {name} ({api_key[:20]}...) ===")
|
||
|
|
start = time.time()
|
||
|
|
try:
|
||
|
|
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||
|
|
resp = client.post(url, headers=headers, json=payload)
|
||
|
|
elapsed = (time.time() - start) * 1000
|
||
|
|
print(f"Status: {resp.status_code}, Time: {elapsed:.0f}ms")
|
||
|
|
|
||
|
|
if resp.status_code == 200:
|
||
|
|
data = resp.json()
|
||
|
|
answer = data.get('answer', '')
|
||
|
|
print(f"conversation_id: {data.get('conversation_id', 'N/A')}")
|
||
|
|
print(f"answer (first 300 chars): {answer[:300]}")
|
||
|
|
|
||
|
|
# Try JSON parse
|
||
|
|
try:
|
||
|
|
parsed = json.loads(answer)
|
||
|
|
print(f"JSON Parse: SUCCESS - keys: {list(parsed.keys())}")
|
||
|
|
except:
|
||
|
|
print(f"JSON Parse: FAILED (plain text)")
|
||
|
|
else:
|
||
|
|
print(f"Error: {resp.text[:300]}")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Exception: {type(e).__name__}: {e}")
|
||
|
|
|
||
|
|
print()
|