Skip to content

Commit 49b1078

Browse files
author
Andrei Bratu
committed
fixed fixtures, some tests, linting
1 parent f9e2744 commit 49b1078

File tree

10 files changed

+274
-331
lines changed

10 files changed

+274
-331
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ poetry.toml
88
.env.test
99
tests/assets/*.jsonl
1010
tests/assets/*.parquet
11+
humanloop

src/humanloop/client.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ def __init__(
142142
)
143143

144144
self.use_local_files = use_local_files
145-
self._sync_client = SyncClient(
146-
client=self,
147-
base_dir=files_directory,
148-
cache_size=cache_size
149-
)
145+
self._sync_client = SyncClient(client=self, base_dir=files_directory, cache_size=cache_size)
150146
eval_client = ExtendedEvalsClient(client_wrapper=self._client_wrapper)
151147
eval_client.client = self
152148
self.evaluations = eval_client
@@ -156,15 +152,15 @@ def __init__(
156152
# and the @flow decorator providing the trace_id
157153
self.prompts = overload_log(client=self.prompts)
158154
self.prompts = overload_call(client=self.prompts)
159-
self.prompts = overload_with_local_files(
160-
client=self.prompts,
155+
self.prompts = overload_with_local_files( # type: ignore [assignment]
156+
client=self.prompts,
161157
sync_client=self._sync_client,
162-
use_local_files=self.use_local_files
158+
use_local_files=self.use_local_files,
163159
)
164-
self.agents = overload_with_local_files(
165-
client=self.agents,
160+
self.agents = overload_with_local_files( # type: ignore [assignment]
161+
client=self.agents,
166162
sync_client=self._sync_client,
167-
use_local_files=self.use_local_files
163+
use_local_files=self.use_local_files,
168164
)
169165
self.flows = overload_log(client=self.flows)
170166
self.tools = overload_log(client=self.tools)
@@ -387,10 +383,7 @@ def agent():
387383
attributes=attributes,
388384
)
389385

390-
def pull(self,
391-
environment: str | None = None,
392-
path: str | None = None
393-
) -> Tuple[List[str], List[str]]:
386+
def pull(self, environment: str | None = None, path: str | None = None) -> Tuple[List[str], List[str]]:
394387
"""Pull Prompt and Agent files from Humanloop to local filesystem.
395388
396389
This method will:
@@ -425,17 +418,14 @@ def pull(self,
425418
If not provided, all Prompt and Agent files will be pulled.
426419
:return: List of successfully processed file paths.
427420
"""
428-
return self._sync_client.pull(
429-
environment=environment,
430-
path=path
431-
)
421+
return self._sync_client.pull(environment=environment, path=path)
422+
432423

433-
434424
class AsyncHumanloop(AsyncBaseHumanloop):
435425
"""
436426
See docstring of AsyncBaseHumanloop.
437427
438428
TODO: Add custom evaluation utilities for async case.
439429
"""
440430

441-
pass
431+
pass

src/humanloop/files/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def list_files(
118118
def retrieve_by_path(
119119
self,
120120
*,
121-
path: str,
121+
# @TODO: @ale, can this be None?
122+
path: str | None = None,
122123
environment: typing.Optional[str] = None,
123124
include_raw_file_content: typing.Optional[bool] = None,
124125
request_options: typing.Optional[RequestOptions] = None,

src/humanloop/files/raw_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def list_files(
132132
def retrieve_by_path(
133133
self,
134134
*,
135-
path: str,
135+
path: str | None = None,
136136
environment: typing.Optional[str] = None,
137137
include_raw_file_content: typing.Optional[bool] = None,
138138
request_options: typing.Optional[RequestOptions] = None,

src/humanloop/overload.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,58 +127,60 @@ def _overload_call(self, **kwargs) -> PromptCallResponse:
127127
client.call = types.MethodType(_overload_call, client) # type: ignore [assignment]
128128
return client
129129

130+
130131
def _get_file_type_from_client(client: Union[PromptsClient, AgentsClient]) -> FileType:
131132
"""Get the file type based on the client type."""
132-
if isinstance(client, PromptsClient):
133-
return "prompt"
133+
if isinstance(client, PromptsClient):
134+
return "prompt"
134135
elif isinstance(client, AgentsClient):
135136
return "agent"
136137
else:
137138
raise ValueError(f"Unsupported client type: {type(client)}")
138139

140+
139141
def overload_with_local_files(
140-
client: Union[PromptsClient, AgentsClient],
142+
client: Union[PromptsClient, AgentsClient],
141143
sync_client: SyncClient,
142144
use_local_files: bool,
143145
) -> Union[PromptsClient, AgentsClient]:
144146
"""Overload call and log methods to handle local files when use_local_files is True.
145-
147+
146148
When use_local_files is True, the following prioritization strategy is used:
147149
1. Direct Parameters: If {file_type} parameters are provided directly (as a PromptKernelRequestParams or AgentKernelRequestParams object),
148150
these take precedence and the local file is ignored.
149151
2. Version/Environment: If version_id or environment is specified, the remote version is used instead
150152
of the local file.
151153
3. Local File: If neither of the above are specified, attempts to use the local file at the given path.
152-
154+
153155
For example, with a prompt client:
154156
- If prompt={model: "gpt-4", ...} is provided, uses those parameters directly
155157
- If version_id="123" is provided, uses that remote version
156158
- Otherwise, tries to load from the local file at the given path
157-
159+
158160
Args:
159161
client: The client to overload (PromptsClient or AgentsClient)
160162
sync_client: The sync client used for file operations
161163
use_local_files: Whether to enable local file handling
162-
164+
163165
Returns:
164166
The client with overloaded methods
165-
167+
166168
Raises:
167169
HumanloopRuntimeError: If use_local_files is True and local file cannot be accessed
168170
"""
169-
original_call = client._call if hasattr(client, '_call') else client.call
170-
original_log = client._log if hasattr(client, '_log') else client.log
171+
original_call = client._call if hasattr(client, "_call") else client.call
172+
original_log = client._log if hasattr(client, "_log") else client.log
171173
file_type = _get_file_type_from_client(client)
172174

173175
def _overload(self, function_name: str, **kwargs) -> PromptCallResponse:
174-
if "id" in kwargs and "path" in kwargs:
176+
if "id" in kwargs and "path" in kwargs:
175177
raise HumanloopRuntimeError(f"Can only specify one of `id` or `path` when {function_name}ing a {file_type}")
176178
# Handle local files if enabled
177179
if use_local_files and "path" in kwargs:
178180
# Check if version_id or environment is specified
179181
use_remote = any(["version_id" in kwargs, "environment" in kwargs])
180182
normalized_path = sync_client._normalize_path(kwargs["path"])
181-
183+
182184
if use_remote:
183185
raise HumanloopRuntimeError(
184186
f"Cannot use local file for `{normalized_path}` as version_id or environment was specified. "
@@ -196,7 +198,7 @@ def _overload(self, function_name: str, **kwargs) -> PromptCallResponse:
196198
else:
197199
file_content = sync_client.get_file_content(normalized_path, file_type)
198200
kwargs[file_type] = file_content
199-
except (HumanloopRuntimeError) as e:
201+
except HumanloopRuntimeError as e:
200202
# Re-raise with more context
201203
raise HumanloopRuntimeError(f"Failed to use local file for `{normalized_path}`: {str(e)}")
202204

@@ -217,6 +219,6 @@ def _overload_call(self, **kwargs) -> PromptCallResponse:
217219
def _overload_log(self, **kwargs) -> PromptCallResponse:
218220
return _overload(self, "log", **kwargs)
219221

220-
client.call = types.MethodType(_overload_call, client)
221-
client.log = types.MethodType(_overload_log, client)
222-
return client
222+
client.call = types.MethodType(_overload_call, client) # type: ignore [assignment]
223+
client.log = types.MethodType(_overload_log, client) # type: ignore [assignment]
224+
return client

0 commit comments

Comments
 (0)