Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Feat: Config/override max_output_tokens (#1036)

Kilian Liereta352250e669c
diff --git a/sweagent/agent/models.py b/sweagent/agent/models.py
index 62791fdc..54d5f796 100644
--- a/sweagent/agent/models.py
+++ b/sweagent/agent/models.py
@@ -130,6 +130,14 @@ class GenericAPIModelConfig(PydanticBaseModel):
Set this to 0 to disable this check.
"""
+ max_output_tokens: int | None = None
+ """If set, this will override the max output tokens for the model that we usually look
+ up from `litellm.model_cost`.
+ Use this for local models or if you want to set a custom max output token limit.
+ If this value is exceeded, a `ContextWindowExceededError` will be raised.
+ Set this to 0 to disable this check.
+ """
+
# pydantic
model_config = ConfigDict(extra="forbid")
@@ -566,7 +574,11 @@ class LiteLLMModel(AbstractModel):
else:
self.model_max_input_tokens = litellm.model_cost.get(self.config.name, {}).get("max_input_tokens")
- self.model_max_output_tokens = litellm.model_cost.get(self.config.name, {}).get("max_output_tokens")
+ if self.config.max_output_tokens is not None:
+ self.model_max_output_tokens = self.config.max_output_tokens
+ else:
+ self.model_max_output_tokens = litellm.model_cost.get(self.config.name, {}).get("max_output_tokens")
+
self.lm_provider = litellm.model_cost.get(self.config.name, {}).get("litellm_provider")
self.logger = get_logger("swea-lm", emoji="🤖")