From 4e3a8625710189bdfce281d963d5ea0e0351780d Mon Sep 17 00:00:00 2001 From: Jesse Date: Tue, 12 Aug 2025 23:52:11 -0400 Subject: [PATCH] Add llm disable stop word env var (#10274) Co-authored-by: Xingyao Wang --- openhands/core/config/llm_config.py | 1 + openhands/llm/llm.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/openhands/core/config/llm_config.py b/openhands/core/config/llm_config.py index 2a11d95213..eaa381b835 100644 --- a/openhands/core/config/llm_config.py +++ b/openhands/core/config/llm_config.py @@ -80,6 +80,7 @@ class LLMConfig(BaseModel): # Note: this setting is actually global, unlike drop_params modify_params: bool = Field(default=True) disable_vision: bool | None = Field(default=None) + disable_stop_word: bool | None = Field(default=False) caching_prompt: bool = Field(default=True) log_completions: bool = Field(default=False) log_completions_folder: str = Field(default=os.path.join(LOG_DIR, 'completions')) diff --git a/openhands/llm/llm.py b/openhands/llm/llm.py index 8901b1665c..08d9308be6 100644 --- a/openhands/llm/llm.py +++ b/openhands/llm/llm.py @@ -305,8 +305,11 @@ class LLM(RetryMixin, DebugMixin): ) kwargs['messages'] = messages - # add stop words if the model supports it - if self.config.model not in MODELS_WITHOUT_STOP_WORDS: + # add stop words if the model supports it and stop words are not disabled + if ( + self.config.model not in MODELS_WITHOUT_STOP_WORDS + and not self.config.disable_stop_word + ): kwargs['stop'] = STOP_WORDS mock_fncall_tools = kwargs.pop('tools')