MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _should_use_max_completion_tokens

Function _should_use_max_completion_tokens

codewiki/src/be/llm_services.py:23–38  ·  view source on GitHub ↗

Determine whether to use max_completion_tokens instead of max_tokens. Newer OpenAI models (o1, o3, o4, gpt-4o, gpt-5, etc.) require max_completion_tokens. Anthropic and other providers still use max_tokens.

(model_name: str, base_url: str)

Source from the content-addressed store, hash-verified

21
22# (base_url, model_name) pairs whose provider rejected cache_control markers.
23# Module-level because sub-agent runs re-create model instances per tool call
24# (see generate_sub_module_documentations); the fallback probe should only
25# happen once per provider/model, not once per sub-module.
26_CACHE_UNSUPPORTED: set = set()
27
28_EPHEMERAL_CACHE = {"type": "ephemeral"}
29
30
31def _add_cache_control_to_message(message) -> None:
32 """Attach an ephemeral ``cache_control`` marker to an OpenAI-format message in place.
33
34 Tool messages get the marker at message level: OpenAI-compatible proxies
35 (e.g. LiteLLM) map that onto the Anthropic ``tool_result`` block, whereas a
36 part-level marker would land on a nested block, which Anthropic rejects.
37 Other roles get it on the last content part (string content is converted to
38 a single text part).
39 """
40 if message.get("role") == "tool":
41 message.setdefault("cache_control", dict(_EPHEMERAL_CACHE))

Callers 2

_build_model_settingsFunction · 0.85
call_llmFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected