11import inspect
22import logging
33import types
4- from typing import TypeVar , Union
5-
4+ from typing import TypeVar , Union , Literal
5+ from pathlib import Path
66from humanloop .context import (
77 get_decorator_context ,
88 get_evaluation_context ,
1313from humanloop .evaluators .client import EvaluatorsClient
1414from humanloop .flows .client import FlowsClient
1515from humanloop .prompts .client import PromptsClient
16+ from humanloop .agents .client import AgentsClient
1617from humanloop .tools .client import ToolsClient
1718from humanloop .types .create_evaluator_log_response import CreateEvaluatorLogResponse
1819from humanloop .types .create_flow_log_response import CreateFlowLogResponse
@@ -112,6 +113,7 @@ def _overload_call(self, **kwargs) -> PromptCallResponse:
112113 }
113114
114115 try :
116+ logger .info (f"Calling inner overload" )
115117 response = self ._call (** kwargs )
116118 except Exception as e :
117119 # Re-raising as HumanloopDecoratorError so the decorators don't catch it
@@ -122,3 +124,43 @@ def _overload_call(self, **kwargs) -> PromptCallResponse:
122124 # Replace the original log method with the overloaded one
123125 client .call = types .MethodType (_overload_call , client ) # type: ignore [assignment]
124126 return client
127+
128+ def overload_call_with_local_files (
129+ client : Union [PromptsClient , AgentsClient ],
130+ use_local_files : bool ,
131+ file_type : Literal ["prompt" , "agent" ]
132+ ) -> Union [PromptsClient , AgentsClient ]:
133+ """Overload call to handle local files when use_local_files is True.
134+
135+ Args:
136+ client: The client to overload (PromptsClient or AgentsClient)
137+ use_local_files: Whether to use local files
138+ file_type: Type of file ("prompt" or "agent")
139+ """
140+ original_call = client ._call if hasattr (client , '_call' ) else client .call
141+
142+ def _overload_call (self , ** kwargs ) -> PromptCallResponse :
143+ if use_local_files and "path" in kwargs :
144+ try :
145+ # Construct path to local file
146+ local_path = Path ("humanloop" ) / kwargs ["path" ]
147+ # Add appropriate extension
148+ local_path = local_path .parent / f"{ local_path .stem } .{ file_type } "
149+
150+ if local_path .exists ():
151+ # Read the file content
152+ with open (local_path ) as f :
153+ file_content = f .read ()
154+
155+ kwargs [file_type ] = file_content # "prompt" or "agent"
156+
157+ logger .debug (f"Using local file content from { local_path } " )
158+ else :
159+ logger .warning (f"Local file not found: { local_path } , falling back to API" )
160+ except Exception as e :
161+ logger .error (f"Error reading local file: { e } , falling back to API" )
162+
163+ return original_call (** kwargs )
164+
165+ client .call = types .MethodType (_overload_call , client )
166+ return client
0 commit comments