Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from contextlib import contextmanager, redirect_stdout
from dataclasses import dataclass
import os
from typing import Any, ContextManager, Generator
import io
from typing import TextIO
import os
import uuid
import pytest
from contextlib import contextmanager, redirect_stdout
from dataclasses import dataclass
from typing import Any, ContextManager, Generator, TextIO

import dotenv
import pytest
from humanloop.client import Humanloop
from humanloop.requests.prompt_kernel_request import PromptKernelRequestParams


@dataclass
Expand Down Expand Up @@ -55,7 +56,7 @@ def sdk_test_dir(humanloop_test_client: Humanloop) -> Generator[str, None, None]


@pytest.fixture(scope="function")
def test_prompt_config() -> dict[str, Any]:
def test_prompt_config() -> PromptKernelRequestParams:
return {
"provider": "openai",
"model": "gpt-4o-mini",
Expand Down Expand Up @@ -119,6 +120,22 @@ def eval_prompt(
pytest.fail(f"Failed to create prompt {prompt_path}: {e}")


@pytest.fixture(scope="function")
def prompt(
humanloop_test_client: Humanloop, sdk_test_dir: str, openai_key: str, test_prompt_config: dict[str, Any]
) -> Generator[TestIdentifiers, None, None]:
prompt_path = f"{sdk_test_dir}/prompt"
try:
response = humanloop_test_client.prompts.upsert(
path=prompt_path,
**test_prompt_config,
)
yield TestIdentifiers(file_id=response.id, file_path=response.path)
humanloop_test_client.prompts.delete(id=response.id)
except Exception as e:
pytest.fail(f"Failed to create prompt {prompt_path}: {e}")


@pytest.fixture(scope="function")
def output_not_null_evaluator(
humanloop_test_client: Humanloop, sdk_test_dir: str
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/test_prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from humanloop.client import Humanloop

from tests.integration.conftest import TestIdentifiers


def test_prompts_call(
humanloop_test_client: Humanloop,
prompt: TestIdentifiers,
test_prompt_config: TestIdentifiers,
) -> None:
response = humanloop_test_client.prompts.call( # type: ignore [attr-defined]
path=prompt.file_path,
prompt={**test_prompt_config}, # type: ignore [misc, arg-type, typeddict-item, dict-item, list-item]
inputs={"question": "What is the capital of the France?"},
)
assert response is not None
assert response.log_id is not None
assert response.logs is not None
for log in response.logs:
assert log is not None
assert log.output is not None
assert "Paris" in log.output
assert response.prompt.path == prompt.file_path


def test_prompts_call_stream(
humanloop_test_client: Humanloop,
prompt: TestIdentifiers,
test_prompt_config: TestIdentifiers,
) -> None:
response = humanloop_test_client.prompts.call_stream( # type: ignore [attr-defined]
path=prompt.file_path,
prompt={**test_prompt_config}, # type: ignore [misc, arg-type, typeddict-item, dict-item, list-item]
inputs={"question": "What is the capital of the France?"},
)

output = ""
for chunk in response:
assert chunk is not None
assert chunk.output is not None
assert chunk.id is not None
assert chunk.prompt_id is not None
assert chunk.version_id is not None
output += chunk.output

assert "Paris" in output