Skip to content

Commit 12c7048

Browse files
author
Andrei Bratu
committed
bug + test for prompt decorator
1 parent 1b117cf commit 12c7048

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/humanloop/otel/exporter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
7474

7575
for span in spans:
7676
# only process spans that are relevant to Humanloop
77-
if not is_humanloop_span(span) or not is_llm_provider_call(span):
77+
if not is_humanloop_span(span) and not is_llm_provider_call(span):
7878
continue
7979

8080
file_type = span.attributes.get(HUMANLOOP_FILE_TYPE_KEY) # type: ignore [union-attr]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import time
2+
from typing import Any
3+
4+
from openai import OpenAI
5+
from humanloop.client import Humanloop
6+
7+
8+
def test_prompt_decorator(
9+
humanloop_test_client: Humanloop,
10+
sdk_test_dir: str,
11+
test_prompt_config: dict[str, Any],
12+
openai_key: str,
13+
):
14+
try:
15+
prompt_path = f"{sdk_test_dir}/test_prompt"
16+
prompt_response = humanloop_test_client.prompts.upsert(
17+
path=prompt_path,
18+
**test_prompt_config,
19+
)
20+
21+
prompt_versions_response = humanloop_test_client.prompts.list_versions(id=prompt_response.id)
22+
assert len(prompt_versions_response.records) == 1
23+
24+
@humanloop_test_client.prompt(path=prompt_path)
25+
def my_prompt(question: str) -> str:
26+
openai_client = OpenAI(api_key=openai_key)
27+
28+
response = openai_client.chat.completions.create(
29+
model="gpt-4o-mini",
30+
messages=[{"role": "user", "content": question}],
31+
)
32+
33+
return response.choices[0].message.content
34+
35+
assert "paris" in my_prompt("What is the capital of the France?").lower()
36+
37+
time.sleep(5)
38+
prompt_versions_response = humanloop_test_client.prompts.list_versions(id=prompt_response.id)
39+
assert len(prompt_versions_response.records) == 2
40+
41+
logs = humanloop_test_client.logs.list(file_id=prompt_response.id, page=1, size=50)
42+
assert len(logs.items) == 1
43+
finally:
44+
humanloop_test_client.prompts.delete(id=prompt_response.id)

0 commit comments

Comments
 (0)