52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Test old Dify key - show full response"""
|
||
|
|
import httpx
|
||
|
|
import json
|
||
|
|
import time
|
||
|
|
|
||
|
|
base_url = "http://yw-dify.dc.servyou-it.com"
|
||
|
|
api_key = "app-UaTWYdBSwN6VktKQlbh5YN5H"
|
||
|
|
|
||
|
|
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 old key with full response ===")
|
||
|
|
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")
|
||
|
|
print()
|
||
|
|
|
||
|
|
data = resp.json()
|
||
|
|
print(f"conversation_id: {data.get('conversation_id', 'N/A')}")
|
||
|
|
answer = data.get('answer', '')
|
||
|
|
print(f"answer (first 800 chars):")
|
||
|
|
print(answer[:800])
|
||
|
|
print()
|
||
|
|
|
||
|
|
# Try JSON parse
|
||
|
|
try:
|
||
|
|
parsed = json.loads(answer)
|
||
|
|
print("=== JSON Parse: SUCCESS ===")
|
||
|
|
print(f"Keys: {list(parsed.keys())}")
|
||
|
|
for k, v in parsed.items():
|
||
|
|
print(f" {k}: {str(v)[:200]}")
|
||
|
|
except json.JSONDecodeError as e:
|
||
|
|
print(f"=== JSON Parse: FAILED ===")
|
||
|
|
print(f"Error: {e}")
|
||
|
|
print("Answer is plain text, not JSON")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Exception: {type(e).__name__}: {e}")
|