refactor: 移除 relay 服务中的 model 参数,Dify /chat-messages 不需要此字段

This commit is contained in:
2026-04-22 16:18:44 +08:00
parent 5722c75536
commit 69d948de88
3 changed files with 5 additions and 14 deletions

View File

@@ -35,7 +35,7 @@ curl http://localhost:8000/health
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "your-model",
"model": "dify",
"messages": [{"role": "user", "content": "你好"}]
}'
```

View File

@@ -136,7 +136,7 @@ async def health_check():
# ──────────────────────────────────────────────────────────────
# Dify 响应格式转 OpenAI 兼容格式
# ──────────────────────────────────────────────────────────────
def dify_to_openai(dify_resp: Dict[str, Any], model: str = "dify") -> Dict[str, Any]:
def dify_to_openai(dify_resp: Dict[str, Any]) -> Dict[str, Any]:
"""
将 Dify /chat-messages 的响应转换为 OpenAI /chat/completions 兼容格式。
Dify 响应示例: { answer: "...", conversation_id: "...", task_id: "..." }
@@ -146,7 +146,7 @@ def dify_to_openai(dify_resp: Dict[str, Any], model: str = "dify") -> Dict[str,
"id": f"chatcmpl-{dify_resp.get('task_id', 'unknown')}",
"object": "chat.completion",
"created": 0,
"model": model,
"model": "dify",
"choices": [
{
"index": 0,
@@ -210,7 +210,7 @@ async def chat_completions(request: Request):
cached = get_redis().get(cache_key)
if cached:
logger.info(f"缓存命中: {cache_key}")
return dify_to_openai(json.loads(cached), model=body.get("model", "dify"))
return dify_to_openai(json.loads(cached))
except RedisConnectionError:
logger.warning("Redis 不可用,跳过缓存读取")
@@ -243,7 +243,7 @@ async def chat_completions(request: Request):
pass
# ── 响应转 OpenAI 兼容格式 ─────────────────────────────────
return dify_to_openai(result, model=body.get("model", "dify"))
return dify_to_openai(result)
# ──────────────────────────────────────────────────────────────

View File

@@ -194,9 +194,6 @@
.success-text { color: #86efac; }
.warn-text { color: #fcd34d; }
/* Model select */
#model { margin-bottom: 20px; }
/* Streaming indicator */
.streaming-indicator {
display: none;
@@ -256,10 +253,6 @@
<label>Dify API 密钥</label>
<input type="password" id="apiKey" placeholder="app-xxxxxxxx" />
</div>
<div class="field">
<label>模型名称</label>
<input type="text" id="modelName" placeholder="dify" />
</div>
</div>
<div class="btn-row">
@@ -286,7 +279,6 @@
// ── Helpers ────────────────────────────────────────────────
const relayUrl = () => document.getElementById('relayUrl').value.replace(/\/$/, '');
const apiKey = () => document.getElementById('apiKey').value.trim();
const model = () => document.getElementById('modelName').value.trim() || 'dify';
function setStatus(type, text) {
const dot = document.getElementById('statusDot');
@@ -354,7 +346,6 @@
setStatus('idle', '请求中…');
const payload = {
model: model(),
stream: false,
messages: [
{ role: 'user', content: '你好,请用一句话介绍自己。' }