forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_completions.py
More file actions
66 lines (57 loc) · 2.64 KB
/
test_completions.py
File metadata and controls
66 lines (57 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pytest
from llama_stack_client import LlamaStackClient
from tests.llama_stack.constants import ModelInfo
from utilities.opendatahub_logger import get_logger
LOGGER = get_logger(name=__name__)
@pytest.mark.parametrize(
"unprivileged_model_namespace",
[
pytest.param(
{"name": "test-llamastack-infer-completions", "randomize_name": True},
),
],
indirect=True,
)
@pytest.mark.llama_stack
class TestLlamaStackInferenceCompletions:
"""Test class for LlamaStack Inference API for Chat Completions and Completions
For more information about this API, see:
- https://llamastack.github.io/docs/references/python_sdk_reference#inference
- https://github.com/openai/openai-python/blob/main/api.md#completions-1
"""
@pytest.mark.tier1
def test_inference_chat_completion(
self,
unprivileged_llama_stack_client: LlamaStackClient,
llama_stack_models: ModelInfo,
) -> None:
"""Test chat completion functionality with a simple ACK response."""
response = unprivileged_llama_stack_client.chat.completions.create(
model=llama_stack_models.model_id,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Just respond ACK."},
],
temperature=0,
)
assert len(response.choices) > 0, "No response after basic inference on llama-stack server"
# Check if response has the expected structure and content
content = response.choices[0].message.content
assert content is not None, "LLM response content is None"
assert "ACK" in content, "The LLM didn't provide the expected answer to the prompt"
@pytest.mark.tier1
def test_inference_completion(
self,
unprivileged_llama_stack_client: LlamaStackClient,
llama_stack_models: ModelInfo,
) -> None:
"""Test text completion functionality with a geography question."""
response = unprivileged_llama_stack_client.completions.create(
model=llama_stack_models.model_id, prompt="What is the capital of Catalonia?", max_tokens=20, temperature=0
)
assert len(response.choices) > 0, "No response after basic inference on llama-stack server"
# Check if response has the expected structure and content
content = response.choices[0].text.lower()
assert content is not None, "LLM response content is None"
LOGGER.info(f"LLM response content for test_inference_completion: {content}")
assert "barcelona" in content, "The LLM didn't provide the expected answer to the prompt"