wip: 2026-08-11 工作树快照(docs/memory/h5.py/scripts 等 447 项未评审改动,安全提交到 feat 分支)
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test Dify API with different model parameter formats."""
|
||||
import json
|
||||
import httpx
|
||||
|
||||
BASE_URL = "http://yw-dify.dc.servyou-it.com/dify2openai"
|
||||
API_KEY = "app-JWI7u1LTn9XPVe95KL6dHzPx"
|
||||
url = f"{BASE_URL.rstrip('/')}/v1/chat/completions"
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {API_KEY}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
# Test different model parameter formats
|
||||
test_models = [
|
||||
"dify",
|
||||
"", # empty string
|
||||
"gpt-3.5-turbo",
|
||||
"deepseek-chat",
|
||||
"default",
|
||||
]
|
||||
|
||||
for model in test_models:
|
||||
body = {
|
||||
"model": model,
|
||||
"messages": [
|
||||
{"role": "user", "content": "我要申请VPN"},
|
||||
],
|
||||
"temperature": 0,
|
||||
}
|
||||
print(f"\n=== model={repr(model)} ===")
|
||||
try:
|
||||
resp = httpx.post(url, json=body, headers=headers, timeout=15.0)
|
||||
print(f" HTTP Status: {resp.status_code}")
|
||||
body_text = resp.text[:500]
|
||||
print(f" Response: {body_text}")
|
||||
except Exception as e:
|
||||
print(f" ERROR: {type(e).__name__}: {e}")
|
||||
|
||||
# Also test without model parameter at all
|
||||
print(f"\n=== No model parameter ===")
|
||||
body = {
|
||||
"messages": [
|
||||
{"role": "user", "content": "我要申请VPN"},
|
||||
],
|
||||
"temperature": 0,
|
||||
}
|
||||
try:
|
||||
resp = httpx.post(url, json=body, headers=headers, timeout=15.0)
|
||||
print(f" HTTP Status: {resp.status_code}")
|
||||
print(f" Response: {resp.text[:500]}")
|
||||
except Exception as e:
|
||||
print(f" ERROR: {type(e).__name__}: {e}")
|
||||
|
||||
# Test with the main AI chat API key to compare
|
||||
# First, check what API key the main Dify uses
|
||||
print(f"\n=== Check main Dify config ===")
|
||||
import os
|
||||
main_key = os.environ.get("DIFY_API_KEY", "")
|
||||
main_base = os.environ.get("DIFY_BASE_URL", "")
|
||||
print(f" DIFY_API_KEY: {main_key[:20]}..." if main_key else " DIFY_API_KEY: not set")
|
||||
print(f" DIFY_BASE_URL: {main_base}")
|
||||
|
||||
if main_key:
|
||||
main_url = f"{main_base.rstrip('/')}/v1/chat/completions" if main_base else url
|
||||
main_headers = {"Authorization": f"Bearer {main_key}", "Content-Type": "application/json"}
|
||||
body = {
|
||||
"model": "dify",
|
||||
"messages": [{"role": "user", "content": "你好"}],
|
||||
"temperature": 0,
|
||||
}
|
||||
print(f"\n=== Test main Dify API with model='dify' ===")
|
||||
try:
|
||||
resp = httpx.post(main_url, json=body, headers=main_headers, timeout=15.0)
|
||||
print(f" HTTP Status: {resp.status_code}")
|
||||
print(f" Response: {resp.text[:500]}")
|
||||
except Exception as e:
|
||||
print(f" ERROR: {type(e).__name__}: {e}")
|
||||
Reference in New Issue
Block a user