lionagi 0.2.7__py3-none-any.whl → 0.2.9__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 +6 -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.9.dist-info/METADATA +68 -0
  167. lionagi-0.2.9.dist-info/RECORD +267 -0
  168. {lionagi-0.2.7.dist-info → lionagi-0.2.9.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.9.dist-info}/LICENSE +0 -0
@@ -1,37 +1,17 @@
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
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
14
- """
15
-
16
- """
17
- The base directive module.
18
- """
19
-
20
1
  import asyncio
21
2
  import contextlib
22
3
  import re
23
4
  from abc import ABC
24
-
25
5
  from typing import Any, Optional
26
6
 
27
- from lionagi.libs import ParseUtil, StringMatch, to_list
28
- from lionagi.libs.ln_nested import nmerge
7
+ from lionfuncs import extract_json_block, to_dict, validate_mapping
8
+
29
9
  from lionagi.core.collections.abc import ActionError
30
10
  from lionagi.core.message import ActionRequest, ActionResponse, Instruction
31
11
  from lionagi.core.message.util import _parse_action_request
32
12
  from lionagi.core.report.form import Form
33
13
  from lionagi.core.unit.util import process_tools
34
- from lionagi.core.validator.validator import Validator
14
+ from lionagi.libs.ln_nested import nmerge
35
15
 
36
16
 
37
17
  class DirectiveMixin(ABC):
@@ -868,7 +848,7 @@ class DirectiveMixin(ABC):
868
848
 
869
849
  if plan:
870
850
  keys = [f"step_{i+1}" for i in range(len(plan))]
871
- plan = StringMatch.force_validate_dict(plan, keys)
851
+ plan = validate_mapping(plan, keys, handle_unmatched="force")
872
852
 
873
853
  # If plan is provided, process each step
874
854
  for i in keys:
@@ -904,7 +884,7 @@ class DirectiveMixin(ABC):
904
884
  return form
905
885
 
906
886
  keys = [f"action_{i+1}" for i in range(len(actions))]
907
- actions = StringMatch.force_validate_dict(actions, keys)
887
+ actions = validate_mapping(actions, keys, handle_unmatched="force")
908
888
 
909
889
  try:
910
890
  requests = []
@@ -1149,18 +1129,20 @@ class DirectiveMixin(ABC):
1149
1129
 
1150
1130
  if requested_fields:
1151
1131
  with contextlib.suppress(Exception):
1152
- return StringMatch.force_validate_dict(out_, requested_fields)
1132
+ return validate_mapping(
1133
+ out_, requested_fields, handle_unmatched="force"
1134
+ )
1153
1135
 
1154
1136
  if isinstance(out_, str):
1155
1137
  with contextlib.suppress(Exception):
1156
- return ParseUtil.fuzzy_parse_json(out_)
1138
+ return to_dict(out_, fuzzy_parse=True)
1157
1139
 
1158
1140
  with contextlib.suppress(Exception):
1159
- return ParseUtil.extract_json_block(out_)
1141
+ return extract_json_block(out_)
1160
1142
 
1161
1143
  with contextlib.suppress(Exception):
1162
1144
  match = re.search(r"```json\n({.*?})\n```", out_, re.DOTALL)
1163
1145
  if match:
1164
- return ParseUtil.fuzzy_parse_json(match.group(1))
1146
+ return to_dict(match.group(1), fuzzy_parse=True)
1165
1147
 
1166
1148
  return out_
lionagi/core/unit/util.py CHANGED
@@ -22,6 +22,7 @@ choices_fields = ["index", "message", "logprobs", "finish_reason"]
22
22
  usage_fields = ["prompt_tokens", "completion_tokens", "total_tokens"]
23
23
 
24
24
  from typing import Callable
25
+
25
26
  from lionagi.core.action.tool import Tool
26
27
  from lionagi.core.action.tool_manager import func_to_tool
27
28
 
@@ -1,30 +1,16 @@
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
+ import asyncio
2
+ from typing import Any, Callable, Dict, List, Union
9
3
 
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
- """
4
+ from lionfuncs import lcall
16
5
 
17
- import asyncio
18
- from typing import Any, Dict, List, Union, Callable
19
- from lionagi.libs import SysUtil
20
- from lionagi.libs.ln_func_call import lcall
21
6
  from lionagi.core.collections.abc import FieldError
