cjovs commited on
Commit
2ca38ff
·
verified ·
1 Parent(s): 624fe7f

Force all API requests onto deepseek-v4-pro-search

Browse files
Files changed (1) hide show
  1. app/routes.py +34 -73
app/routes.py CHANGED
@@ -34,6 +34,18 @@ from .tokens import count_tokens
34
  logger = logging.getLogger(__name__)
35
 
36
  router = APIRouter()
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
 
39
  # ----------------------------------------------------------------------
@@ -64,31 +76,19 @@ def _delete_deepseek_session(request: Request, session_id: str):
64
  # 路由:/v1/models
65
  # ----------------------------------------------------------------------
66
  BASE_MODELS = [
67
- "deepseek-v4-flash",
68
- "deepseek-chat",
69
- "deepseek-reasoner",
70
  "deepseek-v4-pro",
71
  ]
72
 
73
 
74
  @router.get("/v1/models")
75
  def list_models():
76
- models_list = []
77
- for base_id in BASE_MODELS:
78
- models_list.append({
79
- "id": base_id,
80
- "object": "model",
81
- "created": 1677610602,
82
- "owned_by": "deepseek",
83
- "permission": [],
84
- })
85
- models_list.append({
86
- "id": f"{base_id}-search",
87
- "object": "model",
88
- "created": 1677610602,
89
- "owned_by": "deepseek",
90
- "permission": [],
91
- })
92
  data = {"object": "list", "data": models_list}
93
  return JSONResponse(content=data, status_code=200)
94
 
@@ -432,9 +432,10 @@ def _stream_responses_from_chat(chat_body: dict, auth_header: str, x_api_key: st
432
  async def responses_api(request: Request):
433
  try:
434
  req_data = await request.json()
435
- model = req_data.get("model")
 
436
  messages = _responses_input_to_messages(req_data)
437
- if not model or not messages:
438
  return JSONResponse(
439
  status_code=400,
440
  content={"error": "Request must include 'model' and a non-empty 'input'."},
@@ -500,36 +501,17 @@ async def chat_completions(request: Request):
500
  )
501
 
502
  req_data = await request.json()
503
- model = req_data.get("model")
 
504
  messages = req_data.get("messages", [])
505
- if not model or not messages:
506
  raise HTTPException(
507
  status_code=400, detail="Request must include 'model' and 'messages'."
508
  )
509
- # 判断模型类型(支持 -search 后缀)
510
- model_lower = model.lower().strip()
511
- if model_lower.endswith("-search"):
512
- model_lower = model_lower[:-7]
513
- search_by_model = True
514
- else:
515
- search_by_model = False
516
-
517
- if model_lower in ["deepseek-v4-flash", "deepseek-chat"]:
518
- model_type = "default"
519
- auto_thinking = True
520
- lock_thinking = False
521
- elif model_lower in ["deepseek-reasoner"]:
522
- model_type = "default"
523
- auto_thinking = True
524
- lock_thinking = True # deepseek-reasoner 强制开启思考,不可关闭
525
- elif model_lower in ["deepseek-v4-pro"]:
526
- model_type = "expert"
527
- auto_thinking = True
528
- lock_thinking = False
529
- else:
530
- raise HTTPException(
531
- status_code=503, detail=f"Model '{model}' is not available."
532
- )
533
  # 解析 thinking,支持 thinking_enabled 和 thinking.type 两种格式
534
  if lock_thinking:
535
  thinking_enabled = True
@@ -1201,32 +1183,11 @@ async def anthropic_messages(request: Request):
1201
  )
1202
 
1203
  req_data = await request.json()
1204
- model = req_data.get("model", "deepseek-v4-flash")
1205
-
1206
- # ---------- 模型类型(支持 -search 后缀) ----------
1207
- model_lower = model.lower().strip()
1208
- if model_lower.endswith("-search"):
1209
- model_lower = model_lower[:-7]
1210
- search_by_model = True
1211
- else:
1212
- search_by_model = False
1213
-
1214
- if model_lower in [
1215
- "deepseek-v4-flash", "deepseek-chat",
1216
- "claude-sonnet-4-6", "claude-opus-4-6", "claude-haiku-4-5",
1217
- ]:
1218
- model_type = "default"
1219
- auto_thinking = True
1220
- elif model_lower in ["deepseek-reasoner"]:
1221
- model_type = "default"
1222
- auto_thinking = True
1223
- elif model_lower in ["deepseek-v4-pro"]:
1224
- model_type = "expert"
1225
- auto_thinking = True
1226
- else:
1227
- raise HTTPException(
1228
- status_code=503, detail=f"Model '{model}' is not available."
1229
- )
1230
 
1231
  # ---------- Thinking (Anthropic 格式) ----------
1232
  thinking_obj = req_data.get("thinking")
 
34
  logger = logging.getLogger(__name__)
35
 
36
  router = APIRouter()
37
+ FORCED_MODEL = "deepseek-v4-pro-search"
38
+
39
+
40
+ def _forced_model_config():
41
+ return {
42
+ "model": FORCED_MODEL,
43
+ "model_lower": "deepseek-v4-pro",
44
+ "model_type": "expert",
45
+ "search_by_model": True,
46
+ "auto_thinking": True,
47
+ "lock_thinking": False,
48
+ }
49
 
50
 
51
  # ----------------------------------------------------------------------
 
76
  # 路由:/v1/models
77
  # ----------------------------------------------------------------------
78
  BASE_MODELS = [
 
 
 
79
  "deepseek-v4-pro",
80
  ]
81
 
82
 
83
  @router.get("/v1/models")
84
  def list_models():
85
+ models_list = [{
86
+ "id": FORCED_MODEL,
87
+ "object": "model",
88
+ "created": 1677610602,
89
+ "owned_by": "deepseek",
90
+ "permission": [],
91
+ }]
 
 
 
 
 
 
 
 
 
92
  data = {"object": "list", "data": models_list}
93
  return JSONResponse(content=data, status_code=200)
94
 
 
432
  async def responses_api(request: Request):
433
  try:
434
  req_data = await request.json()
435
+ forced = _forced_model_config()
436
+ model = forced["model"]
437
  messages = _responses_input_to_messages(req_data)
438
+ if not messages:
439
  return JSONResponse(
440
  status_code=400,
441
  content={"error": "Request must include 'model' and a non-empty 'input'."},
 
501
  )
502
 
503
  req_data = await request.json()
504
+ forced = _forced_model_config()
505
+ model = forced["model"]
506
  messages = req_data.get("messages", [])
507
+ if not messages:
508
  raise HTTPException(
509
  status_code=400, detail="Request must include 'model' and 'messages'."
510
  )
511
+ model_type = forced["model_type"]
512
+ auto_thinking = forced["auto_thinking"]
513
+ lock_thinking = forced["lock_thinking"]
514
+ search_by_model = forced["search_by_model"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
  # 解析 thinking,支持 thinking_enabled 和 thinking.type 两种格式
516
  if lock_thinking:
517
  thinking_enabled = True
 
1183
  )
1184
 
1185
  req_data = await request.json()
1186
+ forced = _forced_model_config()
1187
+ model = forced["model"]
1188
+ model_type = forced["model_type"]
1189
+ auto_thinking = forced["auto_thinking"]
1190
+ search_by_model = forced["search_by_model"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1191
 
1192
  # ---------- Thinking (Anthropic 格式) ----------
1193
  thinking_obj = req_data.get("thinking")