The world's first agentic reverse engineer.
feat: add base_url parameter to OpenAIClient
Amruthbbbbc39215dc
diff --git a/kong/llm/openai_client.py b/kong/llm/openai_client.pyindex 83b1f51..44aeb55 100644--- a/kong/llm/openai_client.py+++ b/kong/llm/openai_client.py@@ -55,10 +55,11 @@ class OpenAIClient:model: str = DEFAULT_MODEL,max_tokens: int = 2048,api_key: str | None = None,+ base_url: str | None = None,) -> None:self.model = modelself.max_tokens = max_tokens- self._client = openai.OpenAI(api_key=api_key, max_retries=5)+ self._client = openai.OpenAI(api_key=api_key, base_url=base_url, max_retries=5)self.usage = TokenUsage()def analyze_function(self, prompt: str, *, model: str | None = None) -> LLMResponse:diff --git a/tests/test_llm_client.py b/tests/test_llm_client.pyindex 114f304..1253898 100644--- a/tests/test_llm_client.py+++ b/tests/test_llm_client.py@@ -237,6 +237,34 @@ class TestAnalyzeFunctionBatch:assert client.usage.calls == 1+class TestOpenAIClientBaseUrl:+ @patch("kong.llm.openai_client.openai.OpenAI")+ def test_base_url_passed_to_sdk(self, mock_openai_cls):+ from kong.llm.openai_client import OpenAIClient++ OpenAIClient(+ model="llama3:8b",+ base_url="http://localhost:11434/v1",+ api_key="test",+ )+ mock_openai_cls.assert_called_once_with(+ api_key="test",+ base_url="http://localhost:11434/v1",+ max_retries=5,+ )++ @patch("kong.llm.openai_client.openai.OpenAI")+ def test_base_url_none_by_default(self, mock_openai_cls):+ from kong.llm.openai_client import OpenAIClient++ OpenAIClient(model="gpt-4o", api_key="sk-test")+ mock_openai_cls.assert_called_once_with(+ api_key="sk-test",+ base_url=None,+ max_retries=5,+ )++class TestProviderAwarePricing:def test_custom_provider_returns_zero_pricing(self):from kong.config import LLMProvider