From 69d948de887d2bf3091d676c8ec012cd7f63e10e Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Wed, 22 Apr 2026 16:18:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20relay=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=AD=E7=9A=84=20model=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8CDify=20/chat-messages=20=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=AD=A4=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- digital-human.py | 8 ++++---- test.html | 9 --------- 3 files changed, 5 insertions(+), 14 deletions(-) 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 @@ -