lionagi 0.2.7__py3-none-any.whl → 0.2.8__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. lionagi/__init__.py +11 -25
  2. lionagi/core/action/README.md +20 -0
  3. lionagi/core/action/__init__.py +1 -2
  4. lionagi/core/action/function_calling.py +2 -27
  5. lionagi/core/action/node.py +1 -16
  6. lionagi/core/action/tool.py +4 -17
  7. lionagi/core/action/tool_manager.py +8 -31
  8. lionagi/core/agent/README.md +1 -0
  9. lionagi/core/agent/base_agent.py +3 -27
  10. lionagi/core/agent/eval/README.md +1 -0
  11. lionagi/core/collections/README.md +23 -0
  12. lionagi/core/collections/__init__.py +2 -3
  13. lionagi/core/collections/_logger.py +0 -17
  14. lionagi/core/collections/abc/README.md +63 -0
  15. lionagi/core/collections/abc/__init__.py +18 -18
  16. lionagi/core/collections/abc/component.py +5 -21
  17. lionagi/core/collections/abc/concepts.py +1 -17
  18. lionagi/core/collections/abc/exceptions.py +0 -16
  19. lionagi/core/collections/exchange.py +1 -16
  20. lionagi/core/collections/flow.py +5 -25
  21. lionagi/core/collections/model.py +6 -21
  22. lionagi/core/collections/pile.py +317 -35
  23. lionagi/core/collections/progression.py +4 -17
  24. lionagi/core/collections/util.py +2 -2
  25. lionagi/core/director/README.md +1 -0
  26. lionagi/core/director/direct.py +1 -17
  27. lionagi/core/engine/branch_engine.py +6 -6
  28. lionagi/core/engine/instruction_map_engine.py +4 -4
  29. lionagi/core/engine/script_engine.py +2 -16
  30. lionagi/core/executor/base_executor.py +1 -1
  31. lionagi/core/executor/graph_executor.py +6 -9
  32. lionagi/core/executor/neo4j_executor.py +7 -9
  33. lionagi/core/generic/README.md +0 -0
  34. lionagi/core/generic/__init__.py +1 -2
  35. lionagi/core/generic/edge.py +7 -3
  36. lionagi/core/generic/edge_condition.py +3 -2
  37. lionagi/core/generic/graph.py +5 -6
  38. lionagi/core/generic/node.py +4 -4
  39. lionagi/core/generic/tree.py +2 -1
  40. lionagi/core/generic/tree_node.py +2 -0
  41. lionagi/core/mail/__init__.py +0 -1
  42. lionagi/core/mail/mail.py +2 -1
  43. lionagi/core/mail/mail_manager.py +8 -6
  44. lionagi/core/mail/package.py +2 -0
  45. lionagi/core/mail/start_mail.py +2 -2
  46. lionagi/core/message/__init__.py +4 -5
  47. lionagi/core/message/action_request.py +5 -31
  48. lionagi/core/message/action_response.py +3 -23
  49. lionagi/core/message/assistant_response.py +2 -17
  50. lionagi/core/message/instruction.py +2 -48
  51. lionagi/core/message/message.py +2 -17
  52. lionagi/core/message/system.py +2 -17
  53. lionagi/core/message/util.py +7 -26
  54. lionagi/core/report/base.py +4 -26
  55. lionagi/core/report/form.py +7 -28
  56. lionagi/core/report/report.py +3 -26
  57. lionagi/core/report/util.py +2 -17
  58. lionagi/core/rule/_default.py +3 -2
  59. lionagi/core/rule/action.py +4 -19
  60. lionagi/core/rule/base.py +4 -19
  61. lionagi/core/rule/boolean.py +2 -2
  62. lionagi/core/rule/choice.py +3 -2
  63. lionagi/core/rule/mapping.py +7 -21
  64. lionagi/core/rule/number.py +3 -1
  65. lionagi/core/rule/rulebook.py +2 -70
  66. lionagi/core/rule/string.py +2 -13
  67. lionagi/core/rule/util.py +0 -35
  68. lionagi/core/session/branch.py +11 -27
  69. lionagi/core/session/directive_mixin.py +1 -16
  70. lionagi/core/session/session.py +8 -24
  71. lionagi/core/unit/__init__.py +1 -2
  72. lionagi/core/unit/parallel_unit.py +4 -21
  73. lionagi/core/unit/template/action.py +0 -16
  74. lionagi/core/unit/template/base.py +0 -16
  75. lionagi/core/unit/template/plan.py +1 -16
  76. lionagi/core/unit/template/predict.py +0 -16
  77. lionagi/core/unit/template/score.py +1 -17
  78. lionagi/core/unit/template/select.py +1 -16
  79. lionagi/core/unit/unit.py +6 -21
  80. lionagi/core/unit/unit_form.py +6 -19
  81. lionagi/core/unit/unit_mixin.py +11 -29
  82. lionagi/core/unit/util.py +1 -0
  83. lionagi/core/validator/validator.py +8 -22
  84. lionagi/core/work/work.py +2 -19
  85. lionagi/core/work/work_edge.py +3 -3
  86. lionagi/core/work/work_function.py +1 -18
  87. lionagi/core/work/work_function_node.py +0 -5
  88. lionagi/core/work/work_queue.py +1 -16
  89. lionagi/core/work/work_task.py +4 -4
  90. lionagi/core/work/worker.py +5 -20
  91. lionagi/core/work/worker_engine.py +5 -5
  92. lionagi/core/work/worklog.py +1 -17
  93. lionagi/experimental/compressor/base.py +1 -0
  94. lionagi/experimental/compressor/llm_compressor.py +7 -4
  95. lionagi/experimental/directive/README.md +1 -0
  96. lionagi/experimental/directive/parser/base_parser.py +2 -17
  97. lionagi/experimental/directive/parser/base_syntax.txt +200 -0
  98. lionagi/experimental/directive/template/base_template.py +1 -17
  99. lionagi/experimental/directive/tokenizer.py +0 -16
  100. lionagi/experimental/evaluator/README.md +1 -0
  101. lionagi/experimental/evaluator/ast_evaluator.py +0 -16
  102. lionagi/experimental/evaluator/base_evaluator.py +1 -17
  103. lionagi/experimental/knowledge/base.py +1 -1
  104. lionagi/integrations/bridge/__init__.py +1 -1
  105. lionagi/integrations/bridge/langchain_/documents.py +1 -1
  106. lionagi/integrations/bridge/llamaindex_/node_parser.py +2 -1
  107. lionagi/integrations/bridge/llamaindex_/textnode.py +2 -1
  108. lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +1 -1
  109. lionagi/integrations/bridge/transformers_/install_.py +1 -0
  110. lionagi/integrations/chunker/chunk.py +5 -6
  111. lionagi/integrations/loader/load.py +3 -3
  112. lionagi/integrations/loader/load_util.py +2 -2
  113. lionagi/integrations/provider/__init__.py +0 -1
  114. lionagi/integrations/provider/_mapping.py +6 -5
  115. lionagi/integrations/provider/mlx_service.py +4 -3
  116. lionagi/integrations/provider/oai.py +1 -17
  117. lionagi/integrations/provider/ollama.py +1 -1
  118. lionagi/integrations/provider/openrouter.py +1 -0
  119. lionagi/integrations/provider/transformers.py +2 -2
  120. lionagi/integrations/storage/neo4j.py +1 -1
  121. lionagi/integrations/storage/storage_util.py +3 -4
  122. lionagi/integrations/storage/structure_excel.py +5 -4
  123. lionagi/integrations/storage/to_csv.py +3 -2
  124. lionagi/integrations/storage/to_excel.py +2 -2
  125. lionagi/libs/__init__.py +15 -19
  126. lionagi/libs/ln_api.py +9 -26
  127. lionagi/libs/ln_async.py +3 -2
  128. lionagi/libs/ln_convert.py +1 -18
  129. lionagi/libs/ln_func_call.py +3 -20
  130. lionagi/libs/ln_image.py +4 -1
  131. lionagi/libs/ln_knowledge_graph.py +5 -2
  132. lionagi/libs/ln_nested.py +2 -18
  133. lionagi/libs/ln_parse.py +4 -19
  134. lionagi/libs/ln_queue.py +2 -17
  135. lionagi/libs/ln_tokenize.py +3 -1
  136. lionagi/libs/ln_validate.py +2 -18
  137. lionagi/libs/sys_util.py +0 -16
  138. lionagi/lions/coder/code_form.py +3 -1
  139. lionagi/lions/coder/coder.py +1 -1
  140. lionagi/lions/coder/util.py +3 -2
  141. lionagi/lions/researcher/data_source/finhub_.py +1 -0
  142. lionagi/lions/researcher/data_source/google_.py +2 -2
  143. lionagi/lions/researcher/data_source/wiki_.py +1 -1
  144. lionagi/tests/libs/test_api.py +2 -1
  145. lionagi/tests/libs/test_convert.py +2 -1
  146. lionagi/tests/libs/test_field_validators.py +9 -8
  147. lionagi/tests/libs/test_func_call.py +2 -2
  148. lionagi/tests/libs/test_nested.py +1 -0
  149. lionagi/tests/libs/test_queue.py +1 -0
  150. lionagi/tests/libs/test_sys_util.py +4 -4
  151. lionagi/tests/test_core/collections/test_component.py +6 -4
  152. lionagi/tests/test_core/collections/test_exchange.py +2 -1
  153. lionagi/tests/test_core/collections/test_flow.py +2 -1
  154. lionagi/tests/test_core/collections/test_pile.py +3 -2
  155. lionagi/tests/test_core/collections/test_progression.py +3 -2
  156. lionagi/tests/test_core/generic/test_edge.py +4 -2
  157. lionagi/tests/test_core/generic/test_graph.py +3 -2
  158. lionagi/tests/test_core/generic/test_node.py +2 -1
  159. lionagi/tests/test_core/generic/test_tree_node.py +2 -1
  160. lionagi/tests/test_core/mail/test_mail.py +2 -1
  161. lionagi/tests/test_core/test_branch.py +3 -2
  162. lionagi/tests/test_core/test_form.py +1 -0
  163. lionagi/tests/test_core/test_report.py +1 -0
  164. lionagi/tests/test_core/test_validator.py +4 -3
  165. lionagi/version.py +1 -1
  166. lionagi-0.2.8.dist-info/METADATA +66 -0
  167. lionagi-0.2.8.dist-info/RECORD +267 -0
  168. {lionagi-0.2.7.dist-info → lionagi-0.2.8.dist-info}/WHEEL +1 -2
  169. lionagi-0.2.7.dist-info/METADATA +0 -277
  170. lionagi-0.2.7.dist-info/RECORD +0 -258
  171. lionagi-0.2.7.dist-info/top_level.txt +0 -1
  172. {lionagi-0.2.7.dist-info → lionagi-0.2.8.dist-info}/LICENSE +0 -0
