langroid 0.16.7__py3-none-any.whl → 0.17.1__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.
Files changed (91) hide show
  1. langroid/agent/base.py +45 -21
  2. langroid/agent/chat_agent.py +22 -14
  3. langroid/agent/chat_document.py +22 -13
  4. langroid/agent/tool_message.py +11 -11
  5. langroid/agent/tools/file_tools.py +234 -0
  6. langroid/agent/xml_tool_message.py +179 -45
  7. langroid/utils/constants.py +2 -0
  8. langroid/utils/git_utils.py +251 -0
  9. langroid/utils/system.py +78 -0
  10. {langroid-0.16.7.dist-info → langroid-0.17.1.dist-info}/METADATA +6 -3
  11. {langroid-0.16.7.dist-info → langroid-0.17.1.dist-info}/RECORD +14 -89
  12. pyproject.toml +3 -2
  13. langroid/agent/md_tool_message_grammar.py +0 -455
  14. langroid/agent/tools/code_file_tool_parse.py +0 -150
  15. langroid/agent/tools/code_file_tool_pyparsing.py +0 -194
  16. langroid/agent/tools/code_file_tool_pyparsing2.py +0 -199
  17. langroid/agent/tools/extract_tool.py +0 -96
  18. langroid/agent/tools/formatted_model_custom.py +0 -150
  19. langroid/agent/tools/formatted_model_custom2.py +0 -168
  20. langroid/agent/tools/formatted_model_custom3.py +0 -279
  21. langroid/agent/tools/formatted_model_custom4.py +0 -395
  22. langroid/agent/tools/formatted_model_jinja.py +0 -133
  23. langroid/agent/tools/formatted_model_jinja.py-e +0 -122
  24. langroid/agent/tools/formatted_model_jinja2.py +0 -145
  25. langroid/agent/tools/formatted_model_jinja2.py-e +0 -135
  26. langroid/agent/tools/formatted_model_lark.py +0 -0
  27. langroid/agent/tools/formatted_model_lark2.py +0 -168
  28. langroid/agent/tools/formatted_model_parse.py +0 -105
  29. langroid/agent/tools/formatted_model_parse.py-e +0 -98
  30. langroid/agent/tools/formatted_model_parse2.py +0 -113
  31. langroid/agent/tools/formatted_model_parse2.py-e +0 -109
  32. langroid/agent/tools/formatted_model_parse3.py +0 -114
  33. langroid/agent/tools/formatted_model_parse3.py-e +0 -110
  34. langroid/agent/tools/formatted_model_parsimon.py +0 -194
  35. langroid/agent/tools/formatted_model_parsimon.py-e +0 -186
  36. langroid/agent/tools/formatted_model_pyparsing.py +0 -169
  37. langroid/agent/tools/formatted_model_pyparsing.py-e +0 -149
  38. langroid/agent/tools/formatted_model_pyparsing2.py +0 -159
  39. langroid/agent/tools/formatted_model_pyparsing2.py-e +0 -143
  40. langroid/agent/tools/formatted_model_pyparsing3.py +0 -133
  41. langroid/agent/tools/formatted_model_pyparsing3.py-e +0 -121
  42. langroid/agent/tools/formatted_model_pyparsing4.py +0 -213
  43. langroid/agent/tools/formatted_model_pyparsing4.py-e +0 -176
  44. langroid/agent/tools/formatted_model_pyparsing5.py +0 -173
  45. langroid/agent/tools/formatted_model_pyparsing5.py-e +0 -142
  46. langroid/agent/tools/formatted_model_regex.py +0 -246
  47. langroid/agent/tools/formatted_model_regex.py-e +0 -248
  48. langroid/agent/tools/formatted_model_regex2.py +0 -250
  49. langroid/agent/tools/formatted_model_regex2.py-e +0 -253
  50. langroid/agent/tools/formatted_model_tatsu.py +0 -172
  51. langroid/agent/tools/formatted_model_tatsu.py-e +0 -160
  52. langroid/agent/tools/formatted_model_template.py +0 -217
  53. langroid/agent/tools/formatted_model_template.py-e +0 -200
  54. langroid/agent/tools/formatted_model_xml.py +0 -178
  55. langroid/agent/tools/formatted_model_xml2.py +0 -178
  56. langroid/agent/tools/formatted_model_xml3.py +0 -132
  57. langroid/agent/tools/formatted_model_xml4.py +0 -130
  58. langroid/agent/tools/formatted_model_xml5.py +0 -130
  59. langroid/agent/tools/formatted_model_xml6.py +0 -113
  60. langroid/agent/tools/formatted_model_xml7.py +0 -117
  61. langroid/agent/tools/formatted_model_xml8.py +0 -164
  62. langroid/agent/tools/generator_tool.py +0 -20
  63. langroid/agent/tools/generic_tool.py +0 -165
  64. langroid/agent/tools/generic_tool_tatsu.py +0 -275
  65. langroid/agent/tools/grammar_based_model.py +0 -132
  66. langroid/agent/tools/grammar_based_model.py-e +0 -128
  67. langroid/agent/tools/grammar_based_model_lark.py +0 -156
  68. langroid/agent/tools/grammar_based_model_lark.py-e +0 -153
  69. langroid/agent/tools/grammar_based_model_parse.py +0 -86
  70. langroid/agent/tools/grammar_based_model_parse.py-e +0 -80
  71. langroid/agent/tools/grammar_based_model_parsimonious.py +0 -129
  72. langroid/agent/tools/grammar_based_model_parsimonious.py-e +0 -120
  73. langroid/agent/tools/grammar_based_model_pyparsing.py +0 -105
  74. langroid/agent/tools/grammar_based_model_pyparsing.py-e +0 -103
  75. langroid/agent/tools/grammar_based_model_regex.py +0 -139
  76. langroid/agent/tools/grammar_based_model_regex.py-e +0 -130
  77. langroid/agent/tools/grammar_based_model_regex2.py +0 -124
  78. langroid/agent/tools/grammar_based_model_regex2.py-e +0 -116
  79. langroid/agent/tools/grammar_based_model_tatsu.py +0 -80
  80. langroid/agent/tools/grammar_based_model_tatsu.py-e +0 -77
  81. langroid/agent/tools/lark_earley_example.py +0 -135
  82. langroid/agent/tools/lark_earley_example.py-e +0 -117
  83. langroid/agent/tools/lark_example.py +0 -72
  84. langroid/agent/tools/note_tool.py +0 -0
  85. langroid/agent/tools/parse_example.py +0 -76
  86. langroid/agent/tools/parse_example2.py +0 -87
  87. langroid/agent/tools/parse_example3.py +0 -42
  88. langroid/agent/tools/parse_test.py +0 -791
  89. langroid/agent/tools/run_python_code.py +0 -60
  90. {langroid-0.16.7.dist-info → langroid-0.17.1.dist-info}/LICENSE +0 -0
  91. {langroid-0.16.7.dist-info → langroid-0.17.1.dist-info}/WHEEL +0 -0
