Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pr_agent/algo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
'anthropic/claude-3-5-sonnet-20240620': 100000,
'anthropic/claude-3-5-sonnet-20241022': 100000,
'anthropic/claude-3-7-sonnet-20250219': 200000,
'claude-3-7-sonnet-20250219': 200000,
'anthropic/claude-sonnet-4-20250514': 1000000,
'anthropic/claude-3-5-haiku-20241022': 100000,
'bedrock/anthropic.claude-instant-v1': 100000,
'bedrock/anthropic.claude-v2': 100000,
Expand Down Expand Up @@ -167,7 +167,7 @@

CLAUDE_EXTENDED_THINKING_MODELS = [
"anthropic/claude-opus-4-20250514",
"anthropic/claude-sonnet-4-20250514",
"anthropic/claude-sonnet-4-20250514",
"anthropic/claude-3-7-sonnet-20250219",
"claude-3-7-sonnet-20250219"
]
19 changes: 17 additions & 2 deletions pr_agent/algo/ai_handlers/litellm_ai_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,30 @@ async def chat_completion(self, model: str, system: str, user: str, temperature:
if self.repetition_penalty:
kwargs["repetition_penalty"] = self.repetition_penalty

#Added support for extra_headers while using litellm to call underlying model, via a api management gateway, would allow for passing custom headers for security and authorization
# Added support for extra_headers while using litellm to call underlying model, via a api management gateway, would allow for passing custom headers for security and authorization
if get_settings().get("LITELLM.EXTRA_HEADERS", None):
try:
litellm_extra_headers = json.loads(get_settings().litellm.extra_headers)
if not isinstance(litellm_extra_headers, dict):
raise ValueError("LITELLM.EXTRA_HEADERS must be a JSON object")
except json.JSONDecodeError as e:
raise ValueError(f"LITELLM.EXTRA_HEADERS contains invalid JSON: {str(e)}")
kwargs["extra_headers"] = litellm_extra_headers
# Merge with any pre-existing headers
merged_headers = dict(kwargs.get("extra_headers", {}))
merged_headers.update(litellm_extra_headers)
kwargs["extra_headers"] = merged_headers

# Ensure Anthropic 1M-context beta is enabled for relevant Claude models (not Bedrock)
try:
if (
("claude" in model.lower() or model.lower().startswith("anthropic/"))
and not model.lower().startswith("bedrock/")
):
headers = dict(kwargs.get("extra_headers", {}))
headers.setdefault("anthropic-beta", "context-1m-2025-08-07")
kwargs["extra_headers"] = headers
except Exception as e:
get_logger().debug(f"Unable to set Anthropic beta header: {e}")

get_logger().debug("Prompts", artifact={"system": system, "user": user})

Expand Down