forked from Alishahryar1/free-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra_body.py
More file actions
63 lines (55 loc) · 1.55 KB
/
Copy pathextra_body.py
File metadata and controls
63 lines (55 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Validation helpers for OpenAI-chat ``extra_body`` passthrough."""
from typing import Any
CANONICAL_OPENAI_CHAT_BODY_KEYS = frozenset(
{
"model",
"messages",
"tools",
"tool_choice",
"stream",
"max_tokens",
"max_completion_tokens",
"temperature",
"top_p",
"metadata",
"stop",
"stop_sequences",
"stream_options",
"reasoning",
"reasoning_effort",
"reasoning_tokens",
"thinking",
"thinking_budget_tokens",
"enable_thinking",
"thinking_budget",
}
)
REASONING_OPENAI_CHAT_BODY_KEYS = frozenset(
{
"reasoning",
"reasoning_effort",
"reasoning_tokens",
"thinking",
"thinking_budget_tokens",
"enable_thinking",
"thinking_budget",
}
)
def validate_extra_body_does_not_override_canonical_fields(
extra: dict[str, Any],
) -> None:
"""Reject extras that would replace FCC-owned chat-completion fields."""
bad = CANONICAL_OPENAI_CHAT_BODY_KEYS & extra.keys()
if bad:
raise ValueError(
f"extra_body must not override canonical request fields: {sorted(bad)}"
)
def validate_extra_body_does_not_override_reasoning_fields(
extra: dict[str, Any],
) -> None:
"""Keep provider reasoning translation authoritative over caller extras."""
bad = REASONING_OPENAI_CHAT_BODY_KEYS & extra.keys()
if bad:
raise ValueError(
f"extra_body must not override reasoning fields: {sorted(bad)}"
)