lionagi/core/rule/base.py CHANGED
@@ -1,25 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from abc import abstractmethod
18
- from typing import Any, List, Dict
2
+ from typing import Any, Dict, List
3
+
19
4
  from pandas import Series
20
- from lionagi.libs import SysUtil
21
5
 
22
- from lionagi.core.collections.abc import FieldError, Condition, Actionable, Component
6
+ from lionagi.core.collections.abc import Actionable, Component, Condition, FieldError
7
+ from lionagi.libs import SysUtil
23
8
 
24
9
  _rule_classes = {}
25
10
 
@@ -1,5 +1,5 @@
1
1
  from typing import Any
2
- from lionagi.libs.ln_convert import to_str, strip_lower
2
+
3
3
  from lionagi.core.rule.base import Rule
4
4
 
5
5
 
@@ -46,7 +46,7 @@ class BooleanRule(Rule):
46
46
  Raises:
47
47
  ValueError: If the value cannot be converted to a boolean.
48
48
  """
49
- value = strip_lower(to_str(value))
49
+ value = str(value).strip().lower()
50
50
  if value in ["true", "1", "correct", "yes"]:
51
51
  return True
52
52
 
@@ -1,4 +1,5 @@
1
- from lionagi.libs.ln_parse import StringMatch
1
+ from lionfuncs import choose_most_similar
2
+
2
3
  from lionagi.core.rule.base import Rule
3
4
 
4
5
 
@@ -44,4 +45,4 @@ class ChoiceRule(Rule):
44
45
  Returns:
45
46
  str: The most similar value from the set of predefined choices.
46
47
  """
