Skip to content

Commit d50a844

Browse files
tobitegeSmartManoj
andauthored
fix: add llm drop_params parameter to LLMConfig (OpenHands#2471)
* feat: add drop_params to LLMConfig * Update opendevin/llm/llm.py Fix use of unknown method. Co-authored-by: மனோஜ்குமார் பழனிச்சாமி <[email protected]> --------- Co-authored-by: மனோஜ்குமார் பழனிச்சாமி <[email protected]>
1 parent 405c8a0 commit d50a844

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

docs/modules/usage/llms/llms.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ OpenDevin will issue many prompts to the LLM you configure. Most of these LLMs c
1515
The `LLM_MODEL` environment variable controls which model is used in programmatic interactions.
1616
But when using the OpenDevin UI, you'll need to choose your model in the settings window.
1717

18-
The following environment variables might be necessary for some LLMs:
18+
The following environment variables might be necessary for some LLMs/providers:
1919

2020
- `LLM_API_KEY`
2121
- `LLM_BASE_URL`
2222
- `LLM_EMBEDDING_MODEL`
2323
- `LLM_EMBEDDING_DEPLOYMENT_NAME`
2424
- `LLM_API_VERSION`
25+
- `LLM_DROP_PARAMS`
2526

2627
We have a few guides for running OpenDevin with specific model providers:
2728

opendevin/core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class LLMConfig:
4949
input_cost_per_token: The cost per input token. This will available in logs for the user to check.
5050
output_cost_per_token: The cost per output token. This will available in logs for the user to check.
5151
ollama_base_url: The base URL for the OLLAMA API.
52+
drop_params: Drop any unmapped (unsupported) params without causing an exception.
5253
"""
5354

5455
model: str = 'gpt-4o'
@@ -75,6 +76,7 @@ class LLMConfig:
7576
input_cost_per_token: float | None = None
7677
output_cost_per_token: float | None = None
7778
ollama_base_url: str | None = None
79+
drop_params: bool | None = None
7880

7981
def defaults_to_dict(self) -> dict:
8082
"""Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""

opendevin/core/schema/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class ConfigType(str, Enum):
55
# For frontend
66
LLM_CUSTOM_LLM_PROVIDER = 'LLM_CUSTOM_LLM_PROVIDER'
7+
LLM_DROP_PARAMS = 'LLM_DROP_PARAMS'
78
LLM_MAX_INPUT_TOKENS = 'LLM_MAX_INPUT_TOKENS'
89
LLM_MAX_OUTPUT_TOKENS = 'LLM_MAX_OUTPUT_TOKENS'
910
LLM_TOP_P = 'LLM_TOP_P'

opendevin/llm/llm.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ def __init__(
5252
Args:
5353
config: The LLM configuration
5454
"""
55-
5655
self.config = copy.deepcopy(config)
5756
self.metrics = metrics if metrics is not None else Metrics()
5857
self.cost_metric_supported = True
5958

6059
# litellm actually uses base Exception here for unknown model
6160
self.model_info = None
6261
try:
63-
if not config.model.startswith('openrouter'):
64-
self.model_info = litellm.get_model_info(config.model.split(':')[0])
62+
if self.config.model.startswith('openrouter'):
63+
self.model_info = litellm.get_model_info(self.config.model)
6564
else:
66-
self.model_info = litellm.get_model_info(config.model)
65+
self.model_info = litellm.get_model_info(
66+
self.config.model.split(':')[0]
67+
)
6768
# noinspection PyBroadException
6869
except Exception:
6970
logger.warning(f'Could not get model info for {config.model}')
@@ -91,6 +92,9 @@ def __init__(
9192
# Max output tokens for gpt3.5, so this is a safe fallback for any potentially viable model
9293
self.config.max_output_tokens = 1024
9394

95+
if self.config.drop_params:
96+
litellm.drop_params = self.config.drop_params
97+
9498
self._completion = partial(
9599
litellm_completion,
96100
model=self.config.model,

0 commit comments

Comments
 (0)