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.
- 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 +7 -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.8.dist-info/METADATA +66 -0
- lionagi-0.2.8.dist-info/RECORD +267 -0
- {lionagi-0.2.7.dist-info → lionagi-0.2.8.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.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,
|
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
|
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
|
|
lionagi/core/rule/boolean.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from typing import Any
|
2
|
-
|
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 =
|
49
|
+
value = str(value).strip().lower()
|
50
50
|
if value in ["true", "1", "correct", "yes"]:
|
51
51
|
return True
|
52
52
|
|
lionagi/core/rule/choice.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
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
|
48
|
+
return choose_most_similar(value, self.keys)
|
lionagi/core/rule/mapping.py
CHANGED
@@ -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
|
20
|
-
|
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
|
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
|
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
|
|
lionagi/core/rule/number.py
CHANGED
lionagi/core/rule/rulebook.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
from
|
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
|
lionagi/core/rule/string.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
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
|
lionagi/core/session/branch.py
CHANGED
@@ -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
|
-
|
19
|
-
from lionagi.core.
|
2
|
+
|
3
|
+
from lionagi.core.action import Tool, ToolManager
|
20
4
|
from lionagi.core.collections import (
|
21
|
-
|
22
|
-
progression,
|
5
|
+
Exchange,
|
23
6
|
Pile,
|
24
7
|
Progression,
|
25
8
|
iModel,
|
26
|
-
|
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
|
|
lionagi/core/session/session.py
CHANGED
@@ -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:
|
lionagi/core/unit/__init__.py
CHANGED
@@ -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.
|
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
|
-
|
19
|
-
from lionagi.
|
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.
|
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,
|
365
|
-
directive = getattr(self,
|
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:
|
lionagi/core/unit/unit_form.py
CHANGED
@@ -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
|
-
|
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: {
|
196
|
-
f"- Additional context: {
|
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
|
|