free-claude-code/providers/deepseek/request.py
Alishahryar1 f3a7528d49
Some checks are pending
CI / checks (push) Waiting to run
Major refactor: API, providers, messaging, and Anthropic protocol
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
2026-04-26 03:01:14 -07:00

45 lines
1.4 KiB
Python

"""Request builder for DeepSeek provider."""
from typing import Any
from loguru import logger
from core.anthropic import build_base_request_body
from core.anthropic.conversion import OpenAIConversionError
from providers.exceptions import InvalidRequestError
def build_request_body(request_data: Any, *, thinking_enabled: bool) -> dict:
"""Build OpenAI-format request body from Anthropic request for DeepSeek."""
logger.debug(
"DEEPSEEK_REQUEST: conversion start model={} msgs={}",
getattr(request_data, "model", "?"),
len(getattr(request_data, "messages", [])),
)
try:
body = build_base_request_body(
request_data,
include_thinking=thinking_enabled,
include_reasoning_content=thinking_enabled,
)
except OpenAIConversionError as exc:
raise InvalidRequestError(str(exc)) from exc
extra_body: dict[str, Any] = {}
request_extra = getattr(request_data, "extra_body", None)
if request_extra:
extra_body.update(request_extra)
if thinking_enabled and body.get("model") != "deepseek-reasoner":
extra_body.setdefault("thinking", {"type": "enabled"})
if extra_body:
body["extra_body"] = extra_body
logger.debug(
"DEEPSEEK_REQUEST: conversion done model={} msgs={} tools={}",
body.get("model"),
len(body.get("messages", [])),
len(body.get("tools", [])),
)
return body