Resolve _send_llm_request default max_tokens binding to support runtime overrides#235
Conversation
|
👋 Thanks for the PR, @copilot! To get this PR reviewed, please ⭐ star this repo — it's free and helps others discover it. Once starred, run A |
|
👋 Thanks for the PR, @copilot! To get this PR reviewed, please ⭐ star this repo — it's free and helps others discover it. Once starred, run A |
_send_llm_request default max_tokens binding to support runtime overrides
|
| Filename | Overview |
|---|---|
| termstory/ai.py | Signature change to _send_llm_request fixes definition-time default binding; 5 existing call sites still pass max_tokens=_DEFAULT_MAX_TOKENS explicitly (P2 style issue, already flagged in prior review). |
| tests/test_ai.py | Adds a focused regression test for the runtime default resolution; test is correctly structured and assertions are accurate. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Caller invokes _send_llm_request(...)"] --> B{max_tokens passed?}
B -- "Yes (explicit value)" --> D["Use caller-supplied max_tokens"]
B -- "No (None / omitted)" --> C["Read _DEFAULT_MAX_TOKENS\nat call time"]
C --> D
D --> E["Build request body\nwith resolved max_tokens"]
E --> F["POST to LLM endpoint"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["Caller invokes _send_llm_request(...)"] --> B{max_tokens passed?}
B -- "Yes (explicit value)" --> D["Use caller-supplied max_tokens"]
B -- "No (None / omitted)" --> C["Read _DEFAULT_MAX_TOKENS\nat call time"]
C --> D
D --> E["Build request body\nwith resolved max_tokens"]
E --> F["POST to LLM endpoint"]
Reviews (2): Last reviewed commit: "fix(ai): resolve max_tokens default at r..." | Re-trigger Greptile
|
@copilot fix whatever greptile flagged |
Addressed in |
|
@greptile-apps review |
|
/lgtm /approve /merge |
|
miku ✅ LGTM! Label added by @bitflicker64. Use miku ✅ Approved! 🎉 miku ✅ Merged! 🎉 |
This PR addresses the review comment about Python default argument evaluation in
_send_llm_request:max_tokenswas bound at function definition time, so later runtime updates to the module default were ignored. The change makes default resolution dynamic when callers omitmax_tokens.Runtime default resolution
_send_llm_request(max_tokens=...)from a definition-time constant to an optional parameter resolved inside the function body._DEFAULT_MAX_TOKENSvalues are used by defaulted calls.Focused regression coverage
termstory.ai._DEFAULT_MAX_TOKENSand asserts the outbound request payload uses the patched value whenmax_tokensis not passed.