22
- from lionagi.core.collections.model import iModel
23
- from ..rule.base import Rule
24
- from ..rule._default import DEFAULT_RULES
25
- from ..rule.rulebook import RuleBook
7
+ from lionagi.libs import SysUtil
8
+
26
9
  from ..report.form import Form
27
10
  from ..report.report import Report
11
+ from ..rule._default import DEFAULT_RULES
12
+ from ..rule.base import Rule
13
+ from ..rule.rulebook import RuleBook
28
14
 
29
15
  _DEFAULT_RULEORDER = [
30
16
  "choice",
lionagi/core/work/work.py CHANGED
@@ -1,26 +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
-
1
+ from collections.abc import Coroutine
17
2
  from enum import Enum
18
- import asyncio
19
3
  from typing import Any
20
- from collections.abc import Coroutine
21
4
 
22
- from lionagi.libs import SysUtil
23
5
  from lionagi.core.collections.abc import Component
6
+ from lionagi.libs import SysUtil
24
7
 
25
8
 
26
9
  class WorkStatus(str, Enum):
@@ -1,10 +1,10 @@
1
+ import inspect
1
2
  from typing import Callable
3
+
2
4
  from pydantic import Field, field_validator
3
- import inspect
4
5
 
5
- from lionagi.core.generic.edge import Edge
6
6
  from lionagi.core.collections.abc.concepts import Progressable
7
-
7
+ from lionagi.core.generic.edge import Edge
8
8
  from lionagi.core.work.worker import Worker
9
9
 
10
10
 
@@ -1,24 +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
  import asyncio
18
- import logging
19
2
 
20
- from lionagi.libs.ln_func_call import rcall
21
3
  from lionagi.core.work.worklog import WorkLog
4
+ from lionagi.libs.ln_func_call import rcall
22
5
 
23
6
 
24
7
  class WorkFunction:
@@ -1,10 +1,5 @@
1
- from pydantic import Field
2
- import asyncio
3
-
4
1
  from lionagi.core.generic.node import Node
5
2
  from lionagi.core.work.work_function import WorkFunction
6
- from lionagi.core.collections import Exchange
7
- from lionagi.core.mail.mail import Mail
8
3
 
9
4
 
10
5
  class WorkFunctionNode(WorkFunction, Node):
@@ -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
  import asyncio
2
+
18
3
  from lionagi.core.work.work import WorkStatus
19
4
 
20
5
 
@@ -1,10 +1,10 @@
1
1
  import inspect
2
- from typing import Any, Callable
3
- from pydantic import Field, field_validator, model_validator
2
+ from typing import Callable
3
+
4
+ from pydantic import Field, field_validator
4
5
 
5
6
  from lionagi.core.collections.abc.component import Component
6
- from lionagi.core.work.work import WorkStatus, Work
7
- from collections.abc import Coroutine
7
+ from lionagi.core.work.work import Work, WorkStatus
8
8
 
9
9
 
10
10
  class WorkTask(Component):
@@ -1,27 +1,12 @@
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
-
1
+ import inspect
17
2
  from abc import ABC
18
3
  from functools import wraps
19
- import inspect
4
+
20
5
  from lionagi import logging as _logging
21
- from lionagi.core.work.work_function import WorkFunction
22
- from lionagi.core.work.work import Work
23
- from lionagi.core.report.form import Form
24
6
  from lionagi.core.collections.abc import get_lion_id
7
+ from lionagi.core.report.form import Form
8
+ from lionagi.core.work.work import Work
9
+ from lionagi.core.work.work_function import WorkFunction
25
10
 
26
11
 
27
12
  class Worker(ABC):
@@ -1,12 +1,12 @@
1
1
  import asyncio
2
- from lionagi.core.work.work import WorkStatus
3
- from lionagi.core.work.worker import Worker
4
- from lionagi.core.work.work_task import WorkTask
5
- from lionagi.core.work.work_edge import WorkEdge
6
- from lionagi.core.work.work_function_node import WorkFunctionNode
7
2
 
8
3
  from lionagi.core.collections.pile import pile
9
4
  from lionagi.core.generic.graph import Graph
5
+ from lionagi.core.work.work import WorkStatus
6
+ from lionagi.core.work.work_edge import WorkEdge
7
+ from lionagi.core.work.work_function_node import WorkFunctionNode
8
+ from lionagi.core.work.work_task import WorkTask
9
+ from lionagi.core.work.worker import Worker
10
10
 
11
11
 
12
12
  class WorkerEngine:
@@ -1,21 +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
-
1
+ from lionagi.core.collections import Pile, pile, progression
17
2
  from lionagi.core.collections.abc import Progressable
18
- from lionagi.core.collections import pile, progression, Pile
19
3
  from lionagi.core.work.work import Work, WorkStatus
20
4
  from lionagi.core.work.work_queue import WorkQueue
21
5
 
@@ -1,4 +1,5 @@
1
1
  from abc import ABC
2
+
2
3
  from lionagi.core.collections import iModel
3
4
 
4
5
 
@@ -1,11 +1,14 @@
1
1
  import asyncio
2
- from lionagi import alcall
3
- from lionagi.libs.ln_convert import to_list
2
+ from time import time
3
+
4
4
  import numpy as np
5
+
6
+ from lionagi import alcall
5
7
  from lionagi.core.collections import iModel
6
- from .base import TokenCompressor
8
+ from lionagi.libs.ln_convert import to_list
7
9
  from lionagi.libs.ln_tokenize import TokenizeUtil
8
- from time import time
10
+
11
+ from .base import TokenCompressor
9
12
 
10
13
  # inspired by LLMLingua, MIT License, Copyright (c) Microsoft Corporation.
11
14
  # https://github.com/microsoft/LLMLingua
@@ -0,0 +1 @@
1
+ TODO
@@ -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
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 List, Optional
18
2
 
19
3
  from lionagi.experimental.directive.tokenizer import BaseToken
20
- from ..template.schema import IfNode, TryNode, ForNode
4
+
5
+ from ..template.schema import ForNode, IfNode, TryNode
21
6
 
22
7
 
23
8
  class BaseDirectiveParser:
@@ -0,0 +1,200 @@
1
+
2
+ """
3
+ # basic syntax
4
+ executeAction(param1, param2) IF condition1 && condition2 || !condition3;
5
+
6
+ # verb
7
+ DO
8
+
9
+ # logic operator
10
+
11
+ AND: &&
12
+ OR: ||
13
+ NOT: !
14
+ GREATER_THAN: >
15
+ LESS_THAN: <
16
+ GREATER_THAN_OR_EQUAL: >=
17
+ LESS_THAN_OR_EQUAL: <=
18
+ EQUAL: ==
19
+ NOT_EQUAL: !=
20
+
21
+ # conditions
22
+ IF
23
+ ELIF
24
+ ELSE
25
+
26
+ # loop
27
+ FOR
28
+ IN
29
+
30
+ # EXCEPTION
31
+ TRY
32
+ EXCEPT
33
+
34
+ """
35
+
36
+ """
37
+ DO: perform a single action
38
+ THEN: extend directive to include more statment
39
+ IF: condition
40
+
41
+ FOR
42
+ IN
43
+ END
44
+ BEGIN
45
+
46
+ TRY
47
+ EXCEPT
48
+
49
+ ---
50
+
51
+ tools 1,2,3
52
+
53
+
54
+
55
+ def main(): <-> compose
56
+
57
+ If condition1 && condition2 || !condition3;
58
+ DO tool1(param1, param2);
59
+ ENDIF;
60
+
61
+ IF must follow condition, (condition parsing logic);
62
+ DO ....;
63
+ ENDIF;
64
+
65
+
66
+
67
+
68
+ THEN;
69
+ DO tool2(param1, param2);
70
+
71
+ THEN;
72
+
73
+ TRY; DO ACTION_C;
74
+ EXCEPT; DO ACTION_D;
75
+ ENDEXCEPT;
76
+ ENDTRY;
77
+
78
+ RETURN <-> run
79
+
80
+
81
+
82
+
83
+ COMPOSE; - indicate the beginning of a script-like block to execute
84
+
85
+ THEN; - indicate continuation of a script-like block, another statement to execute
86
+
87
+ RUN; - indicate the end of script-like block, and let the script execute
88
+
89
+
90
+ XX; ; END XX;
91
+
92
+
93
+
94
+ TRY; DO ACTION_A; END TRY;
95
+
96
+
97
+
98
+ COMPOSE;
99
+
100
+ IF CONDITION_A; DO ACTION_B; ELIF CONDITION_C; DO ACTION_D; ELSE; DO ACTION_E; ENDIF;
101
+
102
+ THEN TRY; DO ACTION_C; EXCEPT; DO ACTION_D; ENDEXCEPT; ENDTRY;
103
+
104
+
105
+ THEN TRY; DO ACTION_C ENDTRY;
106
+
107
+
108
+
109
+ THEN IF EXCEPT; IF CONDITION_C; DO ACTION_D; ENDEXCEPT
110
+
111
+ ;
112
+ THEN FOR ITEM IN COLLECTION; DO ACTION_E(input_.param1, input_.param2); ENDFOR
113
+ RUN;
114
+
115
+
116
+
117
+ DO ACTION B;
118
+
119
+ IF
120
+ THEN
121
+
122
+ GROUP
123
+
124
+ """
125
+
126
+ """syntax:
127
+
128
+
129
+ BEGIN; IF condition1 && condition2 || !condition3; THEN DO action(param1, param2); END IF; END;
130
+
131
+ BEGIN; FOR input_ IN nested_structure; DO action(input_.param1, input_.param2); END FOR; END;
132
+
133
+ BEGIN; DO action1(param1, param2); DO action2(param3, param4); END GROUP; END;
134
+
135
+
136
+ """
137
+
138
+ """
139
+ FOR input_ IN nested_structure DO
140
+ executeAction(input_.param1, input_.param2);
141
+ END FOR;
142
+ """
143
+
144
+ """
145
+ example 1:
146
+
147
+ BEGIN; IF condition1 && condition2 || !condition3; DO action1(param1, param2); ENDIF;
148
+ FOR input_ IN collections DO action2(input_.param1, input_.param2); ENDFOR; END;
149
+
150
+
151
+ example 2:
152
+ BEGIN; IF condition1; TRY DO action1(param1, param2); EXCEPT DO action2(param3, param4);
153
+ ENDTRY; ELIF condition2; DO action2(param1, param2); ELSE DO action3(param1, param2);
154
+ ENDIF; END;
155
+
156
+ """
157
+
158
+ """
159
+ BEGIN
160
+ executeAction1(param1, param2);
161
+ IF condition2 THEN executeAction2(param3, param4);
162
+ FOR input_ IN nested_structure DO
163
+ executeAction3(input_.param1, input_.param2);
164
+ END FOR;
165
+ END;
166
+ """
167
+
168
+ """
169
+ TRY
170
+ executeAction(param1, param2);
171
+ EXCEPT
172
+ handleErrorAction(param1, param2);
173
+ """
174
+
175
+ """
176
+
177
+ CHAT / REACT
178
+
179
+
180
+ DO 1,2
181
+ session = Li.Session(..., tools=tools)
182
+ await alcall(session.branches, func_1)
183
+
184
+
185
+ THEN DO 3,4
186
+ session.chat.py(3,4)
187
+
188
+
189
+ THEN 5
190
+ session.chat.py(5)
191
+
192
+
193
+ call (1,2,3,4,5)
194
+
195
+ run 1,2,3,4,5
196
+
197
+
198
+ 1->2, or 1->3, or 1->4, THEN....
199
+
200
+ """
@@ -1,21 +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
- from typing import Any, Dict
18
1
  import re
2
+ from typing import Any, Dict
19
3
 
20
4
  from ..evaluator.base_evaluator import BaseEvaluator
21
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
  import re
18
2
 
19
3
 
@@ -0,0 +1 @@
1
+ TODO
@@ -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
  import ast
18
2
  import operator
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
1
  import ast
18
2
  import operator
19
- from typing import Any, Dict, Tuple, Callable
3
+ from typing import Any, Callable, Dict, Tuple
20
4
 
21
5
  from lionagi.libs.ln_convert import to_dict
22
6
 
@@ -1,5 +1,5 @@
1
- from ..collections.abc import Component, Field
2
1
  from ..collections import Pile, pile
2
+ from ..collections.abc import Component, Field
3
3
  from ..generic import Node
4
4
 
5
5