Prefect client prep for langchain
This commit is contained in:
@@ -123,9 +123,9 @@ class _AdaptiveFile(ABC):
|
||||
|
||||
# This method allows to work with file locally, and lambda should be provided for this.
|
||||
# Why separate method? For possible cleanup after work is done. And to download file, if needed
|
||||
# Lambda: first argument is a local path
|
||||
# Lambda: first argument is an original path, second: local path. In case of just local files, these will be the same
|
||||
@abstractmethod
|
||||
def work_with_file_locally(self, func: Callable[[str], None]):
|
||||
def work_with_file_locally(self, func: Callable[[str, str], None]):
|
||||
"""Run callback with a local path to the file."""
|
||||
|
||||
|
||||
@@ -143,8 +143,8 @@ class LocalFilesystemAdaptiveFile(_AdaptiveFile):
|
||||
super().__init__(filename, extension)
|
||||
self.local_path = local_path
|
||||
|
||||
def work_with_file_locally(self, func: Callable[[str], None]):
|
||||
func(self.local_path)
|
||||
def work_with_file_locally(self, func: Callable[[str, str], None]):
|
||||
func(self.local_path, self.local_path)
|
||||
|
||||
|
||||
class LocalFilesystemAdaptiveCollection(_AdaptiveCollection):
|
||||
@@ -196,10 +196,10 @@ class YandexDiskAdaptiveFile(_AdaptiveFile):
|
||||
temp_file.write(file_response.content)
|
||||
return temp_file.name
|
||||
|
||||
def work_with_file_locally(self, func: Callable[[str], None]):
|
||||
def work_with_file_locally(self, func: Callable[[str, str], None]):
|
||||
temp_path = self._download_to_temp_file()
|
||||
try:
|
||||
func(temp_path)
|
||||
func(self.remote_path, temp_path)
|
||||
finally:
|
||||
if os.path.exists(temp_path):
|
||||
os.unlink(temp_path)
|
||||
|
||||
Reference in New Issue
Block a user