@@ -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+
130131def _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+
139141def 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