localhost base_url fixup when running in a docker container (#11474)

Co-authored-by: Rohit Malhotra <rohitvinodmalhotra@gmail.com>
This commit is contained in:
eddierichter-amd
2025-11-04 15:57:25 -07:00
committed by GitHub
parent 308d0e62ab
commit c544ea1187
6 changed files with 128 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
import pytest
from openhands.utils import environment
@pytest.fixture(autouse=True)
def clear_docker_cache():
if hasattr(environment.is_running_in_docker, 'cache_clear'):
environment.is_running_in_docker.cache_clear()
yield
if hasattr(environment.is_running_in_docker, 'cache_clear'):
environment.is_running_in_docker.cache_clear()
def test_get_effective_base_url_lemonade_in_docker(monkeypatch):
monkeypatch.setattr(environment, 'is_running_in_docker', lambda: True)
result = environment.get_effective_llm_base_url('lemonade/example', None)
assert result == environment.LEMONADE_DOCKER_BASE_URL
def test_get_effective_base_url_lemonade_outside_docker(monkeypatch):
monkeypatch.setattr(environment, 'is_running_in_docker', lambda: False)
base_url = 'http://localhost:8000/api/v1/'
result = environment.get_effective_llm_base_url('lemonade/example', base_url)
assert result == base_url
def test_get_effective_base_url_non_lemonade(monkeypatch):
monkeypatch.setattr(environment, 'is_running_in_docker', lambda: True)
base_url = 'https://api.example.com'
result = environment.get_effective_llm_base_url('openai/gpt-4', base_url)
assert result == base_url