@@ -1,72 +0,0 @@
1
- from typing import ClassVar
2
-
3
- from lark import Lark, Transformer, Tree
4
-
5
- from langroid.pydantic_v1 import BaseModel
6
-
7
-
8
- class Person(BaseModel):
9
- name: str
10
- age: int
11
- city: str
12
-
13
- # Class variable to hold the grammar
14
- grammar: ClassVar[
15
- str
16
- ] = """
17
- start: "START Person" "\n" field ("---" "\n" field)* "END Person"
18
- field: NAME "=" VALUE
19
- NAME: "name" | "age" | "city"
20
- VALUE: /[^\n]+/
21
-
22
- %import common.WS
23
- %ignore WS
24
- """
25
-
26
- @classmethod
27
- def from_string(cls, string: str) -> "Person":
28
- parser = Lark(cls.grammar, parser="lalr", transformer=PersonTransformer())
29
- result = parser.parse(string)
30
- return cls(**result)
31
-
32
- def to_string(self) -> str:
33
- parser = Lark(self.grammar, parser="lalr")
34
- tree = Tree(
35
- "start",
36
- [
37
- Tree("field", [Tree("NAME", [name]), Tree("VALUE", [str(value)])])
38
- for name, value in self.dict().items()
39
- ],
40
- )
41
- return parser.serialize(tree)
42
-
43
-
44
- class PersonTransformer(Transformer):
45
- def start(self, items):
46
- return dict(items)
47
-
48
- def field(self, items):
49
- name, value = items
50
- if name == "age":
51
- value = int(value)
52
- return name, value
53
-
54
-
55
- # Example usage:
56
- if __name__ == "__main__":
57
- # Create a Person instance
58
- p = Person(name="John Doe", age=30, city="New York")
59
-
60
- # Convert to string
61
- s = p.to_string()
62
- print("To string:")
63
- print(s)
64
- print()
65
-
66
- # Parse from string
67
- p2 = Person.from_string(s)
68
- print("Parsed from string:")
69
- print(p2)
70
-
71
- # Demonstrate that they're equal
72
- print("\nAre equal:", p == p2)
File without changes
@@ -1,76 +0,0 @@
1
- from datetime import datetime
2
-
3
- from parse import compile
4
-
5
-
6
- class PersonFormatter:
7
- # Define the grammar/template as a class attribute
8
- GRAMMAR = """
9
- Name: {name}
10
- Age: {age:d}
11
- Birthday: {birthday}
12
- Hobbies: {hobbies}
13
- """
14
-
15
- @classmethod
16
- def parse(cls, string):
17
- parser = compile(cls.GRAMMAR)
18
- result = parser.parse(string)
19
- if result:
20
- return {
21
- "name": result["name"],
22
- "age": result["age"],
23
- "birthday": datetime.strptime(result["birthday"], "%Y-%m-%d").date(),
24
- "hobbies": [hobby.strip() for hobby in result["hobbies"].split(",")],
25
- }
26
- return None
27
-
28
- @classmethod
29
- def format(cls, data):
30
- hobbies_str = ", ".join(data["hobbies"])
31
- return cls.GRAMMAR.format(
32
- name=data["name"],
33
- age=data["age"],
34
- birthday=data["birthday"].strftime("%Y-%m-%d"),
35
- hobbies=hobbies_str,
36
- )
37
-
38
-
39
- # Example usage
40
- if __name__ == "__main__":
41
- # Parsing
42
- input_string = """
43
- Name: John Doe
44
- Age: 30
45
- Birthday: 1993-05-15
46
- Hobbies: reading, swimming, coding
47
- """
48
- parsed_data = PersonFormatter.parse(input_string)
49
- print("Parsed data:", parsed_data)
50
-
51
- # Formatting
52
- person_data = {
53
- "name": "Jane Smith",
54
- "age": 25,
55
- "birthday": datetime(1998, 8, 22).date(),
56
- "hobbies": ["painting", "yoga", "traveling"],
57
- }
58
- formatted_string = PersonFormatter.format(person_data)
59
- print("\nFormatted string:")
60
- print(formatted_string)
61
-
62
- # Demonstrating bidirectional conversion
63
- print("\nBidirectional conversion:")
64
- original_string = """
65
- Name: Alice Johnson
66
- Age: 35
67
- Birthday: 1988-12-01
68
- Hobbies: gardening, photography, cooking
69
- """
70
- print("Original:")
71
- print(original_string)
72
- parsed = PersonFormatter.parse(original_string)
73
- print("Parsed:", parsed)
74
- reformatted = PersonFormatter.format(parsed)
75
- print("Reformatted:")
76
- print(reformatted)
@@ -1,87 +0,0 @@
1
- from parse import parse
2
-
3
- # Define the format string
4
- format_string = """
5
- name:{:s}
6
- {:d} is the age
7
- lives in {:s}
8
- """
9
-
10
-
11
- def parse_person_info(input_string):
12
- # Remove leading/trailing whitespace and split into lines
13
- lines = input_string.strip().split("\n")
14
-
15
- # Join the lines with a single newline
16
- normalized_input = "\n".join(line.strip() for line in lines if line.strip())
17
-
18
- # Parse the normalized input
19
- result = parse(format_string, normalized_input)
20
-
21
- if result:
22
- name, age, city = result
23
- return f"Name: {name.strip()}, Age: {age}, City: {city.strip()}"
24
- else:
25
- return "Parsing failed"
26
-
27
-
28
- # Test cases and assertions
29
- if __name__ == "__main__":
30
- # Test case 1: Standard format
31
- input1 = """
32
- name: Beck
33
- 30 is the age
34
- lives in Tokyo
35
- """
36
- assert (
37
- parse_person_info(input1) == "Name: Beck, Age: 30, City: Tokyo"
38
- ), "Test case 1 failed"
39
-
40
- # Test case 2: Extra whitespace
41
- input2 = """
42
- name: Beck
43
- 30 is the age
44
- lives in Tokyo
45
- """
46
- assert (
47
- parse_person_info(input2) == "Name: Beck, Age: 30, City: Tokyo"
48
- ), "Test case 2 failed"
49
-
50
- # Test case 3: Extra newlines
51
- input3 = """
52
- name:Beck
53
-
54
-
55
- 30 is the age
56
-
57
- lives in Tokyo
58
- """
59
- assert (
60
- parse_person_info(input3) == "Name: Beck, Age: 30, City: Tokyo"
61
- ), "Test case 3 failed"
62
-
63
- # Test case 4: Minimal whitespace
64
- input4 = "name:John\n25 is the age\nlives in NewYork"
65
- assert (
66
- parse_person_info(input4) == "Name: John, Age: 25, City: NewYork"
67
- ), "Test case 4 failed"
68
-
69
- # Test case 5: Different name, age, city
70
- input5 = """
71
- name: Alice Johnson
72
- 42 is the age
73
- lives in San Francisco
74
- """
75
- assert (
76
- parse_person_info(input5) == "Name: Alice Johnson, Age: 42, City: San Francisco"
77
- ), "Test case 5 failed"
78
-
79
- # Test case 6: Invalid format (should return "Parsing failed")
80
- input6 = """
81
- name: Invalid
82
- not a number is the age
83
- lives in Nowhere
84
- """
85
- assert parse_person_info(input6) == "Parsing failed", "Test case 6 failed"
86
-
87
- print("All tests passed successfully!")
@@ -1,42 +0,0 @@
1
- from parse import parse
2
-
3
- # Define the parse specification
4
- parse_spec = """
5
- <format>
6
- name{:s}{:>}{}\n
7
- age{:s}{:>}{}\n
8
- </format>
9
- """
10
-
11
-
12
- def parse_info(input_string):
13
- print(f"Input string:\n{input_string}") # Debug print
14
- result = parse(parse_spec, input_string, case_sensitive=False)
15
- print(f"Parse result: {result}") # Debug print
16
- if result:
17
- name = result[1].strip() # The actual name value is in the second group
18
- age = result[3].strip() # The actual age value is in the fourth group
19
- return name, age
20
- else:
21
- return None
22
-
23
-
24
- if __name__ == "__main__":
25
- # Test case 1: Standard format
26
- input_string1 = """
27
- <format>
28
- name beck
29
- age 30
30
- </format>
31
- """
32
- print("\nTest case 1:")
33
- result1 = parse_info(input_string1)
34
- print(f"Test 1 result: {result1}")
35
- assert result1 == (
36
- "beck",
37
- "30",
38
- ), f"Test 1 failed. Expected ('beck', '30'), got {result1}"
39
-
40
- # Additional test cases...
41
-
42
- print("All tests passed successfully!")