lionagi 0.2.10__py3-none-any.whl → 0.3.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. lionagi/core/action/function_calling.py +13 -6
  2. lionagi/core/action/tool.py +10 -9
  3. lionagi/core/action/tool_manager.py +18 -9
  4. lionagi/core/agent/README.md +1 -1
  5. lionagi/core/agent/base_agent.py +5 -2
  6. lionagi/core/agent/eval/README.md +1 -1
  7. lionagi/core/collections/README.md +1 -1
  8. lionagi/core/collections/_logger.py +16 -6
  9. lionagi/core/collections/abc/README.md +1 -1
  10. lionagi/core/collections/abc/component.py +35 -11
  11. lionagi/core/collections/abc/concepts.py +5 -3
  12. lionagi/core/collections/abc/exceptions.py +3 -1
  13. lionagi/core/collections/flow.py +16 -5
  14. lionagi/core/collections/model.py +34 -8
  15. lionagi/core/collections/pile.py +65 -28
  16. lionagi/core/collections/progression.py +1 -2
  17. lionagi/core/collections/util.py +11 -2
  18. lionagi/core/director/README.md +1 -1
  19. lionagi/core/engine/branch_engine.py +35 -10
  20. lionagi/core/engine/instruction_map_engine.py +14 -5
  21. lionagi/core/engine/sandbox_.py +3 -1
  22. lionagi/core/engine/script_engine.py +6 -2
  23. lionagi/core/executor/base_executor.py +10 -3
  24. lionagi/core/executor/graph_executor.py +12 -4
  25. lionagi/core/executor/neo4j_executor.py +18 -6
  26. lionagi/core/generic/edge.py +7 -2
  27. lionagi/core/generic/graph.py +23 -7
  28. lionagi/core/generic/node.py +14 -5
  29. lionagi/core/generic/tree_node.py +5 -1
  30. lionagi/core/mail/mail_manager.py +3 -1
  31. lionagi/core/mail/package.py +3 -1
  32. lionagi/core/message/action_request.py +9 -2
  33. lionagi/core/message/action_response.py +9 -3
  34. lionagi/core/message/instruction.py +8 -2
  35. lionagi/core/message/util.py +15 -5
  36. lionagi/core/report/base.py +12 -7
  37. lionagi/core/report/form.py +7 -4
  38. lionagi/core/report/report.py +10 -3
  39. lionagi/core/report/util.py +3 -1
  40. lionagi/core/rule/action.py +4 -1
  41. lionagi/core/rule/base.py +17 -6
  42. lionagi/core/rule/rulebook.py +8 -4
  43. lionagi/core/rule/string.py +3 -1
  44. lionagi/core/session/branch.py +15 -4
  45. lionagi/core/session/session.py +6 -2
  46. lionagi/core/unit/parallel_unit.py +9 -3
  47. lionagi/core/unit/template/action.py +1 -1
  48. lionagi/core/unit/template/predict.py +3 -1
  49. lionagi/core/unit/template/select.py +5 -3
  50. lionagi/core/unit/unit.py +50 -2
  51. lionagi/core/unit/unit_form.py +13 -15
  52. lionagi/core/unit/unit_mixin.py +45 -27
  53. lionagi/core/unit/util.py +7 -3
  54. lionagi/core/validator/validator.py +28 -15
  55. lionagi/core/work/work_edge.py +7 -3
  56. lionagi/core/work/work_task.py +11 -5
  57. lionagi/core/work/worker.py +20 -5
  58. lionagi/core/work/worker_engine.py +6 -2
  59. lionagi/core/work/worklog.py +3 -1
  60. lionagi/experimental/compressor/llm_compressor.py +20 -5
  61. lionagi/experimental/directive/README.md +1 -1
  62. lionagi/experimental/directive/parser/base_parser.py +41 -14
  63. lionagi/experimental/directive/parser/base_syntax.txt +23 -23
  64. lionagi/experimental/directive/template/base_template.py +14 -6
  65. lionagi/experimental/directive/tokenizer.py +3 -1
  66. lionagi/experimental/evaluator/README.md +1 -1
  67. lionagi/experimental/evaluator/ast_evaluator.py +6 -2
  68. lionagi/experimental/evaluator/base_evaluator.py +27 -16
  69. lionagi/integrations/bridge/autogen_/autogen_.py +7 -3
  70. lionagi/integrations/bridge/langchain_/documents.py +13 -10
  71. lionagi/integrations/bridge/llamaindex_/llama_pack.py +36 -12
  72. lionagi/integrations/bridge/llamaindex_/node_parser.py +8 -3
  73. lionagi/integrations/bridge/llamaindex_/reader.py +3 -1
  74. lionagi/integrations/bridge/llamaindex_/textnode.py +9 -3
  75. lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +7 -1
  76. lionagi/integrations/bridge/transformers_/install_.py +3 -1
  77. lionagi/integrations/chunker/chunk.py +5 -2
  78. lionagi/integrations/loader/load.py +7 -3
  79. lionagi/integrations/loader/load_util.py +35 -16
  80. lionagi/integrations/provider/oai.py +13 -4
  81. lionagi/integrations/provider/openrouter.py +13 -4
  82. lionagi/integrations/provider/services.py +3 -1
  83. lionagi/integrations/provider/transformers.py +5 -3
  84. lionagi/integrations/storage/neo4j.py +23 -7
  85. lionagi/integrations/storage/storage_util.py +23 -7
  86. lionagi/integrations/storage/structure_excel.py +7 -2
  87. lionagi/integrations/storage/to_csv.py +8 -2
  88. lionagi/integrations/storage/to_excel.py +11 -3
  89. lionagi/libs/ln_api.py +41 -19
  90. lionagi/libs/ln_context.py +4 -4
  91. lionagi/libs/ln_convert.py +35 -14
  92. lionagi/libs/ln_dataframe.py +9 -3
  93. lionagi/libs/ln_func_call.py +53 -18
  94. lionagi/libs/ln_image.py +9 -5
  95. lionagi/libs/ln_knowledge_graph.py +21 -7
  96. lionagi/libs/ln_nested.py +57 -16
  97. lionagi/libs/ln_parse.py +45 -15
  98. lionagi/libs/ln_queue.py +8 -3
  99. lionagi/libs/ln_tokenize.py +19 -6
  100. lionagi/libs/ln_validate.py +14 -3
  101. lionagi/libs/sys_util.py +44 -12
  102. lionagi/lions/coder/coder.py +24 -8
  103. lionagi/lions/coder/util.py +6 -2
  104. lionagi/lions/researcher/data_source/google_.py +12 -4
  105. lionagi/lions/researcher/data_source/wiki_.py +3 -1
  106. lionagi/version.py +1 -1
  107. {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/METADATA +6 -7
  108. lionagi-0.3.0.dist-info/RECORD +226 -0
  109. lionagi/tests/__init__.py +0 -0
  110. lionagi/tests/api/__init__.py +0 -0
  111. lionagi/tests/api/aws/__init__.py +0 -0
  112. lionagi/tests/api/aws/conftest.py +0 -25
  113. lionagi/tests/api/aws/test_aws_s3.py +0 -6
  114. lionagi/tests/integrations/__init__.py +0 -0
  115. lionagi/tests/libs/__init__.py +0 -0
  116. lionagi/tests/libs/test_api.py +0 -48
  117. lionagi/tests/libs/test_convert.py +0 -89
  118. lionagi/tests/libs/test_field_validators.py +0 -354
  119. lionagi/tests/libs/test_func_call.py +0 -701
  120. lionagi/tests/libs/test_nested.py +0 -382
  121. lionagi/tests/libs/test_parse.py +0 -171
  122. lionagi/tests/libs/test_queue.py +0 -68
  123. lionagi/tests/libs/test_sys_util.py +0 -222
  124. lionagi/tests/test_core/__init__.py +0 -0
  125. lionagi/tests/test_core/collections/__init__.py +0 -0
  126. lionagi/tests/test_core/collections/test_component.py +0 -208
  127. lionagi/tests/test_core/collections/test_exchange.py +0 -139
  128. lionagi/tests/test_core/collections/test_flow.py +0 -146
  129. lionagi/tests/test_core/collections/test_pile.py +0 -172
  130. lionagi/tests/test_core/collections/test_progression.py +0 -130
  131. lionagi/tests/test_core/generic/__init__.py +0 -0
  132. lionagi/tests/test_core/generic/test_edge.py +0 -69
  133. lionagi/tests/test_core/generic/test_graph.py +0 -97
  134. lionagi/tests/test_core/generic/test_node.py +0 -107
  135. lionagi/tests/test_core/generic/test_structure.py +0 -194
  136. lionagi/tests/test_core/generic/test_tree_node.py +0 -74
  137. lionagi/tests/test_core/graph/__init__.py +0 -0
  138. lionagi/tests/test_core/graph/test_graph.py +0 -71
  139. lionagi/tests/test_core/graph/test_tree.py +0 -76
  140. lionagi/tests/test_core/mail/__init__.py +0 -0
  141. lionagi/tests/test_core/mail/test_mail.py +0 -98
  142. lionagi/tests/test_core/test_branch.py +0 -116
  143. lionagi/tests/test_core/test_form.py +0 -47
  144. lionagi/tests/test_core/test_report.py +0 -106
  145. lionagi/tests/test_core/test_structure/__init__.py +0 -0
  146. lionagi/tests/test_core/test_structure/test_base_structure.py +0 -198
  147. lionagi/tests/test_core/test_structure/test_graph.py +0 -55
  148. lionagi/tests/test_core/test_structure/test_tree.py +0 -49
  149. lionagi/tests/test_core/test_validator.py +0 -112
  150. lionagi-0.2.10.dist-info/RECORD +0 -267
  151. {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/LICENSE +0 -0
  152. {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/WHEEL +0 -0
@@ -1,354 +0,0 @@
1
- import unittest
2
- from unittest.mock import patch
3
-
4
- from lionagi.libs.ln_validate import (
5
- _fix_action_field,
6
- _fix_bool_field,
7
- _fix_enum_field,
8
- _fix_number_field,
9
- _fix_str_field,
10
- check_action_field,
11
- check_bool_field,
12
- check_dict_field,
13
- check_enum_field,
14
- check_number_field,
15
- check_str_field,
16
- )
17
-
18
-
19
- class TestValidationFunctions(unittest.TestCase):
20
- def test_check_dict_field_valid(self):
21
- x = {"key": "value"}
22
- keys = ["key"]
23
- result = check_dict_field(x, keys)
24
- self.assertEqual(result, x)
25
-
26
- def test_fix_action_field_invalid_string(self):
27
- x = '[{"invalid_key": "value"}]'
28
- try:
29
- _fix_action_field(x)
30
- except ValueError as e:
31
- self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
32
-
33
- def test_fix_action_field_invalid_discard_disabled(self):
34
- x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
35
- try:
36
- _fix_action_field(x, discard_=False)
37
- except ValueError as e:
38
- self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
39
-
40
- def test_check_dict_field_invalid_fixable(self):
41
- x = '{"key": "value"}'
42
- keys = ["key"]
43
- result = check_dict_field(x, keys, fix_=True)
44
- self.assertEqual(result, {"key": "value"})
45
-
46
- def test_check_dict_field_invalid_not_fixable(self):
47
- x = '{"invalid_key": "value"}'
48
- keys = ["key"]
49
- with self.assertRaises(ValueError) as cm:
50
- check_dict_field(x, keys, fix_=False)
51
- self.assertEqual(
52
- str(cm.exception), "Default value for DICT must be a dict, got str"
53
- )
54
-
55
- def test_check_action_field_invalid_not_fixable(self):
56
- x = '[{"invalid_key": "value"}]'
57
- try:
58
- check_action_field(x, fix_=False)
59
- except ValueError as e:
60
- self.assertEqual(str(e), "Invalid action field type.")
61
-
62
- def test_check_action_field_invalid_fix_disabled(self):
63
- x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
64
- try:
65
- check_action_field(x, fix_=False)
66
- except ValueError as e:
67
- self.assertEqual(str(e), "Invalid action field type.")
68
-
69
- def test_check_action_field_valid(self):
70
- x = [
71
- {"function": "func1", "arguments": {}},
72
- {"function": "func2", "arguments": {}},
73
- ]
74
- result = check_action_field(x)
75
- self.assertEqual(result, x)
76
-
77
- def test_check_action_field_invalid_fixable(self):
78
- x = '[{"function": "func1", "arguments": {}}, {"function": "func2", "arguments": {}}]'
79
- result = check_action_field(x, fix_=True)
80
- self.assertEqual(
81
- result,
82
- [
83
- {"function": "func1", "arguments": {}},
84
- {"function": "func2", "arguments": {}},
85
- ],
86
- )
87
-
88
- def test_check_action_field_invalid_fix_disabled(self):
89
- x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
90
- try:
91
- check_action_field(x, fix_=False)
92
- except ValueError as e:
93
- self.assertEqual(str(e), "Invalid action field type.")
94
-
95
- def test_check_number_field_valid(self):
96
- x = 42
97
- result = check_number_field(x)
98
- self.assertEqual(result, x)
99
-
100
- def test_check_number_field_invalid_fixable(self):
101
- x = "42"
102
- result = check_number_field(x, fix_=True)
103
- self.assertEqual(result, 42)
104
-
105
- def test_check_number_field_invalid_not_fixable(self):
106
- x = "not_a_number"
107
- with self.assertRaises(ValueError) as cm:
108
- check_number_field(x, fix_=True)
109
- self.assertEqual(
110
- str(cm.exception), "Failed to convert not_a_number into a numeric value"
111
- )
112
-
113
- def test_check_number_field_invalid_fix_disabled(self):
114
- x = "42"
115
- with self.assertRaises(ValueError) as cm:
116
- check_number_field(x, fix_=False)
117
- self.assertEqual(
118
- str(cm.exception),
119
- "Default value for NUMERIC must be an int or float, got str",
120
- )
121
-
122
- def test_check_bool_field_valid(self):
123
- x = True
124
- result = check_bool_field(x)
125
- self.assertEqual(result, x)
126
-
127
- def test_check_bool_field_invalid_fixable(self):
128
- x = "true"
129
- result = check_bool_field(x, fix_=True)
130
- self.assertTrue(result)
131
-
132
- def test_check_bool_field_invalid_not_fixable(self):
133
- x = "not_a_boolean"
134
- with self.assertRaises(ValueError) as cm:
135
- check_bool_field(x, fix_=True)
136
- self.assertEqual(
137
- str(cm.exception), "Failed to convert not_a_boolean into a boolean value"
138
- )
139
-
140
- def test_check_bool_field_invalid_fix_disabled(self):
141
- x = "true"
142
- with self.assertRaises(ValueError) as cm:
143
- check_bool_field(x, fix_=False)
144
- self.assertEqual(
145
- str(cm.exception), "Default value for BOOLEAN must be a bool, got str"
146
- )
147
-
148
- def test_check_str_field_valid(self):
149
- x = "hello"
150
- result = check_str_field(x)
151
- self.assertEqual(result, x)
152
-
153
- def test_check_str_field_invalid_fixable(self):
154
- x = 42
155
- result = check_str_field(x, fix_=True)
156
- self.assertEqual(result, "42")
157
-
158
- def test_check_str_field_invalid_not_fixable(self):
159
- x = object()
160
- try:
161
- check_str_field(x, fix_=False)
162
- except ValueError as e:
163
- self.assertEqual(
164
- str(e), "Default value for STRING must be a str, got object"
165
- )
166
-
167
- def test_check_str_field_invalid_fix_disabled(self):
168
- x = 42
169
- with self.assertRaises(ValueError) as cm:
170
- check_str_field(x, fix_=False)
171
- self.assertEqual(
172
- str(cm.exception), "Default value for STRING must be a str, got int"
173
- )
174
-
175
- def test_check_enum_field_valid(self):
176
- x = "option1"
177
- choices = ["option1", "option2"]
178
- result = check_enum_field(x, choices)
179
- self.assertEqual(result, x)
180
-
181
- def test_check_enum_field_invalid_fixable(self):
182
- x = "option3"
183
- choices = ["option1", "option2"]
184
- with patch("lionagi.libs.ln_validate._fix_enum_field", return_value="option1"):
185
- result = check_enum_field(x, choices, fix_=True)
186
- self.assertEqual(result, "option1")
187
-
188
- def test_check_enum_field_invalid_not_fixable(self):
189
- x = "option3"
190
- choices = ["option1", "option2"]
191
- with self.assertRaises(ValueError) as cm:
192
- check_enum_field(x, choices, fix_=False)
193
- self.assertEqual(
194
- str(cm.exception),
195
- "Default value for ENUM must be one of the ['option1', 'option2'], got option3",
196
- )
197
-
198
- def test_check_enum_field_invalid_choices(self):
199
- x = "option1"
200
- choices = ["option1", 42]
201
- with self.assertRaises(ValueError) as cm:
202
- check_enum_field(x, choices)
203
- self.assertEqual(
204
- str(cm.exception),
205
- "Field type ENUM requires all choices to be of the same type, got ['option1', 42]",
206
- )
207
-
208
- def test_check_enum_field_invalid_type(self):
209
- x = 42
210
- choices = ["option1", "option2"]
211
- with self.assertRaises(ValueError) as cm:
212
- check_enum_field(x, choices)
213
- self.assertEqual(
214
- str(cm.exception),
215
- "Default value for ENUM must be an instance of the str, got int",
216
- )
217
-
218
- def test_fix_action_field_string(self):
219
- x = '[{"function": "func1", "arguments": {}}, {"function": "func2", "arguments": {}}]'
220
- result = _fix_action_field(x)
221
- self.assertEqual(
222
- result,
223
- [
224
- {"function": "func1", "arguments": {}},
225
- {"function": "func2", "arguments": {}},
226
- ],
227
- )
228
-
229
- def test_fix_action_field_invalid_string(self):
230
- x = '[{"invalid_key": "value"}]'
231
- try:
232
- _fix_action_field(x)
233
- except ValueError as e:
234
- self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
235
-
236
- def test_fix_action_field_invalid_discard_disabled(self):
237
- x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
238
- try:
239
- _fix_action_field(x, discard_=False)
240
- except ValueError as e:
241
- self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
242
-
243
- def test_fix_number_field_valid(self):
244
- x = "42"
245
- result = _fix_number_field(x)
246
- self.assertEqual(result, 42)
247
-
248
- def test_fix_number_field_invalid(self):
249
- x = "not_a_number"
250
- with self.assertRaises(ValueError) as cm:
251
- _fix_number_field(x)
252
- self.assertEqual(
253
- str(cm.exception), "Failed to convert not_a_number into a numeric value"
254
- )
255
-
256
- def test_fix_bool_field_true(self):
257
- x = "true"
258
- result = _fix_bool_field(x)
259
- self.assertTrue(result)
260
-
261
- def test_fix_bool_field_false(self):
262
- x = "false"
263
- result = _fix_bool_field(x)
264
- self.assertFalse(result)
265
-
266
- def test_fix_bool_field_invalid(self):
267
- x = "not_a_boolean"
268
- with self.assertRaises(ValueError) as cm:
269
- _fix_bool_field(x)
270
- self.assertEqual(
271
- str(cm.exception), "Failed to convert not_a_boolean into a boolean value"
272
- )
273
-
274
- def test_fix_str_field_valid(self):
275
- x = 42
276
- result = _fix_str_field(x)
277
- self.assertEqual(result, "42")
278
-
279
- def test_fix_str_field_invalid(self):
280
- x = object()
281
- try:
282
- _fix_str_field(x)
283
- except ValueError as e:
284
- self.assertEqual(
285
- str(e),
286
- "Failed to convert <object object at 0x{:x}> into a string value".format(
287
- id(x)
288
- ),
289
- )
290
-
291
- def test_fix_enum_field_valid(self):
292
- x = "option3"
293
- choices = ["option1", "option2"]
294
- with patch(
295
- "lionagi.libs.StringMatch.choose_most_similar", return_value="option1"
296
- ):
297
- result = _fix_enum_field(x, choices)
298
- self.assertEqual(result, "option1")
299
-
300
- def test_fix_enum_field_invalid(self):
301
- x = "option3"
302
- choices = ["option1", "option2"]
303
- with patch(
304
- "lionagi.libs.StringMatch.choose_most_similar",
305
- side_effect=ValueError("No match found"),
306
- ):
307
- with self.assertRaises(ValueError) as cm:
308
- _fix_enum_field(x, choices)
309
- self.assertEqual(
310
- str(cm.exception), "Failed to convert option3 into one of the choices"
311
- )
312
-
313
- def test_fix_bool_field_false(self):
314
- x = "false"
315
- result = _fix_bool_field(x)
316
- self.assertFalse(result)
317
-
318
- def test_fix_str_field_invalid(self):
319
- x = object()
320
- try:
321
- _fix_str_field(x)
322
- except ValueError as e:
323
- self.assertEqual(
324
- str(e),
325
- "Failed to convert <object object at 0x{:x}> into a string value".format(
326
- id(x)
327
- ),
328
- )
329
-
330
- def test_fix_enum_field_valid(self):
331
- x = "option3"
332
- choices = ["option1", "option2"]
333
- with patch(
334
- "lionagi.libs.StringMatch.choose_most_similar", return_value="option1"
335
- ):
336
- result = _fix_enum_field(x, choices)
337
- self.assertEqual(result, "option1")
338
-
339
- def test_fix_enum_field_invalid(self):
340
- x = "option3"
341
- choices = ["option1", "option2"]
342
- with patch(
343
- "lionagi.libs.StringMatch.choose_most_similar",
344
- side_effect=ValueError("No match found"),
345
- ):
346
- with self.assertRaises(ValueError) as cm:
347
- _fix_enum_field(x, choices)
348
- self.assertEqual(
349
- str(cm.exception), "Failed to convert option3 into one of the choices"
350
- )
351
-
352
-
353
- if __name__ == "__main__":
354
- unittest.main()