-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(algo): let any model run — litellm-backed context window + base-name capability tables #2508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
de0a4e1
684d529
d73a9d1
3943da6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,27 @@ | ||
| import re | ||
|
|
||
| # Deployment-decoration tokens that appear between the provider prefix and the model | ||
| # identity: Bedrock cross-region prefixes and cloud vendor names. | ||
| _PROVIDER_INFIX = {"us", "eu", "au", "jp", "apac", "global", | ||
| "anthropic", "meta", "amazon", "ai21", "cohere", "mistral"} | ||
|
|
||
|
|
||
| def base_model_name(model: str) -> str: | ||
| """Strip deployment decoration so every provider spelling of a model maps to one key. | ||
|
|
||
| e.g. ``anthropic/claude-opus-4-8``, ``bedrock/us.anthropic.claude-opus-4-8-v1:0`` and | ||
| ``vertex_ai/claude-opus-4-8`` all collapse to ``claude-opus-4-8``. Used for the capability | ||
| sets below, which are keyed by base model rather than by every provider-prefixed variant. | ||
| """ | ||
| m = model.split("/", 1)[-1] # drop provider prefix (anthropic/, bedrock/, vertex_ai/, ...) | ||
| m = m.replace("@", "-") # vertex date separator -> '-' (matches anthropic spelling) | ||
| m = re.sub(r"-v\d+:\d+$", "", m) # bedrock cloud-version suffix (-v1:0) | ||
| parts = m.split(".") | ||
| while len(parts) > 1 and parts[0] in _PROVIDER_INFIX: # bedrock region + vendor infixes | ||
| parts.pop(0) | ||
| return ".".join(parts) # dotted model versions (gpt-5.2) are preserved | ||
|
Comment on lines
+16
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Bedrock v2 name mangled base_model_name() strips any trailing -v<digits>:<digits> suffix, which incorrectly removes the -v2:1 portion from Bedrock’s anthropic.claude-v2:1 identifier and collapses it to claude. This can cause base-name matching to miss for plausible regional spellings (e.g. bedrock/us.anthropic.claude-v2:1), leading capability gating and token-window selection to fall back to the wrong model key. Agent Prompt
|
||
|
|
||
|
|
||
| MAX_TOKENS = { | ||
| 'text-embedding-ada-002': 8000, | ||
| 'gpt-3.5-turbo': 16000, | ||
|
|
@@ -298,15 +322,19 @@ | |
| "codestral/codestral-2405": 8191, | ||
| } | ||
|
|
||
| USER_MESSAGE_ONLY_MODELS = [ | ||
| "deepseek/deepseek-reasoner", | ||
| # The capability sets below are keyed by base model name (see base_model_name); membership is | ||
| # checked with `base_model_name(model) in <set>`, so each model is listed once regardless of | ||
| # provider prefix, Bedrock region, or cloud-version/date suffix. | ||
|
|
||
| USER_MESSAGE_ONLY_MODELS = { | ||
| "deepseek-reasoner", | ||
| "o1-mini", | ||
| "o1-mini-2024-09-12", | ||
| "o1-preview" | ||
| ] | ||
| "o1-preview", | ||
| } | ||
|
|
||
| NO_SUPPORT_TEMPERATURE_MODELS = [ | ||
| "deepseek/deepseek-reasoner", | ||
| NO_SUPPORT_TEMPERATURE_MODELS = { | ||
| "deepseek-reasoner", | ||
| "o1-mini", | ||
| "o1-mini-2024-09-12", | ||
| "o1", | ||
|
|
@@ -323,104 +351,40 @@ | |
| "gpt-5.2-codex", | ||
| "gpt-5.3-codex", | ||
| "gpt-5-mini", | ||
| # Anthropic Claude Opus 4-7 — temperature is deprecated (Issue #2400), (Issue #2449) | ||
| # Anthropic Claude — temperature is deprecated (Issue #2400), (Issue #2449) | ||
| "claude-opus-4-7", | ||
| "anthropic/claude-opus-4-7", | ||
| "claude-opus-4-8", | ||
| "anthropic/claude-opus-4-8", | ||
| "vertex_ai/claude-opus-4-8", | ||
| "bedrock/anthropic.claude-opus-4-8", | ||
| "bedrock/global.anthropic.claude-opus-4-8", | ||
| "bedrock/us.anthropic.claude-opus-4-8", | ||
| "bedrock/eu.anthropic.claude-opus-4-8", | ||
| "bedrock/au.anthropic.claude-opus-4-8", | ||
| "bedrock/jp.anthropic.claude-opus-4-8", | ||
| "claude-fable-5", | ||
| "anthropic/claude-fable-5", | ||
| "claude-sonnet-5", | ||
| "anthropic/claude-sonnet-5", | ||
| "vertex_ai/claude-sonnet-5", | ||
| "bedrock/anthropic.claude-sonnet-5", | ||
| "bedrock/global.anthropic.claude-sonnet-5", | ||
| "bedrock/us.anthropic.claude-sonnet-5", | ||
| "bedrock/au.anthropic.claude-sonnet-5", | ||
| "bedrock/eu.anthropic.claude-sonnet-5", | ||
| "bedrock/jp.anthropic.claude-sonnet-5", | ||
| "vertex_ai/claude-opus-4-7", | ||
| "bedrock/anthropic.claude-opus-4-7", | ||
| "bedrock/anthropic.claude-opus-4-7-v1:0", | ||
| "bedrock/us.anthropic.claude-opus-4-7", | ||
| "bedrock/global.anthropic.claude-opus-4-7", | ||
| ] | ||
| } | ||
|
|
||
| SUPPORT_REASONING_EFFORT_MODELS = [ | ||
| SUPPORT_REASONING_EFFORT_MODELS = { | ||
| "o3-mini", | ||
| "o3-mini-2025-01-31", | ||
| "o3", | ||
| "o3-2025-04-16", | ||
| "o4-mini", | ||
| "o4-mini-2025-04-16", | ||
| ] | ||
| } | ||
|
|
||
| # Claude models that support "extended thinking" through the manual | ||
| # thinking={"type": "enabled", "budget_tokens": ...} request built by | ||
| # LiteLLMAIHandler._configure_claude_extended_thinking(). Only models that | ||
| # accept budget_tokens belong here. Adaptive-only models (Claude Opus 4.7/4.8, | ||
| # Sonnet 5, Fable 5) reject budget_tokens with an HTTP 400 and must not be added | ||
| # without also adding an adaptive-thinking code path. This list is the built-in | ||
| # without also adding an adaptive-thinking code path. This set is the built-in | ||
| # default; it can be replaced via the `claude_extended_thinking_models_override` | ||
| # configuration option. | ||
| CLAUDE_EXTENDED_THINKING_MODELS = [ | ||
| "anthropic/claude-3-7-sonnet-20250219", | ||
| CLAUDE_EXTENDED_THINKING_MODELS = { | ||
| "claude-3-7-sonnet-20250219", | ||
| "anthropic/claude-sonnet-4-6", | ||
| "claude-sonnet-4-6", | ||
| "vertex_ai/claude-sonnet-4-6", | ||
| "bedrock/anthropic.claude-sonnet-4-6", | ||
| "bedrock/us.anthropic.claude-sonnet-4-6", | ||
| "bedrock/au.anthropic.claude-sonnet-4-6", | ||
| "bedrock/eu.anthropic.claude-sonnet-4-6", | ||
| "bedrock/jp.anthropic.claude-sonnet-4-6", | ||
| "bedrock/global.anthropic.claude-sonnet-4-6", | ||
| "anthropic/claude-sonnet-4-5-20250929", | ||
| "claude-sonnet-4-5-20250929", | ||
| "vertex_ai/claude-sonnet-4-5@20250929", | ||
| "bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "bedrock/au.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "bedrock/eu.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "bedrock/jp.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "bedrock/global.anthropic.claude-sonnet-4-5-20250929-v1:0", | ||
| "anthropic/claude-opus-4-5-20251101", | ||
| "claude-opus-4-5-20251101", | ||
| "vertex_ai/claude-opus-4-5@20251101", | ||
| "bedrock/anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "bedrock/us.anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "bedrock/au.anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "bedrock/eu.anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "bedrock/jp.anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "bedrock/global.anthropic.claude-opus-4-5-20251101-v1:0", | ||
| "anthropic/claude-opus-4-6", | ||
| "claude-opus-4-6", | ||
| "vertex_ai/claude-opus-4-6", | ||
| "bedrock/anthropic.claude-opus-4-6-v1:0", | ||
| "bedrock/us.anthropic.claude-opus-4-6-v1:0", | ||
| "bedrock/au.anthropic.claude-opus-4-6-v1:0", | ||
| "bedrock/eu.anthropic.claude-opus-4-6-v1:0", | ||
| "bedrock/jp.anthropic.claude-opus-4-6-v1:0", | ||
| "bedrock/global.anthropic.claude-opus-4-6-v1:0", | ||
| "anthropic/claude-haiku-4-5-20251001", | ||
| "claude-haiku-4-5-20251001", | ||
| "vertex_ai/claude-haiku-4-5@20251001", | ||
| "bedrock/anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| "bedrock/au.anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| "bedrock/eu.anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| "bedrock/jp.anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| "bedrock/global.anthropic.claude-haiku-4-5-20251001-v1:0", | ||
| ] | ||
| } | ||
|
|
||
| # Models that require streaming mode | ||
| STREAMING_REQUIRED_MODELS = [ | ||
| "openai/qwq-plus" | ||
| ] | ||
| STREAMING_REQUIRED_MODELS = { | ||
| "qwq-plus", | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| NO_SUPPORT_TEMPERATURE_MODELS, | ||
| STREAMING_REQUIRED_MODELS, | ||
| SUPPORT_REASONING_EFFORT_MODELS, | ||
| USER_MESSAGE_ONLY_MODELS) | ||
| USER_MESSAGE_ONLY_MODELS, base_model_name) | ||
|
Comment on lines
14
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. base_model_name import unsorted The modified from pr_agent.algo import (...) block is not isort-sorted (e.g., base_model_name is appended after the constants). This can violate Ruff/isort checks and causes avoidable churn in future automated formatting runs. Agent Prompt
|
||
| from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler | ||
| from pr_agent.algo.ai_handlers.litellm_helpers import ( | ||
| MockResponse, _get_azure_ad_token, _handle_streaming_response, | ||
|
|
@@ -257,11 +257,11 @@ def __init__(self): | |
| "Falling back to the built-in Claude extended-thinking model list." | ||
| ) | ||
| override = [] | ||
| # Store stripped names so exact-match checks against the model succeed even when the config | ||
| # entries contain surrounding whitespace (validation above already used model.strip()). | ||
| self.claude_extended_thinking_models = ( | ||
| [model.strip() for model in override] if override else CLAUDE_EXTENDED_THINKING_MODELS | ||
| ) | ||
| # Normalize to base model names so membership checks match regardless of provider prefix, | ||
| # whether the entries come from config override or the built-in default. | ||
| self.claude_extended_thinking_models = { | ||
| base_model_name(model.strip()) for model in override | ||
| } if override else set(CLAUDE_EXTENDED_THINKING_MODELS) | ||
|
|
||
| # Models that require streaming | ||
| self.streaming_required_models = STREAMING_REQUIRED_MODELS | ||
|
|
@@ -508,7 +508,7 @@ async def chat_completion(self, model: str, system: str, user: str, temperature: | |
|
|
||
|
|
||
| # Currently, some models do not support a separate system and user prompts | ||
| if model in self.user_message_only_models or get_settings().config.custom_reasoning_model: | ||
| if base_model_name(model) in self.user_message_only_models or get_settings().config.custom_reasoning_model: | ||
| user = f"{system}\n\n\n{user}" | ||
| system = "" | ||
| get_logger().info(f"Using model {model}, combining system and user prompts") | ||
|
|
@@ -528,7 +528,7 @@ async def chat_completion(self, model: str, system: str, user: str, temperature: | |
| } | ||
|
|
||
| # Add temperature only if model supports it | ||
| if model not in self.no_support_temperature_models and not get_settings().config.custom_reasoning_model: | ||
| if base_model_name(model) not in self.no_support_temperature_models and not get_settings().config.custom_reasoning_model: | ||
| # get_logger().info(f"Adding temperature with value {temperature} to model {model}.") | ||
| kwargs["temperature"] = temperature | ||
|
|
||
|
|
@@ -538,7 +538,7 @@ async def chat_completion(self, model: str, system: str, user: str, temperature: | |
| del kwargs['temperature'] | ||
|
|
||
| # Add reasoning_effort if model supports it | ||
| if model in self.support_reasoning_models: | ||
| if base_model_name(model) in self.support_reasoning_models: | ||
| config_effort = get_settings().config.reasoning_effort | ||
| try: | ||
| ReasoningEffort(config_effort) | ||
|
|
@@ -555,7 +555,7 @@ async def chat_completion(self, model: str, system: str, user: str, temperature: | |
| kwargs["reasoning_effort"] = reasoning_effort | ||
|
|
||
| # https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking | ||
| if (model in self.claude_extended_thinking_models) and get_settings().config.get("enable_claude_extended_thinking", False): | ||
| if (base_model_name(model) in self.claude_extended_thinking_models) and get_settings().config.get("enable_claude_extended_thinking", False): | ||
| kwargs = self._configure_claude_extended_thinking(model, kwargs) | ||
|
|
||
| if get_settings().litellm.get("enable_callbacks", False): | ||
|
|
@@ -642,7 +642,7 @@ async def _get_completion(self, **kwargs): | |
| Wrapper that automatically handles streaming for required models. | ||
| """ | ||
| model = kwargs["model"] | ||
| if model in self.streaming_required_models: | ||
| if base_model_name(model) in self.streaming_required_models: | ||
| kwargs["stream"] = True | ||
| get_logger().info(f"Using streaming mode for model {model}") | ||
| response = await acompletion(**kwargs) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Stacked prefix not stripped
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools