Skip to content

Commit 268b669

Browse files
committed
remove unused client
1 parent aca83ea commit 268b669

3 files changed

Lines changed: 11 additions & 29 deletions

File tree

packages/ai-providers/server-ai-openai/src/ldai_openai/openai_agent_runner.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ldai import log
77
from ldai.providers import AgentResult, AgentRunner, ToolRegistry
88
from ldai.providers.types import LDAIMetrics
9-
from openai import AsyncOpenAI
109

1110
from ldai_openai.openai_helper import (
1211
NATIVE_OPENAI_TOOLS,
@@ -27,14 +26,12 @@ class OpenAIAgentRunner(AgentRunner):
2726

2827
def __init__(
2928
self,
30-
client: AsyncOpenAI,
3129
model_name: str,
3230
parameters: Dict[str, Any],
3331
instructions: str,
3432
tool_definitions: List[Dict[str, Any]],
3533
tools: ToolRegistry,
3634
):
37-
self._client = client
3835
self._model_name = model_name
3936
self._parameters = parameters
4037
self._instructions = instructions
@@ -155,7 +152,3 @@ def _build_model_settings(self) -> Any:
155152
}
156153
kwargs = {k: v for k, v in self._parameters.items() if k in known}
157154
return ModelSettings(**kwargs) if kwargs else None
158-
159-
def get_client(self) -> AsyncOpenAI:
160-
"""Return the underlying AsyncOpenAI client."""
161-
return self._client

packages/ai-providers/server-ai-openai/src/ldai_openai/openai_runner_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def create_agent(self, config: Any, tools: Optional[ToolRegistry] = None) -> 'Op
6868
instructions = (config.instructions or '') if hasattr(config, 'instructions') else ''
6969

7070
return OpenAIAgentRunner(
71-
self._client,
7271
model_name,
7372
parameters,
7473
instructions,

packages/ai-providers/server-ai-openai/tests/test_openai_provider.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -424,31 +424,21 @@ def _make_agents_mock(runner_run_mock: Any) -> MagicMock:
424424
mock_runner_cls = MagicMock()
425425
mock_runner_cls.run = runner_run_mock
426426

427-
mock_agent_cls = MagicMock()
428-
429-
mock_function_tool_cls = MagicMock(side_effect=lambda **kw: MagicMock(**kw))
430-
431-
mock_model_settings_cls = MagicMock(side_effect=lambda **kw: MagicMock(**kw))
432-
433427
mock_tool_context_module = MagicMock()
434428
mock_tool_context_module.ToolContext = MagicMock()
435429

436430
agents_mock = MagicMock()
437-
agents_mock.Agent = mock_agent_cls
431+
agents_mock.Agent = MagicMock()
438432
agents_mock.Runner = mock_runner_cls
439-
agents_mock.FunctionTool = mock_function_tool_cls
440-
agents_mock.ModelSettings = mock_model_settings_cls
433+
agents_mock.FunctionTool = MagicMock(side_effect=lambda **kw: MagicMock(**kw))
434+
agents_mock.ModelSettings = MagicMock(side_effect=lambda **kw: MagicMock(**kw))
441435

442436
return agents_mock, mock_tool_context_module
443437

444438

445439
class TestOpenAIAgentRunner:
446440
"""Tests for OpenAIAgentRunner.run."""
447441

448-
@pytest.fixture
449-
def mock_client(self):
450-
return MagicMock()
451-
452442
def _make_run_result(self, output: str, total: int = 15, input_tokens: int = 10, output_tokens: int = 5):
453443
"""Build a mock RunResult with final_output and context_wrapper.usage."""
454444
mock_usage = MagicMock()
@@ -465,7 +455,7 @@ def _make_run_result(self, output: str, total: int = 15, input_tokens: int = 10,
465455
return mock_result
466456

467457
@pytest.mark.asyncio
468-
async def test_runs_agent_and_returns_result_with_no_tool_calls(self, mock_client):
458+
async def test_runs_agent_and_returns_result_with_no_tool_calls(self):
469459
"""Should return AgentResult when Runner.run returns a final output."""
470460
import sys
471461

@@ -474,7 +464,7 @@ async def test_runs_agent_and_returns_result_with_no_tool_calls(self, mock_clien
474464
mock_run_result = self._make_run_result("The answer is 42.", total=15, input_tokens=10, output_tokens=5)
475465
agents_mock, tc_mock = _make_agents_mock(AsyncMock(return_value=mock_run_result))
476466

477-
runner = OpenAIAgentRunner(mock_client, 'gpt-4', {}, 'You are helpful.', [], {})
467+
runner = OpenAIAgentRunner('gpt-4', {}, 'You are helpful.', [], {})
478468
with patch.dict(sys.modules, {'agents': agents_mock, 'agents.tool_context': tc_mock}):
479469
result = await runner.run("What is the answer?")
480470

@@ -484,7 +474,7 @@ async def test_runs_agent_and_returns_result_with_no_tool_calls(self, mock_clien
484474
assert result.metrics.usage.total == 15
485475

486476
@pytest.mark.asyncio
487-
async def test_executes_tool_calls_and_returns_final_response(self, mock_client):
477+
async def test_executes_tool_calls_and_returns_final_response(self):
488478
"""Should delegate tool-calling loop to Runner.run and return final output."""
489479
import sys
490480

@@ -495,7 +485,7 @@ async def test_executes_tool_calls_and_returns_final_response(self, mock_client)
495485

496486
weather_fn = MagicMock(return_value="Sunny, 25°C")
497487
runner = OpenAIAgentRunner(
498-
mock_client, 'gpt-4', {}, 'You are helpful.',
488+
'gpt-4', {}, 'You are helpful.',
499489
[{'name': 'get-weather', 'description': 'Get weather', 'parameters': {}}],
500490
{'get-weather': weather_fn},
501491
)
@@ -507,29 +497,29 @@ async def test_executes_tool_calls_and_returns_final_response(self, mock_client)
507497
assert result.metrics.usage.total == 43
508498

509499
@pytest.mark.asyncio
510-
async def test_returns_failure_when_exception_thrown(self, mock_client):
500+
async def test_returns_failure_when_exception_thrown(self):
511501
"""Should return unsuccessful AgentResult when Runner.run raises."""
512502
import sys
513503

514504
from ldai_openai import OpenAIAgentRunner
515505

516506
agents_mock, tc_mock = _make_agents_mock(AsyncMock(side_effect=Exception("API Error")))
517507

518-
runner = OpenAIAgentRunner(mock_client, 'gpt-4', {}, '', [], {})
508+
runner = OpenAIAgentRunner('gpt-4', {}, '', [], {})
519509
with patch.dict(sys.modules, {'agents': agents_mock, 'agents.tool_context': tc_mock}):
520510
result = await runner.run("Hello")
521511

522512
assert result.output == ""
523513
assert result.metrics.success is False
524514

525515
@pytest.mark.asyncio
526-
async def test_returns_failure_when_openai_agents_not_installed(self, mock_client):
516+
async def test_returns_failure_when_openai_agents_not_installed(self):
527517
"""Should return unsuccessful AgentResult when openai-agents is not installed."""
528518
import sys
529519

530520
from ldai_openai import OpenAIAgentRunner
531521

532-
runner = OpenAIAgentRunner(mock_client, 'gpt-4', {}, '', [], {})
522+
runner = OpenAIAgentRunner('gpt-4', {}, '', [], {})
533523
with patch.dict(sys.modules, {'agents': None}):
534524
result = await runner.run("Hello")
535525

0 commit comments

Comments
 (0)