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.
- lionagi/__init__.py +11 -25
- lionagi/core/action/README.md +20 -0
- lionagi/core/action/__init__.py +1 -2
- lionagi/core/action/function_calling.py +2 -27
- lionagi/core/action/node.py +1 -16
- lionagi/core/action/tool.py +4 -17
- lionagi/core/action/tool_manager.py +8 -31
- lionagi/core/agent/README.md +1 -0
- lionagi/core/agent/base_agent.py +3 -27
- lionagi/core/agent/eval/README.md +1 -0
- lionagi/core/collections/README.md +23 -0
- lionagi/core/collections/__init__.py +2 -3
- lionagi/core/collections/_logger.py +0 -17
- lionagi/core/collections/abc/README.md +63 -0
- lionagi/core/collections/abc/__init__.py +18 -18
- lionagi/core/collections/abc/component.py +5 -21
- lionagi/core/collections/abc/concepts.py +1 -17
- lionagi/core/collections/abc/exceptions.py +0 -16
- lionagi/core/collections/exchange.py +1 -16
- lionagi/core/collections/flow.py +5 -25
- lionagi/core/collections/model.py +6 -21
- lionagi/core/collections/pile.py +317 -35
- lionagi/core/collections/progression.py +4 -17
- lionagi/core/collections/util.py +2 -2
- lionagi/core/director/README.md +1 -0
- lionagi/core/director/direct.py +1 -17
- lionagi/core/engine/branch_engine.py +6 -6
- lionagi/core/engine/instruction_map_engine.py +4 -4
- lionagi/core/engine/script_engine.py +2 -16
- lionagi/core/executor/base_executor.py +1 -1
- lionagi/core/executor/graph_executor.py +6 -9
- lionagi/core/executor/neo4j_executor.py +7 -9
- lionagi/core/generic/README.md +0 -0
- lionagi/core/generic/__init__.py +1 -2
- lionagi/core/generic/edge.py +7 -3
- lionagi/core/generic/edge_condition.py +3 -2
- lionagi/core/generic/graph.py +5 -6
- lionagi/core/generic/node.py +4 -4
- lionagi/core/generic/tree.py +2 -1
- lionagi/core/generic/tree_node.py +2 -0
- lionagi/core/mail/__init__.py +0 -1
- lionagi/core/mail/mail.py +2 -1
- lionagi/core/mail/mail_manager.py +8 -6
- lionagi/core/mail/package.py +2 -0
- lionagi/core/mail/start_mail.py +2 -2
- lionagi/core/message/__init__.py +4 -5
- lionagi/core/message/action_request.py +5 -31
- lionagi/core/message/action_response.py +3 -23
- lionagi/core/message/assistant_response.py +2 -17
- lionagi/core/message/instruction.py +2 -48
- lionagi/core/message/message.py +2 -17
- lionagi/core/message/system.py +2 -17
- lionagi/core/message/util.py +7 -26
- lionagi/core/report/base.py +4 -26
- lionagi/core/report/form.py +6 -28
- lionagi/core/report/report.py +3 -26
- lionagi/core/report/util.py +2 -17
- lionagi/core/rule/_default.py +3 -2
- lionagi/core/rule/action.py +4 -19
- lionagi/core/rule/base.py +4 -19
- lionagi/core/rule/boolean.py +2 -2
- lionagi/core/rule/choice.py +3 -2
- lionagi/core/rule/mapping.py +7 -21
- lionagi/core/rule/number.py +3 -1
- lionagi/core/rule/rulebook.py +2 -70
- lionagi/core/rule/string.py +2 -13
- lionagi/core/rule/util.py +0 -35
- lionagi/core/session/branch.py +11 -27
- lionagi/core/session/directive_mixin.py +1 -16
- lionagi/core/session/session.py +8 -24
- lionagi/core/unit/__init__.py +1 -2
- lionagi/core/unit/parallel_unit.py +4 -21
- lionagi/core/unit/template/action.py +0 -16
- lionagi/core/unit/template/base.py +0 -16
- lionagi/core/unit/template/plan.py +1 -16
- lionagi/core/unit/template/predict.py +0 -16
- lionagi/core/unit/template/score.py +1 -17
- lionagi/core/unit/template/select.py +1 -16
- lionagi/core/unit/unit.py +6 -21
- lionagi/core/unit/unit_form.py +6 -19
- lionagi/core/unit/unit_mixin.py +11 -29
- lionagi/core/unit/util.py +1 -0
- lionagi/core/validator/validator.py +8 -22
- lionagi/core/work/work.py +2 -19
- lionagi/core/work/work_edge.py +3 -3
- lionagi/core/work/work_function.py +1 -18
- lionagi/core/work/work_function_node.py +0 -5
- lionagi/core/work/work_queue.py +1 -16
- lionagi/core/work/work_task.py +4 -4
- lionagi/core/work/worker.py +5 -20
- lionagi/core/work/worker_engine.py +5 -5
- lionagi/core/work/worklog.py +1 -17
- lionagi/experimental/compressor/base.py +1 -0
- lionagi/experimental/compressor/llm_compressor.py +7 -4
- lionagi/experimental/directive/README.md +1 -0
- lionagi/experimental/directive/parser/base_parser.py +2 -17
- lionagi/experimental/directive/parser/base_syntax.txt +200 -0
- lionagi/experimental/directive/template/base_template.py +1 -17
- lionagi/experimental/directive/tokenizer.py +0 -16
- lionagi/experimental/evaluator/README.md +1 -0
- lionagi/experimental/evaluator/ast_evaluator.py +0 -16
- lionagi/experimental/evaluator/base_evaluator.py +1 -17
- lionagi/experimental/knowledge/base.py +1 -1
- lionagi/integrations/bridge/__init__.py +1 -1
- lionagi/integrations/bridge/langchain_/documents.py +1 -1
- lionagi/integrations/bridge/llamaindex_/node_parser.py +2 -1
- lionagi/integrations/bridge/llamaindex_/textnode.py +2 -1
- lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +1 -1
- lionagi/integrations/bridge/transformers_/install_.py +1 -0
- lionagi/integrations/chunker/chunk.py +5 -6
- lionagi/integrations/loader/load.py +3 -3
- lionagi/integrations/loader/load_util.py +2 -2
- lionagi/integrations/provider/__init__.py +0 -1
- lionagi/integrations/provider/_mapping.py +6 -5
- lionagi/integrations/provider/mlx_service.py +4 -3
- lionagi/integrations/provider/oai.py +1 -17
- lionagi/integrations/provider/ollama.py +1 -1
- lionagi/integrations/provider/openrouter.py +1 -0
- lionagi/integrations/provider/transformers.py +2 -2
- lionagi/integrations/storage/neo4j.py +1 -1
- lionagi/integrations/storage/storage_util.py +3 -4
- lionagi/integrations/storage/structure_excel.py +5 -4
- lionagi/integrations/storage/to_csv.py +3 -2
- lionagi/integrations/storage/to_excel.py +2 -2
- lionagi/libs/__init__.py +15 -19
- lionagi/libs/ln_api.py +9 -26
- lionagi/libs/ln_async.py +3 -2
- lionagi/libs/ln_convert.py +1 -18
- lionagi/libs/ln_func_call.py +3 -20
- lionagi/libs/ln_image.py +4 -1
- lionagi/libs/ln_knowledge_graph.py +5 -2
- lionagi/libs/ln_nested.py +2 -18
- lionagi/libs/ln_parse.py +4 -19
- lionagi/libs/ln_queue.py +2 -17
- lionagi/libs/ln_tokenize.py +3 -1
- lionagi/libs/ln_validate.py +2 -18
- lionagi/libs/sys_util.py +0 -16
- lionagi/lions/coder/code_form.py +3 -1
- lionagi/lions/coder/coder.py +1 -1
- lionagi/lions/coder/util.py +3 -2
- lionagi/lions/researcher/data_source/finhub_.py +1 -0
- lionagi/lions/researcher/data_source/google_.py +2 -2
- lionagi/lions/researcher/data_source/wiki_.py +1 -1
- lionagi/tests/libs/test_api.py +2 -1
- lionagi/tests/libs/test_convert.py +2 -1
- lionagi/tests/libs/test_field_validators.py +9 -8
- lionagi/tests/libs/test_func_call.py +2 -2
- lionagi/tests/libs/test_nested.py +1 -0
- lionagi/tests/libs/test_queue.py +1 -0
- lionagi/tests/libs/test_sys_util.py +4 -4
- lionagi/tests/test_core/collections/test_component.py +6 -4
- lionagi/tests/test_core/collections/test_exchange.py +2 -1
- lionagi/tests/test_core/collections/test_flow.py +2 -1
- lionagi/tests/test_core/collections/test_pile.py +3 -2
- lionagi/tests/test_core/collections/test_progression.py +3 -2
- lionagi/tests/test_core/generic/test_edge.py +4 -2
- lionagi/tests/test_core/generic/test_graph.py +3 -2
- lionagi/tests/test_core/generic/test_node.py +2 -1
- lionagi/tests/test_core/generic/test_tree_node.py +2 -1
- lionagi/tests/test_core/mail/test_mail.py +2 -1
- lionagi/tests/test_core/test_branch.py +3 -2
- lionagi/tests/test_core/test_form.py +1 -0
- lionagi/tests/test_core/test_report.py +1 -0
- lionagi/tests/test_core/test_validator.py +4 -3
- lionagi/version.py +1 -1
- lionagi-0.2.9.dist-info/METADATA +68 -0
- lionagi-0.2.9.dist-info/RECORD +267 -0
- {lionagi-0.2.7.dist-info → lionagi-0.2.9.dist-info}/WHEEL +1 -2
- lionagi-0.2.7.dist-info/METADATA +0 -277
- lionagi-0.2.7.dist-info/RECORD +0 -258
- lionagi-0.2.7.dist-info/top_level.txt +0 -1
- {lionagi-0.2.7.dist-info → lionagi-0.2.9.dist-info}/LICENSE +0 -0
lionagi/core/unit/unit_mixin.py
CHANGED
@@ -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
|
28
|
-
|
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.
|
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 =
|
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 =
|
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
|
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
|
1138
|
+
return to_dict(out_, fuzzy_parse=True)
|
1157
1139
|
|
1158
1140
|
with contextlib.suppress(Exception):
|
1159
|
-
return
|
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
|
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
|
-
|
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
|
-
|
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.
|
23
|
-
|
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):
|
lionagi/core/work/work_edge.py
CHANGED
@@ -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):
|
lionagi/core/work/work_queue.py
CHANGED
@@ -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
|
|
lionagi/core/work/work_task.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import inspect
|
2
|
-
from typing import
|
3
|
-
|
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
|
7
|
-
from collections.abc import Coroutine
|
7
|
+
from lionagi.core.work.work import Work, WorkStatus
|
8
8
|
|
9
9
|
|
10
10
|
class WorkTask(Component):
|
lionagi/core/work/worker.py
CHANGED
@@ -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
|
-
|
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:
|
lionagi/core/work/worklog.py
CHANGED
@@ -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,11 +1,14 @@
|
|
1
1
|
import asyncio
|
2
|
-
from
|
3
|
-
|
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 .
|
8
|
+
from lionagi.libs.ln_convert import to_list
|
7
9
|
from lionagi.libs.ln_tokenize import TokenizeUtil
|
8
|
-
|
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
|
-
|
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
|
3
|
+
from typing import Any, Callable, Dict, Tuple
|
20
4
|
|
21
5
|
from lionagi.libs.ln_convert import to_dict
|
22
6
|
|