Skip to content

Commit 8595f7f

Browse files
Add tests for prompts call and call_stream
1 parent 9cdb276 commit 8595f7f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/integration/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ def eval_prompt(
119119
pytest.fail(f"Failed to create prompt {prompt_path}: {e}")
120120

121121

122+
@pytest.fixture(scope="function")
123+
def prompt(
124+
humanloop_test_client: Humanloop, sdk_test_dir: str, openai_key: str, test_prompt_config: dict[str, Any]
125+
) -> Generator[TestIdentifiers, None, None]:
126+
prompt_path = f"{sdk_test_dir}/prompt"
127+
try:
128+
response = humanloop_test_client.prompts.upsert(
129+
path=prompt_path,
130+
**test_prompt_config,
131+
)
132+
yield TestIdentifiers(file_id=response.id, file_path=response.path)
133+
humanloop_test_client.prompts.delete(id=response.id)
134+
except Exception as e:
135+
pytest.fail(f"Failed to create prompt {prompt_path}: {e}")
136+
137+
122138
@pytest.fixture(scope="function")
123139
def output_not_null_evaluator(
124140
humanloop_test_client: Humanloop, sdk_test_dir: str

tests/integration/test_prompts.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from humanloop.client import Humanloop
2+
from tests.integration.conftest import TestIdentifiers
3+
4+
5+
def test_prompts_call(
6+
humanloop_test_client: Humanloop,
7+
prompt: TestIdentifiers,
8+
test_prompt_config: TestIdentifiers,
9+
) -> None:
10+
response = humanloop_test_client.prompts.call(
11+
path=prompt.file_path,
12+
prompt={**test_prompt_config},
13+
inputs={"question": "What is the capital of the France?"},
14+
)
15+
assert response is not None
16+
assert response.log_id is not None
17+
assert response.logs is not None
18+
for log in response.logs:
19+
assert log is not None
20+
assert log.output or log.error or log.output_message is not None
21+
assert "Paris" in log.output
22+
assert response.prompt.path == prompt.file_path
23+
24+
25+
def test_prompts_call_stream(
26+
humanloop_test_client: Humanloop,
27+
prompt: TestIdentifiers,
28+
test_prompt_config: TestIdentifiers,
29+
) -> None:
30+
response = humanloop_test_client.prompts.call_stream(
31+
path=prompt.file_path,
32+
prompt={**test_prompt_config},
33+
inputs={"question": "What is the capital of the France?"},
34+
)
35+
36+
output = ""
37+
for chunk in response:
38+
assert chunk is not None
39+
assert chunk.output or chunk.error or chunk.output_message is not None
40+
assert chunk.id is not None
41+
assert chunk.prompt_id is not None
42+
assert chunk.version_id is not None
43+
output += chunk.output
44+
45+
assert "Paris" in output

0 commit comments

Comments
 (0)