diff --git a/README.md b/README.md index 3f5c350..b0de696 100644 --- a/README.md +++ b/README.md @@ -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": "你好"}] }' ``` diff --git a/digital-human.py b/digital-human.py index b9750cf..7c69a1b 100644 --- a/digital-human.py +++ b/digital-human.py @@ -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) # ────────────────────────────────────────────────────────────── diff --git a/test.html b/test.html index 9f1513b..5c8b7e3 100644 --- a/test.html +++ b/test.html @@ -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 @@ -
- - -
@@ -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: '你好,请用一句话介绍自己。' }