47
- return StringMatch.choose_most_similar(value, self.keys)
48
+ return choose_most_similar(value, self.keys)
@@ -1,23 +1,7 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from typing import Any
18
1
  from collections.abc import Mapping
19
- from lionagi.libs.ln_convert import to_dict
20
- from lionagi.libs import StringMatch, ParseUtil
2
+ from typing import Any
3
+
4
+ from lionfuncs import to_dict, validate_mapping
21
5
 
22
6
  from lionagi.core.rule.choice import ChoiceRule
23
7
 
@@ -83,13 +67,15 @@ class MappingRule(ChoiceRule):
83
67
  check_keys = set(value.keys())
84
68
  if check_keys != set(self.keys):
85
69
  try:
86
- return StringMatch.force_validate_dict(value, keys=self.keys)
70
+ return validate_mapping(
71
+ value, keys=self.keys, handle_unmatched="force"
72
+ )
87
73
  except Exception as e:
88
74
  raise ValueError("Invalid dict keys.") from e
89
75
 
90
76
  else:
91
77
  try:
92
- return ParseUtil.fuzzy_parse_json(value)
78
+ return to_dict(value, fuzzy_parse=True)
93
79
  except Exception as e:
94
80
  raise ValueError("Invalid dict keys.") from e
95
81
 
