Ilia Tambovtsev commited on
Commit
4c785d2
·
1 Parent(s): 49f9629

feat: handle Path input to FindPdfChain

Browse files
Files changed (1) hide show
  1. src/chains/chains.py +12 -7
src/chains/chains.py CHANGED
@@ -1,5 +1,5 @@
1
  from operator import itemgetter
2
- from typing import List, Dict, Any, Sequence, Optional
3
  from pathlib import Path
4
  import logging
5
  import base64
@@ -31,7 +31,7 @@ class FindPdfChain(Chain):
31
  @property
32
  def input_keys(self) -> List[str]:
33
  """Required input keys"""
34
- return ["title"]
35
 
36
  @property
37
  def output_keys(self) -> List[str]:
@@ -47,7 +47,7 @@ class FindPdfChain(Chain):
47
 
48
  Args:
49
  inputs: Dictionary containing:
50
- - title: Substring to search in PDF filenames
51
  run_manager: Callback manager
52
 
53
  Returns:
@@ -56,8 +56,15 @@ class FindPdfChain(Chain):
56
  Raises:
57
  ValueError: If multiple PDFs match the substring
58
  """
59
- title: str = inputs["title"]
60
- pdf_path = self.navigator.find_file_by_substr(title)
 
 
 
 
 
 
 
61
  return dict(pdf_path=pdf_path)
62
 
63
 
@@ -433,5 +440,3 @@ class ImageLoaderChain(Chain):
433
  image_path = inputs["image_path"]
434
  image_base64 = self._encode_image(image_path)
435
  return {"image": image_base64}
436
-
437
-
 
1
  from operator import itemgetter
2
+ from typing import List, Dict, Any, Sequence, Optional, Union
3
  from pathlib import Path
4
  import logging
5
  import base64
 
31
  @property
32
  def input_keys(self) -> List[str]:
33
  """Required input keys"""
34
+ return ["pdf_path"]
35
 
36
  @property
37
  def output_keys(self) -> List[str]:
 
47
 
48
  Args:
49
  inputs: Dictionary containing:
50
+ - pdf_path: Substring to search in PDF filenames or actual path
51
  run_manager: Callback manager
52
 
53
  Returns:
 
56
  Raises:
57
  ValueError: If multiple PDFs match the substring
58
  """
59
+ fpath_or_name: Union[Path, str] = inputs["pdf_path"]
60
+
61
+ if isinstance(fpath_or_name, str):
62
+ pdf_path = self.navigator.find_file_by_substr(fpath_or_name)
63
+ if pdf_path is None:
64
+ raise ValueError(f"No PDF found matching '{path}'")
65
+ else:
66
+ pdf_path = Path(fpath_or_name)
67
+
68
  return dict(pdf_path=pdf_path)
69
 
70
 
 
440
  image_path = inputs["image_path"]
441
  image_base64 = self._encode_image(image_path)
442
  return {"image": image_base64}