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
@@ -2,18 +2,17 @@ import contextlib
2
2
  from collections import deque
3
3
  from typing import Any
4
4
 
5
- from lionagi.libs.ln_convert import to_list
5
+ from lionagi.core.collections import Pile, pile
6
6
  from lionagi.core.collections.abc import (
7
- Condition,
8
7
  Actionable,
9
- LionTypeError,
8
+ Condition,
10
9
  ItemNotFoundError,
11
10
  LionIDable,
11
+ LionTypeError,
12
12
  )
13
- from lionagi.core.collections import pile, Pile
14
-
15
13
  from lionagi.core.generic.edge import Edge
16
14
  from lionagi.core.generic.node import Node
15
+ from lionagi.libs.ln_convert import to_list
17
16
 
18
17
 
19
18
  class Graph(Node):
@@ -211,8 +210,8 @@ class Graph(Node):
211
210
  SysUtil.check_import("networkx")
212
211
  SysUtil.check_import("matplotlib", "pyplot")
213
212
 
214
- import networkx as nx
215
213
  import matplotlib.pyplot as plt
214
+ import networkx as nx
216
215
 
217
216
  g = self.to_networkx(**kwargs)
218
217
  pos = nx.spring_layout(g)
@@ -8,12 +8,12 @@ Includes functionality for managing relationships, such as adding,
8
8
  modifying, and removing edges, and querying related nodes and connections.