@@ -1,5 +1,7 @@
1
1
  from typing import Any
2
- from lionagi.libs.ln_convert import to_num
2
+
3
+ from lionfuncs import to_num
4
+
3
5
  from lionagi.core.rule.base import Rule
4
6
 
5
7
 
@@ -1,6 +1,6 @@
1
- from lionagi.libs.ln_func_call import lcall
2
- from lionagi.core.rule.base import Rule
1
+ from lionfuncs import lcall
3
2
 
3
+ from lionagi.core.rule.base import Rule
4
4
 
5
5
  """
6
6
  rule config schema
@@ -39,71 +39,3 @@ class RuleBook:
39
39
 
40
40
  def __getitem__(self, key: str) -> Rule:
41
41
  return self.rules[key]
42
-
43
- # def add_rule(self, rule_name: str, rule: Rule, config: dict = None):
44
- # if rule_name in self.rules:
45
- # raise ValueError(f"Rule '{rule_name}' already exists.")
46
- # self.rules[rule_name] = rule
47
- # self.ruleorder.append(rule_name)
48
- # self.rule_config[rule_name] = config or {}
49
-
50
- # def remove_rule(self, rule_name: str):
51
- # if rule_name not in self.rules:
52
- # raise ValueError(f"Rule '{rule_name}' does not exist.")
53
- # del self.rules[rule_name]
54
- # self.ruleorder.remove(rule_name)
55
- # del self.rule_config[rule_name]
56
-
57
- # def update_rule_config(self, rule_name: str, config: dict):
58
- # if rule_name not in self.rules:
59
- # raise ValueError(f"Rule '{rule_name}' does not exist.")
60
- # self.rule_config[rule_name] = config
61
-
62
- # def list_rules(self) -> list[str]:
63
- # return self.ruleorder
64
-
65
- # def get_rule_details(self, rule_name: str) -> dict:
66
- # if rule_name not in self.rules:
67
- # raise ValueError(f"Rule '{rule_name}' does not exist.")
68
- # return {
69
- # "rule": self.rules[rule_name],
70
- # "config": self.rule_config[rule_name]
71
- # }
72
-
73
- # async def validate_data(self, data: Any) -> bool:
74
- # for rule in self.rules.values():
75
- # if not await rule.validate(data):
76
- # return False
77
- # return True
78
-
79
- # def export_rulebook(self, filepath: str):
80
- # import json
81
- # with open(filepath, 'w') as f:
82
- # json.dump({
83
- # "rules": list(self.rules.keys()),
84
- # "ruleorder": self.ruleorder,
85
- # "rule_config": self.rule_config
86
- # }, f)
87
-
88
- # @classmethod
89
- # def import_rulebook(cls, filepath: str) -> 'RuleBook':
90
- # import json
91
- # with open(filepath, 'r') as f:
92
- # config = json.load(f)
93
- # rules = {name: Rule() for name in config["rules"]}
94
- # return cls(rules=rules, ruleorder=config["ruleorder"], rule_config=config["rule_config"])
95
-
96
- # def enable_rule(self, rule_name: str, enable: bool = True):
97
- # if rule_name not in self.rules:
98
- # raise ValueError(f"Rule '{rule_name}' does not exist.")
99
- # self.rules[rule_name].enabled = enable
100
-
101
- # def log_rule_application(self, rule_name: str, data: Any):
102
- # if rule_name not in self.rules:
103
- # raise ValueError(f"Rule '{rule_name}' does not exist.")
104
- # log_entry = {
105
- # "rule": rule_name,
106
- # "data": data,
107
- # "timestamp": SysUtil.get_timestamp()
108
- # }
109
- # # Append log_entry to a log file or a logging system
@@ -1,4 +1,5 @@
1
- from lionagi.libs.ln_convert import to_str
1
+ from lionfuncs import to_str
2
+
2
3
  from lionagi.core.rule.base import Rule
3
4
 
4
5
 
@@ -34,18 +35,6 @@ class StringRule(Rule):
34
35
  raise ValueError(f"Invalid string field type.")
35
36
 
36
37
  async def perform_fix(self, value):
37
- """
38
- Attempt to convert a value to a string.
39
-
40
- Args:
41
- value: The value to convert to a string.
42
-
43
- Returns:
44
- str: The value converted to a string.
45
-
46
- Raises:
47
- ValueError: If the value cannot be converted to a string.
48
- """
49
38
  try:
50
39
  return to_str(value, **self.validation_kwargs)
51
40
  except Exception as e:
lionagi/core/rule/util.py CHANGED
@@ -1,35 +0,0 @@
1
- # from lionagi.libs.ln_convert import is_same_dtype
2
- # from collections.abc import Mapping, Generator
3
-
4
-
5
- # def validate_keys(keys):
6
- # """
7
- # choices can be provided from various sources:
8
- # - mapping such as dict, their keys will be used as choices
9
- # - iterables including list, tuple, set, generator, enum, etc.
10
- # - strings, comma separated values
11
- # """
12
-
13
- # try:
14
- # if isinstance(keys, Mapping):
15
- # keys = list(keys.keys())
16
-
17
- # elif isinstance(keys, (list, tuple, set, Generator)):
18
- # keys = set(keys)
19
-
20
- # elif isinstance(keys, str):
21
- # if "," in keys:
22
- # keys = list({i.strip() for i in keys.split(",")})
23
- # else:
24
- # keys = [keys.strip()]
25
-
26
- # else:
27
- # keys = [i.value for i in keys]
28
-
29
- # except Exception as e:
30
- # raise ValueError(f"invalid choices {keys}") from e
31
-
32
- # if not is_same_dtype(keys):
33
- # raise ValueError(f"choices must be of the same type, got {keys}")
34
-
35
- # return keys
@@ -1,44 +1,28 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from typing import Any
18
- from lionagi.libs.ln_convert import is_same_dtype, to_df
19
- from lionagi.core.collections.abc import Field
2
+
3
+ from lionagi.core.action import Tool, ToolManager
20
4
  from lionagi.core.collections import (
21
- pile,
22
- progression,
5
+ Exchange,
23
6
  Pile,
24
7
  Progression,
25
8
  iModel,
26
- Exchange,
9
+ pile,
10
+ progression,
27
11
  )
