Skip to content

Commit aac7e92

Browse files
committed
Update mock_server.py
1 parent 1760de7 commit aac7e92

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

tests/mock_server.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ def __init__(self, api_key: str, extra_headers: Optional[Dict[str, str]] = None)
151151
# We instantiate a new client per request to ensure isolation of user credentials
152152
if extra_headers is None:
153153
extra_headers = {}
154-
logger.debug(
155-
"Initializing DeepSeekProxy client with headers: %s",
156-
[k for k in extra_headers.keys() if k.lower() != "x-api-key"],
157-
)
158154
if "x-api-key" in extra_headers and extra_headers["x-api-key"]:
159155
api_key = extra_headers["x-api-key"]
160156

@@ -431,6 +427,31 @@ async def generate(self, req_data: GenerationRequest, initial_request_id: str):
431427
if stop_list:
432428
openai_params["stop"] = stop_list
433429

430+
# --- 生成 Curl 命令 (过滤掉非法 Header) ---
431+
# 1. 基础 Header
432+
curl_headers = [
433+
f"-H 'Authorization: Bearer $SILICONFLOW_API_KEY'",
434+
"-H 'Content-Type: application/json'",
435+
]
436+
437+
# 2. 补充透传的 Header (过滤掉 Omit 对象和不需要的字段)
438+
# default_headers 包含了初始化时传入的 extra_headers
439+
skip_keys = {"authorization", "content-type", "content-length", "host"}
440+
for k, v in self.client.default_headers.items():
441+
# 过滤掉 OpenAI 内部的 Omit 对象 和 系统自动生成的头
442+
if k.lower() not in skip_keys and not str(v).startswith("<openai."):
443+
curl_headers.append(f"-H '{k}: {v}'")
444+
445+
# 3. 组装命令
446+
curl_cmd = (
447+
f"curl -X POST {SILICON_FLOW_BASE_URL}/chat/completions \\\n "
448+
+ " \\\n ".join(curl_headers)
449+
+ f" \\\n -d '{json.dumps(openai_params, ensure_ascii=False)}'"
450+
)
451+
452+
print(f"\n--- [Generated Curl] ---\n{curl_cmd}\n------------------------\n")
453+
# ----------------------------------------------------
454+
434455
try:
435456
if openai_params["stream"]:
436457
raw_resp = await self.client.chat.completions.with_raw_response.create(

0 commit comments

Comments
 (0)