9
9
  """
10
10
 
11
- from pydantic import Field
12
- from pandas import Series
13
11
  from typing import Callable
14
12
 
15
- from lionagi.libs.ln_convert import to_list
13
+ from pandas import Series
14
+ from pydantic import Field
16
15
 
16
+ from lionagi.core.collections import Pile, pile
17
17
  from lionagi.core.collections.abc import (
18
18
  Component,
19
19
  Condition,
@@ -21,8 +21,8 @@ from lionagi.core.collections.abc import (
21
21
  RelationError,
22
22
  get_lion_id,
23
23
  )
24
- from lionagi.core.collections import pile, Pile
25
24
  from lionagi.core.generic.edge import Edge
25
+ from lionagi.libs.ln_convert import to_list
26
26
 
27
27
 
28
28
  class Node(Component, Relatable):
@@ -1,10 +1,11 @@
1
1
  """This module provides tree structure."""
2
2
 
3
3
  from pydantic import Field
4
+
4
5
  from lionagi.core.collections.abc import Condition
5
6
  from lionagi.core.collections.util import to_list_type
6
- from lionagi.core.generic.tree_node import TreeNode
7
7
  from lionagi.core.generic.graph import Graph
8
+ from lionagi.core.generic.tree_node import TreeNode
8
9
 
9
10
 
10
11
  class Tree(Graph):
@@ -1,5 +1,7 @@
1
1
  from enum import Enum
2
+
2
3
  from pydantic import Field
4
+
3
5
  from lionagi.core.collections.abc import Condition
4
6
  from lionagi.core.collections.util import to_list_type
5
7
  from lionagi.core.generic.node import Node
@@ -3,7 +3,6 @@ from .mail_manager import MailManager
3
3
  from .package import Package
4
4
  from .start_mail import StartMail
5
5
 
6
-
7
6
  __all__ = [
8
7
  "Mail",
9
8
  "MailManager",
lionagi/core/mail/mail.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from lionagi.core.collections.abc import Element, Field, Sendable
2
- from .package import PackageCategory, Package
2
+
3
+ from .package import Package, PackageCategory
3
4
 
4
5
 
5
6
  class Mail(Element, Sendable):
@@ -1,11 +1,13 @@
1
+ import asyncio
1
2
  from collections import deque
3
+
2
4
  from pydantic import Field
3
- from lionagi.libs import AsyncUtil
4
- from lionagi.core.collections.abc import Executable, Element
5
- from lionagi.core.collections import Exchange
6
- from lionagi.core.collections.util import to_list_type, get_lion_id
5
+
6
+ from lionagi.core.collections import Exchange, Pile, pile
7
+ from lionagi.core.collections.abc import Element, Executable
8
+ from lionagi.core.collections.util import get_lion_id, to_list_type
9
+
7
10
  from .mail import Mail, Package
8
- from lionagi.core.collections import Pile, pile
9
11
 
10
12
 
11
13
  class MailManager(Element, Executable):
@@ -178,4 +180,4 @@ class MailManager(Element, Executable):
178
180
  while not self.execute_stop:
179
181
  self.collect_all()
180
182
  self.send_all()
181
- await AsyncUtil.sleep(refresh_time)
183
+ await asyncio.sleep(refresh_time)
@@ -1,6 +1,8 @@
1
1
  from enum import Enum
2
2
  from typing import Any
3
+
3
4
  from pydantic import field_validator
5
+
4
6
  from lionagi.core.collections.abc import Element, Field
5
7
 
6
8
 
@@ -1,8 +1,8 @@
1
- from collections import deque
2
1
  from pydantic import Field
2
+
3
+ from lionagi.core.collections import Exchange
3
4
  from lionagi.core.generic.node import Node
4
5
  from lionagi.core.mail.mail import Mail, Package
5
- from lionagi.core.collections import Exchange
6
6
 
7
7
 
8
8
  class StartMail(Node):
@@ -1,12 +1,11 @@
1
- from .message import RoledMessage, MessageRole
2
- from .system import System
3
- from .instruction import Instruction
4
- from .assistant_response import AssistantResponse
5
1
  from .action_request import ActionRequest
6
2
  from .action_response import ActionResponse
3
+ from .assistant_response import AssistantResponse
4
+ from .instruction import Instruction
5
+ from .message import MessageRole, RoledMessage
6
+ from .system import System
7
7
  from .util import create_message
8
8
 
9
-
10
9
  __all__ = [
11
10
  "RoledMessage",
12
11
  "MessageRole",
@@ -1,23 +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
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
  import inspect
2
+
3
+ from lionfuncs import to_dict
18
4
  from pydantic import Field
19
- from lionagi.libs import convert, ParseUtil
20
- from .message import RoledMessage, MessageRole
5
+
6
+ from .message import MessageRole, RoledMessage
21
7
 
22
8
 
23
9
  class ActionRequest(RoledMessage):
@@ -111,21 +97,9 @@ class ActionRequest(RoledMessage):
111
97
 
112
98
 
113
99
  def _prepare_arguments(arguments):
114
- """
115
- Prepares the arguments for the action request.
116
-
117
- Args:
118
- arguments (Any): The arguments to be prepared.
119
-
120
- Returns:
121
- dict: The prepared arguments.
122
-
123
- Raises:
124
- ValueError: If the arguments are invalid.
125
- """
126
100
  if not isinstance(arguments, dict):
127
101
  try:
128
- arguments = ParseUtil.fuzzy_parse_json(convert.to_str(arguments))
102
+ arguments = to_dict(str(arguments), fuzzy_parse=True)
129
103
  except Exception as e:
130
104
  raise ValueError(f"Invalid arguments: {e}") from e
131
105
  if isinstance(arguments, dict):
@@ -1,23 +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
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
2
+
18
3
  from pydantic import Field
19
- from .message import RoledMessage, MessageRole
4
+
20
5
  from .action_request import ActionRequest
6
+ from .message import MessageRole, RoledMessage
21
7
 
22
8
 
23
9
  # action response must correlates to a specific action request
@@ -95,12 +81,6 @@ class ActionResponse(RoledMessage):
95
81
  action_request.action_response = self.ln_id
96
82
 
97
83
  def _to_dict(self):
98
- """
99
- Converts the action response to a dictionary.
100
-
101
- Returns:
102
- dict: A dictionary representation of the action response.
103
- """
104
84
  return {
105
85
  "function": self.function,
106
86
  "arguments": self.arguments,
@@ -1,21 +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
1
  from typing import Any
18
- from .message import RoledMessage, MessageRole
2
+
3
+ from .message import MessageRole, RoledMessage
19
4
 
20
5
 
21
6
  class AssistantResponse(RoledMessage):
@@ -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.core.collections.abc import LionIDable, SYSTEM_FIELDS
1
+ from lionagi.core.collections.abc import SYSTEM_FIELDS, LionIDable
2
+ from lionagi.core.message.message import MessageRole, RoledMessage
18
3
  from lionagi.core.report.form import Form
19
- from lionagi.core.message.message import RoledMessage, MessageRole
20
4
 
21
5
 
22
6
  class Instruction(RoledMessage):
@@ -108,13 +92,6 @@ class Instruction(RoledMessage):
108
92
  return text_msg
109
93
 
110
94
  def _add_context(self, context: dict | str | None = None, **kwargs):
111
- """
112
- Adds context to the instruction message.
113
-
114
- Args:
115
- context (dict or str, optional): Additional context to be added.
116
- **kwargs: Additional context fields to be added.
117
- """
118
95
  if "context" not in self.content:
119
96
  self.content["context"] = {}
120
97
  if isinstance(context, dict):
@@ -123,12 +100,6 @@ class Instruction(RoledMessage):
123
100
  self.content["context"]["additional_context"] = context
124
101
 
125
102
  def _update_requested_fields(self, requested_fields: dict):
126
- """
127
- Updates the requested fields in the instruction message.
128
-
129
- Args:
130
- requested_fields (dict): The fields requested in the instruction.
131
- """
132
103
  if "context" not in self.content:
133
104
  self.content["context"] = {}
134
105
  self.content["context"]["requested_fields"] = {}
@@ -137,14 +108,6 @@ class Instruction(RoledMessage):
137
108
  def _initiate_content(
138
109
  self, context, requested_fields, images, image_detail, **kwargs
139
110
  ):
140
- """
141
- Processes context and requested fields to update the message content.
142
-
143
- Args:
144
- context (dict or str, optional): Additional context for the instruction.
145
- requested_fields (dict, optional): Fields requested in the instruction.
146
- **kwargs: Additional context fields to be added.
147
- """
148
111
  if context:
149
112
  context = {"context": context} if not isinstance(context, dict) else context
150
113
  if (
@@ -188,15 +151,6 @@ class Instruction(RoledMessage):
188
151
 
189
152
  @staticmethod
190
153
  def _format_requested_fields(requested_fields):
191
- """
192
- Formats the requested fields into a JSON-parseable response format.
193
-
194
- Args:
195
- requested_fields (dict): The fields requested in the instruction.
196
-
197
- Returns:
198
- dict: The formatted requested fields.
199
- """
200
154
  format_ = f"""
