langroid 0.1.35__py3-none-any.whl → 0.1.36__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
langroid/agent/base.py CHANGED
@@ -525,8 +525,8 @@ class Agent(ABC):
525
525
  try:
526
526
  result = handler_method(tool)
527
527
  except Exception as e:
528
- logger.warning(f"Error handling tool-message {tool_name}: {type(e)}: {e}")
529
- return None
528
+ # return the error message to the LLM so it can try to fix the error
529
+ result = f"Error in tool/function-call {tool_name} usage: {type(e)}: {e}"
530
530
  return result # type: ignore
531
531
 
532
532
  def num_tokens(self, prompt: str) -> int:
langroid/parsing/utils.py CHANGED
@@ -1,4 +1,6 @@
1
+ import difflib
1
2
  import random
3
+ from typing import List
2
4
 
3
5
  import nltk
4
6
  from faker import Faker
@@ -30,3 +32,34 @@ def generate_random_text(num_sentences: int) -> str:
30
32
  for _ in range(num_sentences):
31
33
  text += fake.sentence() + " "
32
34
  return text
35
+
36
+
37
+ def closest_string(query: str, string_list: List[str]) -> str:
38
+ """Find the closest match to the query in a list of strings.
39
+
40
+ This function is case-insensitive and ignores leading and trailing whitespace.
41
+ If no match is found, it returns 'No match found'.
42
+
43
+ Args:
44
+ query (str): The string to match.
45
+ string_list (List[str]): The list of strings to search.
46
+
47
+ Returns:
48
+ str: The closest match to the query from the list, or 'No match found'
49
+ if no match is found.
50
+ """
51
+ # Create a dictionary where the keys are the standardized strings and
52
+ # the values are the original strings.
53
+ str_dict = {s.lower().strip(): s for s in string_list}
54
+
55
+ # Standardize the query and find the closest match in the list of keys.
56
+ closest_match = difflib.get_close_matches(
57
+ query.lower().strip(), str_dict.keys(), n=1
58
+ )
59
+
60
+ # Retrieve the original string from the value in the dictionary.
61
+ original_closest_match = (
62
+ str_dict[closest_match[0]] if closest_match else "No match found"
63
+ )
64
+
65
+ return original_closest_match
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.35
3
+ Version: 0.1.36
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -1,6 +1,6 @@
1
1
  langroid/__init__.py,sha256=sEKJ_5WJBAMZApevfeE3gxLK-eotVzJMJlT83G0rAko,30
2
2
  langroid/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- langroid/agent/base.py,sha256=DBAra4SAwCCCUIaDGZd5OHc5VohIggs-lZLHQbDG7Qw,20968
3
+ langroid/agent/base.py,sha256=ud_HNDxmidHAg_JBsP8KZjMn5GHt2hL3c9QBsBOhQ7g,21024
4
4
  langroid/agent/chat_agent.py,sha256=mLCHlYxU1lB7PGOLjjkaEQUqMNKcq0-HOjlG4ZcDjQE,20522
5
5
  langroid/agent/chat_document.py,sha256=Rj7Hfp_FrNjuKsTMA3KyZhno5zKpmvnPPk7WgAuAF2Y,5745
6
6
  langroid/agent/helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -39,7 +39,7 @@ langroid/parsing/table_loader.py,sha256=xr0aeMWN-vT2Tx9HwUkuwLnG7wxA1qNfh1uC9uct
39
39
  langroid/parsing/url_loader.py,sha256=tdYPMC2V9zI_B207LFdU4aroZzJW4sY9y794XePFAVg,1824
40
40
  langroid/parsing/url_loader_cookies.py,sha256=Lg4sNpRz9MByWq2mde6T0hKv68VZSV3mtMjNEHuFeSU,2327
41
41
  langroid/parsing/urls.py,sha256=_Bcf1iRdT7cQrQ8hnbPX0Jtzxc0lVFaucTS5rJoKA14,3709
42
- langroid/parsing/utils.py,sha256=giJOG_idlSrJi3BJWpot3ggent2VYnrNQS5Dj2lGpPk,683
42
+ langroid/parsing/utils.py,sha256=__1Z6mFHk_TqHQY-9uU1aV_bIXeYw8H7NEXagUOEX0I,1818
43
43
  langroid/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
44
  langroid/prompts/dialog.py,sha256=SpfiSyofSgy2pwD1YboHR_yHO3LEEMbv6j2sm874jKo,331
45
45
  langroid/prompts/prompts_config.py,sha256=EMK1Fm7EmS8y3CV4AkrVgn5K4NipiM4m7J8819W1KeM,98
@@ -64,7 +64,7 @@ langroid/vector_store/base.py,sha256=QZx3NUNwf2I0r3A7iuoUHIRGbqt_pFGD0hq1R-Yg8iM
64
64
  langroid/vector_store/chromadb.py,sha256=s5pQkKjaMP-Tt5A8M10EInFzttaALPbJAq7q4gf0TKg,5235
65
65
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
66
66
  langroid/vector_store/qdrantdb.py,sha256=KRvIIj1IZG2zFqejofMnRs2hT86B-27LgBEnuczdqOU,9072
67
- langroid-0.1.35.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
68
- langroid-0.1.35.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
69
- langroid-0.1.35.dist-info/METADATA,sha256=1s4fm22g9WSkufaluJnStROB5Lk5NuIzTlgAOK6PKVM,25190
70
- langroid-0.1.35.dist-info/RECORD,,
67
+ langroid-0.1.36.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
68
+ langroid-0.1.36.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
69
+ langroid-0.1.36.dist-info/METADATA,sha256=H5cDPR68T2YFa2Bz_4UI-sv2xXmyDrjq0m_IxlLNxfg,25190
70
+ langroid-0.1.36.dist-info/RECORD,,