mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
refactor(transports/codex): trim duplicated cache-key comments
The xAI prompt_cache_key block carried two long comment paragraphs that either restated setdefault semantics, narrated the SDK type-validation mechanism, or recapped the historical motivation for the extra_body indirection — all already covered by the test docstring at test_xai_responses_sends_cache_key_via_extra_body (which links to the xAI docs). Also restored the truncated link in the body-injection comment. No behavior change.
This commit is contained in:
parent
e13c1b8060
commit
7fdc16dd4a
2 changed files with 6 additions and 19 deletions
|
|
@ -102,11 +102,8 @@ class ResponsesApiTransport(ProviderTransport):
|
||||||
kwargs["parallel_tool_calls"] = True
|
kwargs["parallel_tool_calls"] = True
|
||||||
|
|
||||||
session_id = params.get("session_id")
|
session_id = params.get("session_id")
|
||||||
# xAI's Responses API uses `prompt_cache_key` (body-level) as the
|
# xAI Responses takes prompt_cache_key in extra_body (set further
|
||||||
# cache-routing key, not a top-level kwarg — the body-field
|
# down); GitHub Models opts out of cache-key routing entirely.
|
||||||
# injection below survives openai SDK builds whose
|
|
||||||
# Responses.stream() signature drops the kwarg. Everything else
|
|
||||||
# that ISN'T github/xAI keeps using the typed kwarg.
|
|
||||||
if not is_github_responses and not is_xai_responses and session_id:
|
if not is_github_responses and not is_xai_responses and session_id:
|
||||||
kwargs["prompt_cache_key"] = session_id
|
kwargs["prompt_cache_key"] = session_id
|
||||||
|
|
||||||
|
|
@ -172,15 +169,10 @@ class ResponsesApiTransport(ProviderTransport):
|
||||||
merged_extra_headers["x-grok-conv-id"] = session_id
|
merged_extra_headers["x-grok-conv-id"] = session_id
|
||||||
kwargs["extra_headers"] = merged_extra_headers
|
kwargs["extra_headers"] = merged_extra_headers
|
||||||
|
|
||||||
# xAI Responses cache-routing field. Lives in the request body
|
# xAI Responses cache-routing — body-level field per
|
||||||
# (per https://docs.x.ai/.../prompt-caching/maximizing-cache-hits),
|
# https://docs.x.ai/developers/advanced-api-usage/prompt-caching/maximizing-cache-hits.
|
||||||
# so we ship it via extra_body — the openai SDK serializes
|
# Sent via extra_body (not the typed kwarg) so it survives openai
|
||||||
# extra_body fields into the JSON body without per-field type
|
# SDK builds whose Responses.stream() signature has dropped the field.
|
||||||
# validation, sidestepping the TypeError that fires on
|
|
||||||
# Responses.stream() builds whose `prompt_cache_key` kwarg has
|
|
||||||
# been dropped. Setdefault preserves a caller-supplied value
|
|
||||||
# (e.g. request_overrides.extra_body.prompt_cache_key) over
|
|
||||||
# the auto-derived session_id.
|
|
||||||
existing_extra_body = kwargs.get("extra_body")
|
existing_extra_body = kwargs.get("extra_body")
|
||||||
merged_extra_body: Dict[str, Any] = {}
|
merged_extra_body: Dict[str, Any] = {}
|
||||||
if isinstance(existing_extra_body, dict):
|
if isinstance(existing_extra_body, dict):
|
||||||
|
|
|
||||||
|
|
@ -117,13 +117,8 @@ class TestCodexBuildKwargs:
|
||||||
session_id="conv-xai-1",
|
session_id="conv-xai-1",
|
||||||
is_xai_responses=True,
|
is_xai_responses=True,
|
||||||
)
|
)
|
||||||
# Top-level prompt_cache_key must NOT be set for xAI — the SDK
|
|
||||||
# signature drop is what motivated the extra_body indirection in
|
|
||||||
# the first place. The cache-routing field must travel in the
|
|
||||||
# body via extra_body.
|
|
||||||
assert "prompt_cache_key" not in kw
|
assert "prompt_cache_key" not in kw
|
||||||
assert kw.get("extra_body", {}).get("prompt_cache_key") == "conv-xai-1"
|
assert kw.get("extra_body", {}).get("prompt_cache_key") == "conv-xai-1"
|
||||||
# Header kept as belt-and-braces.
|
|
||||||
assert kw.get("extra_headers", {}).get("x-grok-conv-id") == "conv-xai-1"
|
assert kw.get("extra_headers", {}).get("x-grok-conv-id") == "conv-xai-1"
|
||||||
|
|
||||||
def test_xai_responses_extra_body_preserves_caller_fields(self, transport):
|
def test_xai_responses_extra_body_preserves_caller_fields(self, transport):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue