Skip to content

Commit 4965c7b

Browse files
committed
test: fix type errors in local file operations test by using proper ChatMessageParams type
1 parent e5314f2 commit 4965c7b

File tree

4 files changed

+29
-39
lines changed

4 files changed

+29
-39
lines changed

src/humanloop/cli/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def get_client(
8181
"""
8282
if not api_key:
8383
api_key = load_api_key(env_file)
84-
print(api_key)
8584
return Humanloop(api_key=api_key, base_url=base_url)
8685

8786

src/humanloop/client.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1+
import logging
12
import os
23
import typing
34
from typing import Any, List, Optional, Sequence, Tuple
4-
import logging
55

66
import httpx
77
from opentelemetry.sdk.resources import Resource
88
from opentelemetry.sdk.trace import TracerProvider
99
from opentelemetry.trace import Tracer
1010

11+
from humanloop.base_client import AsyncBaseHumanloop, BaseHumanloop
1112
from humanloop.core.client_wrapper import SyncClientWrapper
12-
13+
from humanloop.decorators.flow import flow as flow_decorator_factory
14+
from humanloop.decorators.prompt import prompt_decorator_factory
15+
from humanloop.decorators.tool import tool_decorator_factory as tool_decorator_factory
16+
from humanloop.environment import HumanloopEnvironment
1317
from humanloop.evals import run_eval
1418
from humanloop.evals.types import (
1519
DatasetEvalConfig,
16-
EvaluatorEvalConfig,
1720
EvaluatorCheck,
21+
EvaluatorEvalConfig,
1822
FileEvalConfig,
1923
)
20-
21-
from humanloop.base_client import AsyncBaseHumanloop, BaseHumanloop
22-
from humanloop.overload import overload_client
23-
from humanloop.decorators.flow import flow as flow_decorator_factory
24-
from humanloop.decorators.prompt import prompt_decorator_factory
25-
from humanloop.decorators.tool import tool_decorator_factory as tool_decorator_factory
26-
from humanloop.environment import HumanloopEnvironment
2724
from humanloop.evaluations.client import EvaluationsClient
2825
from humanloop.otel import instrument_provider
2926
from humanloop.otel.exporter import HumanloopSpanExporter
3027
from humanloop.otel.processor import HumanloopSpanProcessor
28+
from humanloop.overload import overload_client
3129
from humanloop.prompt_utils import populate_template
3230
from humanloop.prompts.client import PromptsClient
33-
from humanloop.sync.sync_client import SyncClient, DEFAULT_CACHE_SIZE
31+
from humanloop.sync.sync_client import DEFAULT_CACHE_SIZE, SyncClient
3432

3533
logger = logging.getLogger("humanloop.sdk")
3634

@@ -431,11 +429,6 @@ def pull(self, path: Optional[str] = None, environment: Optional[str] = None) ->
431429
432430
If you specify `local_files_directory="data/humanloop"`, files will be saved in ./data/humanloop/ instead.
433431
434-
Important note about paths:
435-
- Paths should not contain leading or trailing slashes
436-
- When specifying a file path, include the file extension (`.prompt` or `.agent`)
437-
- When specifying a directory path, do not include a trailing slash
438-
439432
:param path: Optional path to either a specific file (e.g. "path/to/file.prompt") or a directory (e.g. "path/to/directory").
440433
If not provided, all Prompt and Agent files will be pulled.
441434
:param environment: The environment to pull the files from.

src/humanloop/path_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
from pathlib import Path
22

3-
from humanloop.error import HumanloopRuntimeError
4-
53

64
def normalize_path(path: str, strip_extension: bool = False) -> str:
75
"""Normalize a path to the standard API format: path/to/resource, where resource can be a file or a directory."""
86
# Remove leading/trailing slashes
97
path_obj = Path(path.strip("/"))
108

11-
# Check if path is absolute
12-
if path_obj.is_absolute():
13-
raise HumanloopRuntimeError("Absolute paths are not supported. Ensure the ")
14-
159
# Handle extension
1610
if strip_extension:
1711
normalized = str(path_obj.with_suffix(""))

tests/custom/integration/test_local_file_operations.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pytest
44

55
from humanloop.error import HumanloopRuntimeError
6+
from humanloop.requests.chat_message import ChatMessageParams
7+
from humanloop.types.chat_role import ChatRole
68
from tests.custom.types import GetHumanloopClientFn, SyncableFile
79

810

@@ -99,17 +101,16 @@ def test_local_file_call(
99101
client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path))
100102

101103
# WHEN calling the API with the local file path (without extension)
102-
response = client.prompts.call(
103-
path=test_path, messages=[{"role": "user", "content": "What is the capital of France?"}]
104-
)
104+
call_messages = [ChatMessageParams(role="user", content="What is the capital of France?")]
105+
response = client.prompts.call(path=test_path, messages=call_messages)
105106

106107
# THEN the response should be successful
107108
assert response is not None
108109
assert response.logs is not None
109110
assert len(response.logs) > 0
110111

111112
# AND the response should contain the expected output format (lowercase city name)
112-
assert "paris" in response.logs[0].output.lower()
113+
assert response.logs[0].output is not None and "paris" in response.logs[0].output.lower()
113114

114115
# AND the prompt used should match our expected path
115116
assert response.prompt is not None
@@ -150,11 +151,11 @@ def test_local_file_log(
150151
client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path))
151152

152153
# GIVEN message content to log
153-
test_messages = [{"role": "user", "content": "What is the capital of France?"}]
154154
test_output = "Paris is the capital of France."
155155

156156
# WHEN logging the data with the local file path
157-
response = client.prompts.log(path=test_path, messages=test_messages, output=test_output)
157+
messages = [ChatMessageParams(role="user", content="What is the capital of France?")]
158+
response = client.prompts.log(path=test_path, messages=messages, output=test_output)
158159

159160
# THEN the log should be successful
160161
assert response is not None
@@ -179,6 +180,8 @@ def test_overload_version_environment_handling(
179180
humanloop_client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path))
180181
humanloop_client.pull()
181182

183+
test_message = [ChatMessageParams(role="user", content="Testing")]
184+
182185
# GIVEN a test file that exists locally
183186
test_file = syncable_files_fixture[0]
184187
extension = f".{test_file.type}"
@@ -195,13 +198,13 @@ def test_overload_version_environment_handling(
195198
humanloop_client.prompts.call(
196199
path=test_file.path,
197200
version_id=test_file.version_id,
198-
messages=[{"role": "user", "content": "Testing"}],
201+
messages=test_message,
199202
)
200203
elif test_file.type == "agent":
201204
humanloop_client.agents.call(
202205
path=test_file.path,
203206
version_id=test_file.version_id,
204-
messages=[{"role": "user", "content": "Testing"}],
207+
messages=test_message,
205208
)
206209

207210
# WHEN calling with environment
@@ -211,13 +214,13 @@ def test_overload_version_environment_handling(
211214
humanloop_client.prompts.call(
212215
path=test_file.path,
213216
environment="production",
214-
messages=[{"role": "user", "content": "Testing"}],
217+
messages=test_message,
215218
)
216219
elif test_file.type == "agent":
217220
humanloop_client.agents.call(
218221
path=test_file.path,
219222
environment="production",
220-
messages=[{"role": "user", "content": "Testing"}],
223+
messages=test_message,
221224
)
222225

223226
# WHEN calling with both version_id and environment
@@ -228,14 +231,14 @@ def test_overload_version_environment_handling(
228231
path=test_file.path,
229232
version_id=test_file.version_id,
230233
environment="staging",
231-
messages=[{"role": "user", "content": "Testing"}],
234+
messages=test_message,
232235
)
233236
elif test_file.type == "agent":
234237
humanloop_client.agents.call(
235238
path=test_file.path,
236239
version_id=test_file.version_id,
237240
environment="staging",
238-
messages=[{"role": "user", "content": "Testing"}],
241+
messages=test_message,
239242
)
240243

241244

@@ -280,8 +283,9 @@ def test_overload_version_environment_handling(
280283
# client = get_humanloop_client(use_local_files=True, local_files_directory=str(tmp_path))
281284
#
282285
# # WHEN calling the API with the local file path (without extension)
286+
# agent_call_messages = [ChatMessageParams(role="user", content="What is the capital of France?")]
283287
# response = client.agents.call(
284-
# path=test_path, messages=[{"role": "user", "content": "What is the capital of France?"}]
288+
# path=test_path, messages=agent_call_messages
285289
# )
286290
#
287291
# # THEN the response should be successful
@@ -290,16 +294,16 @@ def test_overload_version_environment_handling(
290294
# assert len(response.logs) > 0
291295
#
292296
# # AND the response should contain the expected output format (lowercase city name)
293-
# assert "paris" in response.logs[0].output.lower()
297+
# assert response.logs[0].output is not None and "paris" in response.logs[0].output.lower()
294298
#
295299
# # AND the agent used should match our expected path
296300
# assert response.agent is not None
297301
# assert response.agent.path == test_path
298302
#
299303
# # WHEN logging with the local agent file
300-
# test_messages = [{"role": "user", "content": "What is the capital of Germany?"}]
301304
# test_output = "Berlin is the capital of Germany."
302-
# log_response = client.agents.log(path=test_path, messages=test_messages, output=test_output)
305+
# agent_messages = [ChatMessageParams(role="user", content="What is the capital of Germany?")]
306+
# log_response = client.agents.log(path=test_path, messages=agent_messages, output=test_output)
303307
#
304308
# # THEN the log should be successful
305309
# assert log_response is not None

0 commit comments

Comments
 (0)