2525 AUTH_DISABLED ,
2626 TemplateRenderError ,
2727 _build_instructions ,
28+ _call_llm ,
2829 _compile_prompt_template ,
2930 _get_default_model_id ,
3031 _redact_sensitive_error_text ,
3132 _resolve_quota_subject ,
3233 infer_endpoint ,
33- retrieve_simple_response ,
3434)
3535from authentication .interface import AuthTuple
3636from authentication .rh_identity import RHIdentityData
@@ -480,40 +480,6 @@ async def test_get_default_model_id_auto_discovery_success(
480480 assert model_id == "openai/gpt-4o-mini"
481481
482482
483- # --- Test retrieve_simple_response ---
484-
485-
486- @pytest .mark .asyncio
487- async def test_retrieve_simple_response_success (
488- mock_configuration : AppConfig , mock_llm_response : None
489- ) -> None :
490- """Test retrieve_simple_response returns LLM response text."""
491- response = await retrieve_simple_response (
492- "How do I list files?" , constants .DEFAULT_SYSTEM_PROMPT
493- )
494- assert response == "This is a test LLM response."
495-
496-
497- @pytest .mark .asyncio
498- async def test_retrieve_simple_response_empty_output (
499- mock_configuration : AppConfig , mock_empty_llm_response : None
500- ) -> None :
501- """Test retrieve_simple_response handles empty LLM output."""
502- response = await retrieve_simple_response (
503- "Test question" , constants .DEFAULT_SYSTEM_PROMPT
504- )
505- assert response == ""
506-
507-
508- @pytest .mark .asyncio
509- async def test_retrieve_simple_response_api_connection_error (
510- mock_configuration : AppConfig , mock_api_connection_error : None
511- ) -> None :
512- """Test retrieve_simple_response propagates APIConnectionError."""
513- with pytest .raises (APIConnectionError ):
514- await retrieve_simple_response ("Test question" , constants .DEFAULT_SYSTEM_PROMPT )
515-
516-
517483# --- Test get_rh_identity_context ---
518484
519485
@@ -982,8 +948,8 @@ async def test_infer_extract_token_usage_on_failure_depends_on_verbose(
982948 )
983949 else :
984950 mocker .patch (
985- "app.endpoints.rlsapi_v1.retrieve_simple_response " ,
986- side_effect = RuntimeError ("retrieval failed" ),
951+ "app.endpoints.rlsapi_v1._call_llm " ,
952+ new = mocker . AsyncMock ( side_effect = RuntimeError ("retrieval failed" ) ),
987953 )
988954
989955 mock_extract = mocker .patch ("app.endpoints.rlsapi_v1.extract_token_usage" )
@@ -1384,8 +1350,8 @@ async def test_infer_shield_blocked_skips_llm_call(
13841350 "app.endpoints.rlsapi_v1.run_shield_moderation" ,
13851351 new = mocker .AsyncMock (return_value = blocked ),
13861352 )
1387- mock_retrieve = mocker .patch (
1388- "app.endpoints.rlsapi_v1.retrieve_simple_response " ,
1353+ mock_call_llm = mocker .patch (
1354+ "app.endpoints.rlsapi_v1._call_llm " ,
13891355 new = mocker .AsyncMock (),
13901356 )
13911357
@@ -1398,7 +1364,7 @@ async def test_infer_shield_blocked_skips_llm_call(
13981364 auth = MOCK_AUTH ,
13991365 )
14001366
1401- mock_retrieve .assert_not_called ()
1367+ mock_call_llm .assert_not_called ()
14021368
14031369
14041370@pytest .mark .asyncio
@@ -1568,40 +1534,36 @@ def _setup_responses_mock_with_capture(
15681534 return mock_create
15691535
15701536
1537+ @pytest .mark .parametrize (
1538+ "tools" ,
1539+ [
1540+ pytest .param (
1541+ [
1542+ {
1543+ "type" : "mcp" ,
1544+ "server_label" : "test-mcp" ,
1545+ "server_url" : "http://localhost:9000/sse" ,
1546+ "require_approval" : "never" ,
1547+ }
1548+ ],
1549+ id = "forwards_tools" ,
1550+ ),
1551+ pytest .param (None , id = "defaults_to_empty" ),
1552+ ],
1553+ )
15711554@pytest .mark .asyncio
1572- async def test_retrieve_simple_response_passes_tools (
1573- mocker : MockerFixture , mock_configuration : AppConfig
1574- ) -> None :
1575- """Test that retrieve_simple_response forwards tools to responses.create()."""
1576- mock_create = _setup_responses_mock_with_capture (mocker )
1577- tools = [
1578- {
1579- "type" : "mcp" ,
1580- "server_label" : "test-mcp" ,
1581- "server_url" : "http://localhost:9000/sse" ,
1582- "require_approval" : "never" ,
1583- }
1584- ]
1585-
1586- await retrieve_simple_response ("Test question" , "Instructions" , tools = tools )
1587-
1588- mock_create .assert_called_once ()
1589- call_kwargs = mock_create .call_args .kwargs
1590- assert call_kwargs ["tools" ] == tools
1591-
1592-
1593- @pytest .mark .asyncio
1594- async def test_retrieve_simple_response_defaults_to_empty_tools (
1595- mocker : MockerFixture , mock_configuration : AppConfig
1555+ async def test_call_llm_forwards_tools (
1556+ mocker : MockerFixture ,
1557+ mock_configuration : AppConfig ,
1558+ tools : Optional [list [dict [str , Any ]]],
15961559) -> None :
1597- """Test that retrieve_simple_response passes empty list when tools is None ."""
1560+ """Test that _call_llm forwards tools to responses.create(), defaulting to [] ."""
15981561 mock_create = _setup_responses_mock_with_capture (mocker )
15991562
1600- await retrieve_simple_response ("Test question" , "Instructions" )
1563+ await _call_llm ("Test question" , "Instructions" , tools = tools )
16011564
16021565 mock_create .assert_called_once ()
1603- call_kwargs = mock_create .call_args .kwargs
1604- assert call_kwargs ["tools" ] == []
1566+ assert mock_create .call_args .kwargs ["tools" ] == (tools or [])
16051567
16061568
16071569@pytest .mark .asyncio
0 commit comments