Skip to content

Commit 2229c71

Browse files
authored
Merge pull request #148 from tisnik/lcore-232-llm-query-response
LCORE-232: LLM query response end to end tests implementation
2 parents df000fc + c89eec9 commit 2229c71

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Implementation of end to end tests steps."""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""LLM query and response steps."""
2+
3+
import requests
4+
from behave import then, when
5+
from behave.runner import Context
6+
7+
DEFAULT_LLM_TIMEOUT = 60
8+
9+
10+
@when('I ask question "{question}"')
11+
def ask_question(context: Context, question: str) -> None:
12+
"""Call the service REST API endpoint with question."""
13+
base = f"http://{context.hostname}:{context.port}"
14+
path = f"{context.api_prefix}/query".replace("//", "/")
15+
url = base + path
16+
data = {"query": question}
17+
context.response = requests.post(url, json=data, timeout=DEFAULT_LLM_TIMEOUT)
18+
19+
20+
@then("The response should have proper LLM response format")
21+
def check_llm_response_format(context: Context) -> None:
22+
"""Check the format of response from the service with LLM-generated answer."""
23+
assert context.response is not None
24+
response_json = context.response.json()
25+
assert "conversation_id" in response_json
26+
assert "response" in response_json
27+
28+
29+
@then("The response should not be truncated")
30+
def check_llm_response_not_truncated(context: Context) -> None:
31+
"""Check that the response from LLM is not truncated."""
32+
assert context.response is not None
33+
response_json = context.response.json()
34+
assert response_json["truncated"] is False
35+
36+
37+
@then("The response should contain following fragments")
38+
def check_fragments_in_response(context: Context) -> None:
39+
"""Check if the LLM response contain list of fragments."""
40+
assert context.response is not None
41+
response_json = context.response.json()
42+
response = response_json["response"]
43+
44+
for fragment in context.table:
45+
expected = fragment["Fragments in LLM response"]
46+
assert (
47+
expected in response
48+
), f"Fragment '{expected}' not found in LLM response: '{response}'"

tests/e2e/test_list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
features/smoketests.feature
2+
features/rest_api.feature
3+
features/llm_interface.feature

0 commit comments

Comments
 (0)