12
+ from lionagi.core.collections.abc import Field
28
13
  from lionagi.core.generic.node import Node
29
- from lionagi.core.action import Tool, ToolManager
30
14
  from lionagi.core.mail import Mail, Package
31
15
  from lionagi.core.message import (
32
- create_message,
33
- System,
34
- Instruction,
35
- AssistantResponse,
36
16
  ActionRequest,
37
17
  ActionResponse,
18
+ AssistantResponse,
19
+ Instruction,
38
20
  RoledMessage,
21
+ System,
22
+ create_message,
39
23
  )
40
-
41
24
  from lionagi.core.session.directive_mixin import DirectiveMixin
25
+ from lionagi.libs.ln_convert import is_same_dtype, to_df
42
26
 
43
27
 
44
28
  class Branch(Node, DirectiveMixin):
@@ -1,22 +1,7 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  # lionagi/core/session/directive_mixin.py
18
2
 
19
3
  from lionagi.core.unit import Unit
4
+
20
5
  from ..message.action_response import ActionResponse
21
6
 
22
7
 
@@ -1,36 +1,20 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
1
+ from typing import Any
16
2
 
3
+ from lionagi.core.action.tool_manager import ToolManager
17
4
  from lionagi.core.collections import (
5
+ Exchange,
18
6
  Pile,
19
7
  Progression,
20
- progression,
21
- pile,
22
8
  iModel,
9
+ pile,
10
+ progression,
23
11
  )
24
- from lionagi.core.message import System
25
- from typing import Any
26
- from lionagi.core.action.tool_manager import ToolManager
27
-
28
- from lionagi.libs import SysUtil
29
- from lionagi.core.session.branch import Branch
30
- from lionagi.core.collections import pile, Pile, Exchange
31
12
  from lionagi.core.collections.abc import get_lion_id
32
13
  from lionagi.core.collections.util import to_list_type
33
14
  from lionagi.core.mail.mail_manager import MailManager
15
+ from lionagi.core.message import System
16
+ from lionagi.core.session.branch import Branch
17
+ from lionagi.libs import SysUtil
34
18
 
35
19
 
36
20
  class Session:
@@ -1,5 +1,4 @@
1
- from .unit_form import UnitForm
2
1
  from .unit import Unit