201
155
  MUST RETURN JSON-PARSEABLE RESPONSE ENCLOSED BY JSON CODE BLOCKS. ----
202
156
  ```json
@@ -1,21 +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
1
  from enum import Enum
18
- from lionagi.core.collections.abc import Sendable, Field
2
+
3
+ from lionagi.core.collections.abc import Field, Sendable
19
4
  from lionagi.core.generic.node import Node
20
5
 
21
6
 
@@ -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
  from typing import Any
2
+
18
3
  from ..collections.abc import Field
19
- from .message import RoledMessage, MessageRole
4
+ from .message import MessageRole, RoledMessage
20
5
 
21
6
 
22
7
  class System(RoledMessage):
@@ -1,33 +1,14 @@
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
- import re
18
1
  import json
19
- import contextlib
2
+ import re
20
3
 
21
- from lionagi.libs import ParseUtil
22
- from lionagi.libs.ln_convert import strip_lower, to_dict
23
- from lionagi.libs.ln_nested import nget
4
+ from lionfuncs import nget, to_dict
24
5
 
25
- from .message import RoledMessage
26
- from .system import System
27
- from .instruction import Instruction
28
- from .assistant_response import AssistantResponse
29
6
  from .action_request import ActionRequest
30
7
  from .action_response import ActionResponse
8
+ from .assistant_response import AssistantResponse
9
+ from .instruction import Instruction
10
+ from .message import RoledMessage
11
+ from .system import System
31
12
 
32
13
 
33
14
  def create_message(
@@ -170,7 +151,7 @@ def _parse_action_request(response):
170
151
  message = to_dict(response) if not isinstance(response, dict) else response
171
152
  content_ = None
172
153
 
173
- if strip_lower(nget(message, ["content"])) == "none":
154
+ if str(nget(message, ["content"])).strip().lower() == "none":
174
155
  content_ = _handle_action_request(message)
175
156
 
176
157
  elif nget(message, ["content", "tool_uses"], None):
@@ -1,32 +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
- """
18
- This module defines the BaseForm class, a foundation for form handling in
19
- applications. It provides common functionalities for form operations like
20
- initialization, validation, and state management. Extend this class to
21
- implement specific form behaviors and configurations.
22
- """
23
-
24
- from abc import abstractmethod
25
- from typing import Any, List, Dict
26
1
  import contextlib
2
+ from abc import abstractmethod
3
+ from typing import Any, Dict, List
4
+
27
5
  from lionagi.core.collections.abc import Component, Field
6
+
28
7
  from ..collections.util import to_list_type
29
- from lionagi.libs.ln_convert import to_str
30
8
 
31
9
 
32
10
  class BaseForm(Component):
@@ -1,31 +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
- """
18
- This module extends the BaseForm class to implement the Form class, which
19
- dynamically manages form operations based on specific assignments. It provides
20
- functionalities for initializing fields, filling forms with data, and
21
- validating the readiness of forms for further processing.
22
- """
23
-
24
- from typing import Dict, Any
25
- from lionagi.libs.ln_convert import to_readable_dict
1
+ from typing import Any, Dict
2
+
3
+ from lionfuncs import as_readable_json
4
+
26
5
  from lionagi.core.collections.abc import SYSTEM_FIELDS
27
- from lionagi.core.report.util import get_input_output_fields
28
6
  from lionagi.core.report.base import BaseForm
7
+ from lionagi.core.report.util import get_input_output_fields
29
8
 
30
9
 
31
10
  class Form(BaseForm):
@@ -214,7 +193,7 @@ class Form(BaseForm):
214
193
  Args:
215
194
  fields (optional): Specific fields to display. Defaults to None.
216
195
  """
217
- from IPython.display import display, Markdown
196
+ from IPython.display import Markdown, display
218
197
 
219
198
  fields = fields or self.work_fields
220
199
 
@@ -224,7 +203,7 @@ class Form(BaseForm):
224
203
 
225
204
  for k, v in fields.items():
226
205
  if isinstance(v, dict):
227
- v = to_readable_dict(v)
206
+ v = as_readable_json(v)
228
207
  if len(str(v)) > 50:
229
208
  display(Markdown(f"**{k}**: \n {v}"))
230
209
  else:
@@ -1,33 +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
- """
18
- This module introduces the Report class, an extension of the BaseForm class
19
- designed to manage and synchronize a collection of Form instances based on
20
- specific assignments. The Report class handles the creation and updating of
21
- forms, ensuring each is properly configured according to the report's
22
- requirements.
23
- """
24
-
25
1
  from typing import Any, Type
26
- from lionagi.core.collections.abc import Field
2
+
27
3
  from lionagi.core.collections import Pile, pile
28
- from lionagi.core.report.util import get_input_output_fields
4
+ from lionagi.core.collections.abc import Field
29
5
  from lionagi.core.report.base import BaseForm
30
6
  from lionagi.core.report.form import Form
7
+ from lionagi.core.report.util import get_input_output_fields
31
8
 
32
9
 
33
10
  class Report(BaseForm):
@@ -1,19 +1,4 @@
1
- from lionagi.libs.ln_convert import strip_lower
2
-
3
-
4
1
  def get_input_output_fields(str_: str) -> list[list[str]]:
5
- """
6
- Parses an assignment string to extract input and output fields.
7
-
8
- Args:
9
- str_ (str): The assignment string in the format 'inputs -> outputs'.
10
-
11
- Returns:
12
- list[list[str]]: A list containing two lists - one for input fields and one for requested fields.
13
-
14
- Raises:
15
- ValueError: If the assignment string is None or if it does not contain '->' indicating invalid format.
16
- """
17
2
  if str_ is None:
18
3
  return [], []
19
4
 
@@ -22,7 +7,7 @@ def get_input_output_fields(str_: str) -> list[list[str]]:
22
7
 
23
8
  inputs, outputs = str_.split("->")
24
9
 
25
- input_fields = [strip_lower(i) for i in inputs.split(",")]
26
- requested_fields = [strip_lower(o) for o in outputs.split(",")]
10
+ input_fields = [str(i).strip().lower() for i in inputs.split(",")]
11
+ requested_fields = [str(o).strip().lower() for o in outputs.split(",")]
27
12
 
28
13
  return input_fields, requested_fields
@@ -1,10 +1,11 @@
1
1
  from enum import Enum
2
+
3
+ from .action import ActionRequestRule
4
+ from .boolean import BooleanRule
2
5
  from .choice import ChoiceRule
3
6
  from .mapping import MappingRule
4
7
  from .number import NumberRule
5
- from .boolean import BooleanRule
6
8
  from .string import StringRule
7
- from .action import ActionRequestRule
8
9
 
9
10
 
10
11
  class DEFAULT_RULES(Enum):
@@ -1,23 +1,8 @@
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, to_list
16
4
 
17
- from enum import Enum
18
5
  from lionagi.core.collections.abc import ActionError
19
- from lionagi.libs import ParseUtil
20
- from lionagi.libs.ln_convert import to_list, to_dict
21
6
  from lionagi.core.rule.mapping import MappingRule
22
7
 
23
8
 
@@ -83,10 +68,10 @@ class ActionRequestRule(MappingRule):
83
68
  """
84
69
  corrected = []
85
70
  if isinstance(value, str):
86
- value = ParseUtil.fuzzy_parse_json(value)
71
+ value = to_dict(value, fuzzy_parse=True)
87
72
 
88
73
  try:
89
- value = to_list(value)
74
+ value = to_list(value, dropna=True, flatten=True)
90
75
  for i in value:
91
76
  i = to_dict(i)
92
77
  if list(i.keys()) >= ["function", "arguments"]: