Skip to content

Commit d837947

Browse files
committed
fix: address review suggestions
1 parent 379353d commit d837947

File tree

5 files changed

+95
-263
lines changed

5 files changed

+95
-263
lines changed

tests/llama_stack/conftest.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import portforward
77
import pytest
8+
import requests
89
from _pytest.fixtures import FixtureRequest
910
from kubernetes.dynamic import DynamicClient
1011
from llama_stack_client import LlamaStackClient
@@ -96,12 +97,6 @@ def llama_stack_server_config(
9697
storage_size = params.get("llama_stack_storage_size")
9798
server_config["storage"] = {"size": storage_size}
9899

99-
if params.get("llama_stack_user_config_enabled"):
100-
# Create configmap trigering the llama_stack_user_config_configmap fixture
101-
request.getfixturevalue(argname="llama_stack_user_config_configmap")
102-
server_config["userConfig"] = {"configMapName": "llama-stack-user-config"}
103-
server_config["containerSpec"]["command"] = ["/bin/sh", "-c", "llama stack run /etc/llama-stack/run.yaml"]
104-
105100
return server_config
106101

107102

@@ -269,7 +264,11 @@ def vector_store(
269264
LOGGER.warning(f"Failed to delete vector store {vector_store.id}: {e}")
270265

271266

272-
@retry(wait_timeout=Timeout.TIMEOUT_1MIN, sleep=5)
267+
@retry(
268+
wait_timeout=Timeout.TIMEOUT_1MIN,
269+
sleep=5,
270+
exceptions_dict={requests.exceptions.RequestException: [], Exception: []},
271+
)
273272
def _download_and_upload_file(url: str, llama_stack_client: LlamaStackClient, vector_store: Any) -> bool:
274273
"""
275274
Downloads a file from URL and uploads it to the vector store.
@@ -282,8 +281,6 @@ def _download_and_upload_file(url: str, llama_stack_client: LlamaStackClient, ve
282281
Returns:
283282
bool: True if successful, raises exception if failed
284283
"""
285-
import requests
286-
287284
try:
288285
response = requests.get(url, timeout=30)
289286
response.raise_for_status()

tests/llama_stack/rag/manifests/llama-stack-user-config-configmap.yaml

Lines changed: 0 additions & 147 deletions
This file was deleted.

tests/llama_stack/rag/test_rag.py

Lines changed: 22 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import uuid
2-
from typing import List
32

43
import pytest
54
from llama_stack_client import Agent, LlamaStackClient, RAGDocument
65
from llama_stack_client.types import EmbeddingsResponse, QueryChunksResponse
76
from llama_stack_client.types.vector_io_insert_params import Chunk
87
from llama_stack_client.types.vector_store import VectorStore
98
from simple_logger.logger import get_logger
10-
from utilities.rag_utils import TurnExpectation, validate_rag_agent_responses, validate_api_responses, ModelInfo
11-
from ocp_resources.config_map import ConfigMap
9+
from utilities.rag_utils import validate_rag_agent_responses, validate_api_responses, ModelInfo
1210

13-
from tests.llama_stack.constants import TORCHTUNE_TEST_EXPECTATIONS
11+
from tests.llama_stack.utils import get_torchtune_test_expectations, create_response_function
1412

1513
LOGGER = get_logger(name=__name__)
1614

1715

1816
@pytest.mark.parametrize(
19-
"model_namespace, llama_stack_user_config_configmap, llama_stack_server_config",
17+
"model_namespace, llama_stack_server_config",
2018
[
2119
pytest.param(
2220
{"name": "test-llamastack-rag"},
23-
{"llama_stack_user_config_configmap_path": "rag/manifests/llama-stack-user-config-configmap.yaml"},
24-
{"llama_stack_storage_size": "", "llama_stack_user_config_enabled": "true"},
21+
{"llama_stack_storage_size": ""},
2522
),
2623
],
2724
indirect=True,
@@ -34,57 +31,10 @@ class TestLlamaStackRag:
3431
vector databases, and document retrieval with the Red Hat LlamaStack Distribution.
3532
"""
3633

37-
def _get_torchtune_test_expectations(self) -> List[TurnExpectation]:
38-
"""
39-
Helper method to get the test expectations for TorchTune documentation questions.
40-
41-
Returns:
42-
List of TurnExpectation objects for testing RAG responses
43-
"""
44-
return [
45-
{
46-
"question": expectation.question,
47-
"expected_keywords": expectation.expected_keywords,
48-
"description": expectation.description,
49-
}
50-
for expectation in TORCHTUNE_TEST_EXPECTATIONS
51-
]
52-
53-
def _create_response_function(
54-
self, llama_stack_client: LlamaStackClient, llama_stack_models: ModelInfo, vector_store: VectorStore
55-
) -> callable:
56-
"""
57-
Helper method to create a response function for testing with vector store integration.
58-
59-
Args:
60-
llama_stack_client: The LlamaStack client instance
61-
llama_stack_models: The model configuration
62-
vector_store: The vector store instance
63-
64-
Returns:
65-
A callable function that takes a question and returns a response
66-
"""
67-
68-
def _response_fn(*, question: str) -> str:
69-
response = llama_stack_client.responses.create(
70-
input=question,
71-
model=llama_stack_models.model_id,
72-
tools=[
73-
{
74-
"type": "file_search",
75-
"vector_store_ids": [vector_store.id],
76-
}
77-
],
78-
)
79-
return response.output_text
80-
81-
return _response_fn
82-
8334
@pytest.mark.smoke
8435
def test_rag_inference_embeddings(
8536
self,
8637
llama_stack_client: LlamaStackClient,
87-
llama_stack_user_config_configmap: ConfigMap,
8838
llama_stack_models: ModelInfo,
8939
) -> None:
9040
"""
@@ -107,7 +57,6 @@ def test_rag_inference_embeddings(
10757
def test_rag_vector_io_ingestion_retrieval(
10858
self,
10959
llama_stack_client: LlamaStackClient,
110-
llama_stack_user_config_configmap: ConfigMap,
11160
llama_stack_models: ModelInfo,
11261
) -> None:
11362
"""
@@ -167,7 +116,6 @@ def test_rag_vector_io_ingestion_retrieval(
167116
def test_rag_simple_agent(
168117
self,
169118
llama_stack_client: LlamaStackClient,
170-
llama_stack_user_config_configmap: ConfigMap,
171119
llama_stack_models: ModelInfo,
172120
) -> None:
173121
"""
@@ -208,7 +156,6 @@ def test_rag_simple_agent(
208156
def test_rag_build_rag_agent(
209157
self,
210158
llama_stack_client: LlamaStackClient,
211-
llama_stack_user_config_configmap: ConfigMap,
212159
llama_stack_models: ModelInfo,
213160
) -> None:
214161
"""
@@ -270,7 +217,7 @@ def test_rag_build_rag_agent(
270217
chunk_size_in_tokens=512,
271218
)
272219

273-
turns_with_expectations = self._get_torchtune_test_expectations()
220+
turns_with_expectations = get_torchtune_test_expectations()
274221

275222
# Ask the agent about the inserted documents and validate responses
276223
validation_result = validate_rag_agent_responses(
@@ -305,7 +252,6 @@ def test_rag_build_rag_agent(
305252
def test_rag_simple_responses(
306253
self,
307254
llama_stack_client: LlamaStackClient,
308-
llama_stack_user_config_configmap: ConfigMap,
309255
llama_stack_models: ModelInfo,
310256
) -> None:
311257
"""
@@ -315,36 +261,28 @@ def test_rag_simple_responses(
315261
Tests identity and capability questions to ensure the LLM can provide
316262
appropriate responses about itself and its functionality.
317263
"""
264+
test_cases = [
265+
("Who are you?", ["model", "assistant", "ai", "artificial", "language model"]),
266+
("What can you do?", ["answer"]),
267+
]
318268

319-
response = llama_stack_client.responses.create(
320-
model=llama_stack_models.model_id,
321-
input="Who are you?",
322-
instructions="You are a helpful assistant.",
323-
)
324-
325-
content = response.output_text
326-
assert content is not None, "LLM response content is None"
327-
assert any(
328-
answer in content.lower() for answer in ["model", "assistant", "ai", "artificial", "language model"]
329-
), (
330-
f"The LLM didn't provide any of the expected answers "
331-
f"['model', 'assistant', 'ai', 'llm', 'language model']. Got: {content}"
332-
)
269+
for question, expected_keywords in test_cases:
270+
response = llama_stack_client.responses.create(
271+
model=llama_stack_models.model_id,
272+
input=question,
273+
instructions="You are a helpful assistant.",
274+
)
333275

334-
response = llama_stack_client.responses.create(
335-
model=llama_stack_models.model_id,
336-
input="What can you do?",
337-
instructions="You are a helpful assistant.",
338-
)
339-
content = response.output_text
340-
assert content is not None, "LLM response content is None"
341-
assert "answer" in content, "The LLM didn't provide the expected answer to the prompt"
276+
content = response.output_text
277+
assert content is not None, "LLM response content is None"
278+
assert any(keyword in content.lower() for keyword in expected_keywords), (
279+
f"The LLM didn't provide any of the expected keywords {expected_keywords}. Got: {content}"
280+
)
342281

343282
@pytest.mark.smoke
344283
def test_rag_full_responses(
345284
self,
346285
llama_stack_client: LlamaStackClient,
347-
llama_stack_user_config_configmap: ConfigMap,
348286
llama_stack_models: ModelInfo,
349287
vector_store_with_docs: VectorStore,
350288
) -> None:
@@ -356,13 +294,13 @@ def test_rag_full_responses(
356294
knowledge from uploaded documents to answer questions.
357295
"""
358296

359-
_response_fn = self._create_response_function(
297+
_response_fn = create_response_function(
360298
llama_stack_client=llama_stack_client,
361299
llama_stack_models=llama_stack_models,
362300
vector_store=vector_store_with_docs,
363301
)
364302

365-
turns_with_expectations = self._get_torchtune_test_expectations()
303+
turns_with_expectations = get_torchtune_test_expectations()
366304

367305
validation_result = validate_api_responses(response_fn=_response_fn, test_cases=turns_with_expectations)
368306

@@ -372,7 +310,6 @@ def test_rag_full_responses(
372310
def test_rag_vector_store_search(
373311
self,
374312
llama_stack_client: LlamaStackClient,
375-
llama_stack_user_config_configmap: ConfigMap,
376313
vector_store_with_docs: VectorStore,
377314
) -> None:
378315
"""

0 commit comments

Comments
 (0)