mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-05-20 17:40:50 +00:00
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""Request builder for OpenCode Zen provider."""
|
|
|
|
from typing import Any
|
|
|
|
from loguru import logger
|
|
|
|
from core.anthropic import ReasoningReplayMode, 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 OpenCode Zen."""
|
|
logger.debug(
|
|
"OPENCODE_REQUEST: conversion start model={} msgs={}",
|
|
getattr(request_data, "model", "?"),
|
|
len(getattr(request_data, "messages", [])),
|
|
)
|
|
try:
|
|
body = build_base_request_body(
|
|
request_data,
|
|
reasoning_replay=ReasoningReplayMode.REASONING_CONTENT
|
|
if thinking_enabled
|
|
else ReasoningReplayMode.DISABLED,
|
|
)
|
|
except OpenAIConversionError as exc:
|
|
raise InvalidRequestError(str(exc)) from exc
|
|
|
|
logger.debug(
|
|
"OPENCODE_REQUEST: conversion done model={} msgs={} tools={}",
|
|
body.get("model"),
|
|
len(body.get("messages", [])),
|
|
len(body.get("tools", [])),
|
|
)
|
|
return body
|