fix(llms): honor OPENAI_BASE_URL in structured provider (#6322)
This commit is contained in:
@@ -15,7 +15,7 @@ class OpenAIStructuredLLM(LLMBase):
|
||||
self.config.model = "gpt-5-mini"
|
||||
|
||||
api_key = self.config.api_key or os.getenv("OPENAI_API_KEY")
|
||||
base_url = self.config.openai_base_url or os.getenv("OPENAI_API_BASE") or "https://api.openai.com/v1"
|
||||
base_url = self.config.openai_base_url or os.getenv("OPENAI_BASE_URL") or "https://api.openai.com/v1"
|
||||
self.client = OpenAI(api_key=api_key, base_url=base_url)
|
||||
|
||||
def generate_response(
|
||||
|
||||
@@ -49,3 +49,14 @@ def test_regular_model_sends_sampling_params(mock_openai_client):
|
||||
assert "max_tokens" in call_kwargs # standard sampling params still forwarded
|
||||
assert "top_p" in call_kwargs
|
||||
assert call_kwargs["model"] == "gpt-4o"
|
||||
|
||||
|
||||
def test_uses_openai_base_url_environment_variable(monkeypatch):
|
||||
base_url = "https://gateway.example/v1"
|
||||
monkeypatch.setenv("OPENAI_API_BASE", "https://legacy.example/v1")
|
||||
monkeypatch.setenv("OPENAI_BASE_URL", base_url)
|
||||
|
||||
with patch("mem0.llms.openai_structured.OpenAI") as mock_openai:
|
||||
OpenAIStructuredLLM(OpenAIConfig(api_key="test-api-key"))
|
||||
|
||||
mock_openai.assert_called_once_with(api_key="test-api-key", base_url=base_url)
|
||||
|
||||
Reference in New Issue
Block a user