3
-
2
+ from .unit_form import UnitForm
4
3
 
5
4
  __all__ = ["UnitForm", "Unit"]
@@ -1,27 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from lionagi.libs.ln_func_call import rcall, pcall
18
- from lionagi.libs import convert, AsyncUtil
19
-
20
- from lionagi.core.collections.abc import Directive
21
1
  from lionagi.core.collections import iModel
22
- from lionagi.core.validator.validator import Validator
2
+ from lionagi.core.collections.abc import Directive
23
3
  from lionagi.core.session.branch import Branch
24
4
  from lionagi.core.unit.util import retry_kwargs
5
+ from lionagi.core.validator.validator import Validator
6
+ from lionagi.libs import AsyncUtil, convert
7
+ from lionagi.libs.ln_func_call import rcall
25
8
 
26
9
 
27
10
  class ParallelUnit(Directive):
@@ -1,19 +1,3 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from .base import BaseUnitForm, Field
18
2
 
19
3
 
@@ -1,19 +1,3 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from lionagi.core.collections.abc import Field
18
2
  from lionagi.core.report.form import Form
19
3
 
@@ -1,20 +1,5 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from lionagi.libs.ln_convert import to_str
2
+
18
3
  from .base import BaseUnitForm, Field
19
4
 
20
5
 
@@ -1,19 +1,3 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from .base import BaseUnitForm, Field
18
2
 
19
3
 
@@ -1,22 +1,6 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from lionagi.libs.ln_convert import to_str
18
1
  from lionagi.core.collections.abc import Field
19
2
  from lionagi.core.unit import UnitForm
3
+ from lionagi.libs.ln_convert import to_str
20
4
 
21
5
 
22
6
  class ScoreTemplate(UnitForm):
@@ -1,20 +1,5 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from enum import Enum
2
+
18
3
  from .base import BaseUnitForm, Field
19
4
 
20
5
 
lionagi/core/unit/unit.py CHANGED
@@ -1,25 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from typing import Callable
18
- from lionagi.libs.ln_convert import strip_lower
19
- from lionagi.libs.ln_func_call import rcall
2
+
3
+ from lionagi.core.collections import iModel
20
4
  from lionagi.core.collections.abc import Directive
21
5
  from lionagi.core.validator.validator import Validator
22
- from lionagi.core.collections import iModel
6
+ from lionagi.libs.ln_func_call import rcall
7
+
23
8
  from .unit_form import UnitForm
24
9
  from .unit_mixin import DirectiveMixin
25
10
  from .util import retry_kwargs
@@ -361,8 +346,8 @@ class Unit(Directive, DirectiveMixin):
361
346
  if system:
362
347
  branch.add_message(system=system)
363
348
 
364
- if hasattr(self, strip_lower(directive)):
365
- directive = getattr(self, strip_lower(directive))
349
+ if hasattr(self, str(directive).strip().lower()):
350
+ directive = getattr(self, str(directive).strip().lower())
366
351
 
367
352
  verbose = verbose if verbose is not None else self.verbose
368
353
  if verbose:
@@ -1,22 +1,9 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
1
+ from enum import Enum
9
2
 
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
3
+ from lionfuncs import to_dict
16
4
 
17
- from enum import Enum
18
- from lionagi.libs.ln_convert import to_str, to_dict
19
5
  from lionagi.core.collections.abc import Field
6
+
20
7
  from .template.base import BaseUnitForm
21
8
 
22
9
 
@@ -192,8 +179,8 @@ class UnitForm(BaseUnitForm):
192
179
 
193
180
  self.task = (
194
181
  f"Follow the prompt and provide the necessary output.\n"
195
- f"- Additional instruction: {to_str(instruction or 'N/A')}\n"
196
- f"- Additional context: {to_str(context or 'N/A')}\n"
182
+ f"- Additional instruction: {str(instruction or 'N/A')}\n"
183
+ f"- Additional context: {str(context or 'N/A')}\n"
197
184
  )
198
185
 
199
186
  if reason:
@@ -272,7 +259,7 @@ class UnitForm(BaseUnitForm):
272
259
  fields["task"] = fields["task"][:2000] + "..."
273
260
 
274
261
  if "tool_schema" in fields:
275
- tools = to_dict(fields["tool_schema"])["tools"]
262
+ tools = to_dict(fields["tool_schema"], fuzzy_parse=True)["tools"]
276
263
  fields["available_tools"] = [i["function"]["name"] for i in tools]
277
264
  fields.pop("tool_schema")
278
265