lionagi 0.0.306__py3-none-any.whl → 0.0.307__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +2 -5
- lionagi/core/__init__.py +7 -5
- lionagi/core/agent/__init__.py +3 -0
- lionagi/core/agent/base_agent.py +10 -12
- lionagi/core/branch/__init__.py +4 -0
- lionagi/core/branch/base_branch.py +81 -81
- lionagi/core/branch/branch.py +16 -28
- lionagi/core/branch/branch_flow_mixin.py +3 -7
- lionagi/core/branch/executable_branch.py +86 -56
- lionagi/core/branch/util.py +77 -162
- lionagi/core/{flow/direct → direct}/__init__.py +1 -1
- lionagi/core/{flow/direct/predict.py → direct/parallel_predict.py} +39 -17
- lionagi/core/direct/parallel_react.py +0 -0
- lionagi/core/direct/parallel_score.py +0 -0
- lionagi/core/direct/parallel_select.py +0 -0
- lionagi/core/direct/parallel_sentiment.py +0 -0
- lionagi/core/direct/predict.py +174 -0
- lionagi/core/{flow/direct → direct}/react.py +2 -2
- lionagi/core/{flow/direct → direct}/score.py +28 -23
- lionagi/core/{flow/direct → direct}/select.py +48 -45
- lionagi/core/direct/utils.py +83 -0
- lionagi/core/flow/monoflow/ReAct.py +6 -5
- lionagi/core/flow/monoflow/__init__.py +9 -0
- lionagi/core/flow/monoflow/chat.py +10 -10
- lionagi/core/flow/monoflow/chat_mixin.py +11 -10
- lionagi/core/flow/monoflow/followup.py +6 -5
- lionagi/core/flow/polyflow/__init__.py +1 -0
- lionagi/core/flow/polyflow/chat.py +15 -3
- lionagi/core/mail/mail_manager.py +18 -19
- lionagi/core/mail/schema.py +5 -4
- lionagi/core/messages/schema.py +18 -20
- lionagi/core/prompt/__init__.py +0 -0
- lionagi/core/prompt/prompt_template.py +0 -0
- lionagi/core/schema/__init__.py +2 -2
- lionagi/core/schema/action_node.py +11 -3
- lionagi/core/schema/base_mixin.py +56 -59
- lionagi/core/schema/base_node.py +35 -38
- lionagi/core/schema/condition.py +24 -0
- lionagi/core/schema/data_logger.py +96 -99
- lionagi/core/schema/data_node.py +19 -19
- lionagi/core/schema/prompt_template.py +0 -0
- lionagi/core/schema/structure.py +171 -169
- lionagi/core/session/__init__.py +1 -3
- lionagi/core/session/session.py +196 -214
- lionagi/core/tool/tool_manager.py +95 -103
- lionagi/integrations/__init__.py +1 -3
- lionagi/integrations/bridge/langchain_/documents.py +17 -18
- lionagi/integrations/bridge/langchain_/langchain_bridge.py +14 -14
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +22 -22
- lionagi/integrations/bridge/llamaindex_/node_parser.py +12 -12
- lionagi/integrations/bridge/llamaindex_/reader.py +11 -11
- lionagi/integrations/bridge/llamaindex_/textnode.py +7 -7
- lionagi/integrations/config/openrouter_configs.py +0 -1
- lionagi/integrations/provider/oai.py +26 -26
- lionagi/integrations/provider/services.py +38 -38
- lionagi/libs/__init__.py +34 -1
- lionagi/libs/ln_api.py +211 -221
- lionagi/libs/ln_async.py +53 -60
- lionagi/libs/ln_convert.py +118 -120
- lionagi/libs/ln_dataframe.py +32 -33
- lionagi/libs/ln_func_call.py +334 -342
- lionagi/libs/ln_nested.py +99 -107
- lionagi/libs/ln_parse.py +161 -165
- lionagi/libs/sys_util.py +52 -52
- lionagi/tests/test_core/test_session.py +254 -266
- lionagi/tests/test_core/test_session_base_util.py +299 -300
- lionagi/tests/test_core/test_tool_manager.py +70 -74
- lionagi/tests/test_libs/test_nested.py +2 -7
- lionagi/tests/test_libs/test_parse.py +2 -2
- lionagi/version.py +1 -1
- {lionagi-0.0.306.dist-info → lionagi-0.0.307.dist-info}/METADATA +4 -2
- lionagi-0.0.307.dist-info/RECORD +115 -0
- lionagi/core/flow/direct/utils.py +0 -43
- lionagi-0.0.306.dist-info/RECORD +0 -106
- /lionagi/core/{flow/direct → direct}/sentiment.py +0 -0
- {lionagi-0.0.306.dist-info → lionagi-0.0.307.dist-info}/LICENSE +0 -0
- {lionagi-0.0.306.dist-info → lionagi-0.0.307.dist-info}/WHEEL +0 -0
- {lionagi-0.0.306.dist-info → lionagi-0.0.307.dist-info}/top_level.txt +0 -0
@@ -1,13 +1,9 @@
|
|
1
1
|
from typing import Tuple, Any, TypeVar, Callable
|
2
2
|
|
3
3
|
import asyncio
|
4
|
-
from lionagi.core.schema.base_node import Tool, TOOL_TYPE
|
5
|
-
|
6
|
-
# from lionagi.libs.ln_async import AsyncUtil
|
7
|
-
from lionagi.libs.ln_parse import ParseUtil
|
8
|
-
from lionagi.libs import ln_convert as convert
|
9
|
-
from lionagi.libs import ln_func_call as func_call
|
10
4
|
|
5
|
+
from lionagi.libs import func_call, convert, ParseUtil
|
6
|
+
from lionagi.core.schema.base_node import Tool, TOOL_TYPE
|
11
7
|
|
12
8
|
T = TypeVar("T", bound=Tool)
|
13
9
|
|
@@ -21,7 +17,7 @@ class ToolManager:
|
|
21
17
|
calls.
|
22
18
|
|
23
19
|
Attributes:
|
24
|
-
|
20
|
+
registry (dict[str, Tool]): A dictionary to hold registered tools, keyed by their names.
|
25
21
|
"""
|
26
22
|
|
27
23
|
registry: dict = {}
|
@@ -31,12 +27,12 @@ class ToolManager:
|
|
31
27
|
Checks if a tool name already exists in the registry.
|
32
28
|
|
33
29
|
Args:
|
34
|
-
|
30
|
+
name (str): The name of the tool to check.
|
35
31
|
|
36
32
|
Returns:
|
37
|
-
|
33
|
+
bool: True if the name exists, False otherwise.
|
38
34
|
"""
|
39
|
-
return
|
35
|
+
return name in self.registry
|
40
36
|
|
41
37
|
@property
|
42
38
|
def has_tools(self):
|
@@ -47,10 +43,10 @@ class ToolManager:
|
|
47
43
|
Registers a tool in the registry. Raises a TypeError if the object is not an instance of Tool.
|
48
44
|
|
49
45
|
Args:
|
50
|
-
|
46
|
+
tool (Tool): The tool instance to register.
|
51
47
|
|
52
48
|
Raises:
|
53
|
-
|
49
|
+
TypeError: If the provided object is not an instance of Tool.
|
54
50
|
"""
|
55
51
|
if not isinstance(tool, Tool):
|
56
52
|
raise TypeError("Please register a Tool object.")
|
@@ -62,33 +58,32 @@ class ToolManager:
|
|
62
58
|
Invokes a registered tool's function with the given arguments. Supports both coroutine and regular functions.
|
63
59
|
|
64
60
|
Args:
|
65
|
-
|
61
|
+
func_call (Tuple[str, Dict[str, Any]]): A tuple containing the function name and a dictionary of keyword arguments.
|
66
62
|
|
67
63
|
Returns:
|
68
|
-
|
64
|
+
Any: The result of the function call.
|
69
65
|
|
70
66
|
Raises:
|
71
|
-
|
67
|
+
ValueError: If the function name is not registered or if there's an error during function invocation.
|
72
68
|
"""
|
73
69
|
name, kwargs = func_calls
|
74
|
-
if self.name_existed(name):
|
75
|
-
tool = self.registry[name]
|
76
|
-
func = tool.func
|
77
|
-
parser = tool.parser
|
78
|
-
try:
|
79
|
-
if func_call.is_coroutine_func(func):
|
80
|
-
tasks = [func_call.call_handler(func, **kwargs)]
|
81
|
-
out = await asyncio.gather(*tasks)
|
82
|
-
return parser(out[0]) if parser else out[0]
|
83
|
-
else:
|
84
|
-
out = func(**kwargs)
|
85
|
-
return parser(out) if parser else out
|
86
|
-
except Exception as e:
|
87
|
-
raise ValueError(
|
88
|
-
f"Error when invoking function {name} with arguments {kwargs} with error message {e}"
|
89
|
-
)
|
90
|
-
else:
|
70
|
+
if not self.name_existed(name):
|
91
71
|
raise ValueError(f"Function {name} is not registered.")
|
72
|
+
tool = self.registry[name]
|
73
|
+
func = tool.func
|
74
|
+
parser = tool.parser
|
75
|
+
try:
|
76
|
+
if func_call.is_coroutine_func(func):
|
77
|
+
tasks = [func_call.call_handler(func, **kwargs)]
|
78
|
+
out = await asyncio.gather(*tasks)
|
79
|
+
return parser(out[0]) if parser else out[0]
|
80
|
+
else:
|
81
|
+
out = func(**kwargs)
|
82
|
+
return parser(out) if parser else out
|
83
|
+
except Exception as e:
|
84
|
+
raise ValueError(
|
85
|
+
f"Error when invoking function {name} with arguments {kwargs} with error message {e}"
|
86
|
+
) from e
|
92
87
|
|
93
88
|
@staticmethod
|
94
89
|
def get_function_call(response: dict) -> Tuple[str, dict]:
|
@@ -96,19 +91,19 @@ class ToolManager:
|
|
96
91
|
Extracts a function call and arguments from a response dictionary.
|
97
92
|
|
98
93
|
Args:
|
99
|
-
|
94
|
+
response (dict): The response dictionary containing the function call information.
|
100
95
|
|
101
96
|
Returns:
|
102
|
-
|
97
|
+
Tuple[str, dict]: A tuple containing the function name and a dictionary of arguments.
|
103
98
|
|
104
99
|
Raises:
|
105
|
-
|
100
|
+
ValueError: If the response does not contain valid function call information.
|
106
101
|
"""
|
107
102
|
try:
|
108
103
|
func = response["action"][7:]
|
109
104
|
args = convert.to_dict(response["arguments"])
|
110
105
|
return func, args
|
111
|
-
except:
|
106
|
+
except Exception:
|
112
107
|
try:
|
113
108
|
func = response["recipient_name"].split(".")[-1]
|
114
109
|
args = response["parameters"]
|
@@ -121,7 +116,7 @@ class ToolManager:
|
|
121
116
|
Registers multiple tools in the registry.
|
122
117
|
|
123
118
|
Args:
|
124
|
-
|
119
|
+
tools (list[Tool]): A list of tool instances to register.
|
125
120
|
"""
|
126
121
|
func_call.lcall(tools, self._register_tool)
|
127
122
|
|
@@ -130,27 +125,24 @@ class ToolManager:
|
|
130
125
|
Generates a list of schemas for all registered tools.
|
131
126
|
|
132
127
|
Returns:
|
133
|
-
|
128
|
+
list[dict[str, Any]]: A list of tool schemas.
|
134
129
|
|
135
130
|
"""
|
136
|
-
|
137
|
-
for tool in self.registry.values():
|
138
|
-
schema_list.append(tool.schema_)
|
139
|
-
return schema_list
|
131
|
+
return [tool.schema_ for tool in self.registry.values()]
|
140
132
|
|
141
133
|
def parse_tool(self, tools: TOOL_TYPE, **kwargs) -> dict:
|
142
134
|
"""
|
143
135
|
Parses tool information and generates a dictionary for tool invocation.
|
144
136
|
|
145
137
|
Args:
|
146
|
-
|
147
|
-
|
138
|
+
tools: Tool information which can be a single Tool instance, a list of Tool instances, a tool name, or a list of tool names.
|
139
|
+
**kwargs: Additional keyword arguments.
|
148
140
|
|
149
141
|
Returns:
|
150
|
-
|
142
|
+
dict: A dictionary containing tool schema information and any additional keyword arguments.
|
151
143
|
|
152
144
|
Raises:
|
153
|
-
|
145
|
+
ValueError: If a tool name is provided that is not registered.
|
154
146
|
"""
|
155
147
|
|
156
148
|
def tool_check(tool):
|
@@ -167,13 +159,13 @@ class ToolManager:
|
|
167
159
|
|
168
160
|
if isinstance(tools, bool):
|
169
161
|
tool_kwarg = {"tools": self.to_tool_schema_list()}
|
170
|
-
kwargs =
|
162
|
+
kwargs = tool_kwarg | kwargs
|
171
163
|
|
172
164
|
else:
|
173
165
|
if not isinstance(tools, list):
|
174
166
|
tools = [tools]
|
175
167
|
tool_kwarg = {"tools": func_call.lcall(tools, tool_check)}
|
176
|
-
kwargs =
|
168
|
+
kwargs = tool_kwarg | kwargs
|
177
169
|
|
178
170
|
return kwargs
|
179
171
|
|
@@ -196,66 +188,66 @@ def func_to_tool(
|
|
196
188
|
objects with structured metadata.
|
197
189
|
|
198
190
|
Args:
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
191
|
+
func_ (Callable): The function to be transformed into a Tool object. This
|
192
|
+
function should have a docstring that follows the
|
193
|
+
specified docstring style for accurate schema generation.
|
194
|
+
parser (Optional[Any]): An optional parser object associated with the Tool.
|
195
|
+
This parameter is currently not utilized in the
|
196
|
+
transformation process but is included for future
|
197
|
+
compatibility and extension purposes.
|
198
|
+
docstring_style (str): The format of the docstring to be parsed, indicating
|
199
|
+
the convention used in the function's docstring.
|
200
|
+
Supports 'google' for Google-style docstrings and
|
201
|
+
'reST' for reStructuredText-style docstrings. The
|
202
|
+
chosen style affects how the docstring is parsed and
|
203
|
+
how the schema is generated.
|
212
204
|
|
213
205
|
Returns:
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
206
|
+
Tool: An object representing the original function wrapped as a Tool, along
|
207
|
+
with its generated schema. This Tool object can be used in systems that
|
208
|
+
require detailed metadata about functions, facilitating tasks such as
|
209
|
+
automatic documentation generation, user interface creation, or
|
210
|
+
integration with other software tools.
|
219
211
|
|
220
212
|
Examples:
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
213
|
+
>>> def example_function_google(param1: int, param2: str) -> bool:
|
214
|
+
... '''
|
215
|
+
... An example function using Google style docstrings.
|
216
|
+
...
|
217
|
+
... Args:
|
218
|
+
... param1 (int): The first parameter, demonstrating an integer input_.
|
219
|
+
... param2 (str): The second parameter, demonstrating a string input_.
|
220
|
+
...
|
221
|
+
... Returns:
|
222
|
+
... bool: A boolean value, illustrating the return type.
|
223
|
+
... '''
|
224
|
+
... return True
|
225
|
+
...
|
226
|
+
>>> tool_google = func_to_tool(example_function_google, docstring_style='google')
|
227
|
+
>>> print(isinstance(tool_google, Tool))
|
228
|
+
True
|
229
|
+
|
230
|
+
>>> def example_function_reST(param1: int, param2: str) -> bool:
|
231
|
+
... '''
|
232
|
+
... An example function using reStructuredText (reST) style docstrings.
|
233
|
+
...
|
234
|
+
... :param param1: The first parameter, demonstrating an integer input_.
|
235
|
+
... :type param1: int
|
236
|
+
... :param param2: The second parameter, demonstrating a string input_.
|
237
|
+
... :type param2: str
|
238
|
+
... :returns: A boolean value, illustrating the return type.
|
239
|
+
... :rtype: bool
|
240
|
+
... '''
|
241
|
+
... return True
|
242
|
+
...
|
243
|
+
>>> tool_reST = func_to_tool(example_function_reST, docstring_style='reST')
|
244
|
+
>>> print(isinstance(tool_reST, Tool))
|
245
|
+
True
|
254
246
|
|
255
247
|
Note:
|
256
|
-
|
257
|
-
|
258
|
-
|
248
|
+
The transformation process relies heavily on the accuracy and completeness of
|
249
|
+
the function's docstring. Functions with incomplete or incorrectly formatted
|
250
|
+
docstrings may result in incomplete or inaccurate Tool schemas.
|
259
251
|
"""
|
260
252
|
|
261
253
|
fs = []
|
@@ -263,7 +255,7 @@ def func_to_tool(
|
|
263
255
|
parsers = convert.to_list(parser, flatten=True, dropna=True)
|
264
256
|
|
265
257
|
if parser:
|
266
|
-
if len(funcs) != len(parsers)
|
258
|
+
if len(funcs) != len(parsers) != 1:
|
267
259
|
raise ValueError(
|
268
260
|
"Length of parser must match length of func. Except if you only pass one"
|
269
261
|
)
|
lionagi/integrations/__init__.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
from typing import Union, Callable, List, Dict, Any, TypeVar
|
2
2
|
|
3
|
-
|
4
3
|
from lionagi.libs.sys_util import SysUtil
|
5
4
|
|
6
5
|
T = TypeVar("T")
|
@@ -15,11 +14,11 @@ def to_langchain_document(datanode: T, **kwargs: Any) -> Any:
|
|
15
14
|
to match the Langchain Document schema before creating a Langchain Document object.
|
16
15
|
|
17
16
|
Args:
|
18
|
-
|
19
|
-
|
17
|
+
datanode (T): The data node to convert. Must have a `to_dict` method.
|
18
|
+
**kwargs: Additional keyword arguments to be passed to the Langchain Document constructor.
|
20
19
|
|
21
20
|
Returns:
|
22
|
-
|
21
|
+
Any: An instance of `LangchainDocument` populated with data from the input node.
|
23
22
|
"""
|
24
23
|
|
25
24
|
SysUtil.check_import("langchain")
|
@@ -44,20 +43,20 @@ def langchain_loader(
|
|
44
43
|
It passes specified arguments and keyword arguments to the loader for data retrieval or processing.
|
45
44
|
|
46
45
|
Args:
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
loader (Union[str, Callable]): A string representing the loader's name or a callable loader function.
|
47
|
+
loader_args (List[Any], optional): A list of positional arguments for the loader.
|
48
|
+
loader_kwargs (Dict[str, Any], optional): A dictionary of keyword arguments for the loader.
|
50
49
|
|
51
50
|
Returns:
|
52
|
-
|
51
|
+
Any: The result returned by the loader function, typically data loaded into a specified format.
|
53
52
|
|
54
53
|
Raises:
|
55
|
-
|
54
|
+
ValueError: If the loader cannot be initialized or fails to load data.
|
56
55
|
|
57
56
|
Examples:
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
>>> data = langchain_loader("json_loader", loader_args=["data.json"])
|
58
|
+
>>> isinstance(data, dict)
|
59
|
+
True
|
61
60
|
"""
|
62
61
|
|
63
62
|
SysUtil.check_import("langchain")
|
@@ -92,16 +91,16 @@ def langchain_text_splitter(
|
|
92
91
|
or documents into chunks. The splitter can be configured with additional arguments and keyword arguments.
|
93
92
|
|
94
93
|
Args:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
data (Union[str, List]): The text or list of texts to be split.
|
95
|
+
splitter (Union[str, Callable]): The name of the splitter function or the splitter function itself.
|
96
|
+
splitter_args (List[Any], optional): Positional arguments to pass to the splitter function.
|
97
|
+
splitter_kwargs (Dict[str, Any], optional): Keyword arguments to pass to the splitter function.
|
99
98
|
|
100
99
|
Returns:
|
101
|
-
|
100
|
+
List[str]: A list of text chunks produced by the text splitter.
|
102
101
|
|
103
102
|
Raises:
|
104
|
-
|
103
|
+
ValueError: If the splitter is invalid or fails during the split operation.
|
105
104
|
"""
|
106
105
|
splitter_args = splitter_args or []
|
107
106
|
splitter_kwargs = splitter_kwargs or {}
|
@@ -10,11 +10,11 @@ class LangchainBridge:
|
|
10
10
|
to match the Langchain Document schema before creating a Langchain Document object.
|
11
11
|
|
12
12
|
Args:
|
13
|
-
|
14
|
-
|
13
|
+
datanode (T): The data node to convert. Must have a `to_dict` method.
|
14
|
+
**kwargs: Additional keyword arguments to be passed to the Langchain Document constructor.
|
15
15
|
|
16
16
|
Returns:
|
17
|
-
|
17
|
+
Any: An instance of `LangchainDocument` populated with data from the input node.
|
18
18
|
"""
|
19
19
|
from .documents import to_langchain_document
|
20
20
|
|
@@ -29,15 +29,15 @@ class LangchainBridge:
|
|
29
29
|
It passes specified arguments and keyword arguments to the loader for data retrieval or processing.
|
30
30
|
|
31
31
|
Args:
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
loader (Union[str, Callable]): A string representing the loader's name or a callable loader function.
|
33
|
+
loader_args (List[Any], optional): A list of positional arguments for the loader.
|
34
|
+
loader_kwargs (Dict[str, Any], optional): A dictionary of keyword arguments for the loader.
|
35
35
|
|
36
36
|
Returns:
|
37
|
-
|
37
|
+
Any: The result returned by the loader function, typically data loaded into a specified format.
|
38
38
|
|
39
39
|
Raises:
|
40
|
-
|
40
|
+
ValueError: If the loader cannot be initialized or fails to load data.
|
41
41
|
"""
|
42
42
|
from .documents import langchain_loader
|
43
43
|
|
@@ -52,16 +52,16 @@ class LangchainBridge:
|
|
52
52
|
or documents into chunks. The splitter can be configured with additional arguments and keyword arguments.
|
53
53
|
|
54
54
|
Args:
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
data (Union[str, List]): The text or list of texts to be split.
|
56
|
+
splitter (Union[str, Callable]): The name of the splitter function or the splitter function itself.
|
57
|
+
splitter_args (List[Any], optional): Positional arguments to pass to the splitter function.
|
58
|
+
splitter_kwargs (Dict[str, Any], optional): Keyword arguments to pass to the splitter function.
|
59
59
|
|
60
60
|
Returns:
|
61
|
-
|
61
|
+
List[str]: A list of text chunks produced by the text splitter.
|
62
62
|
|
63
63
|
Raises:
|
64
|
-
|
64
|
+
ValueError: If the splitter is invalid or fails during the split operation.
|
65
65
|
"""
|
66
66
|
from .documents import langchain_text_splitter
|
67
67
|
|
@@ -9,17 +9,17 @@ class LlamaIndexBridge:
|
|
9
9
|
the expected Llama Index node schema, and then creates a Llama Index node object of the specified type.
|
10
10
|
|
11
11
|
Args:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
lion_node: The Lion node to convert. Must have a `to_dict` method.
|
13
|
+
node_type (Any, optional): The type of Llama Index node to create. Can be a string name of a node class
|
14
|
+
within the Llama Index schema or a class that inherits from `BaseNode`. Defaults to 'TextNode'.
|
15
|
+
**kwargs: Additional keyword arguments to be included in the Llama Index node's initialization.
|
16
16
|
|
17
17
|
Returns:
|
18
|
-
|
18
|
+
Any: A new instance of the specified Llama Index node type populated with data from the Lion node.
|
19
19
|
|
20
20
|
Raises:
|
21
|
-
|
22
|
-
|
21
|
+
TypeError: If `node_type` is neither a string nor a subclass of `BaseNode`.
|
22
|
+
AttributeError: If an error occurs due to an invalid node type or during the creation of the node object.
|
23
23
|
"""
|
24
24
|
from .textnode import to_llama_index_node
|
25
25
|
|
@@ -34,18 +34,18 @@ class LlamaIndexBridge:
|
|
34
34
|
then loads data using the reader's `load_data` method with the provided loader arguments and keyword arguments.
|
35
35
|
|
36
36
|
Args:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
reader (Union[None, str, Any], optional): The reader to use. This can be a class, a string identifier,
|
38
|
+
or None. If None, a default reader is used.
|
39
|
+
reader_args (List[Any], optional): Positional arguments to initialize the reader.
|
40
|
+
reader_kwargs (Dict[str, Any], optional): Keyword arguments to initialize the reader.
|
41
|
+
loader_args (List[Any], optional): Positional arguments for the reader's `load_data` method.
|
42
|
+
loader_kwargs (Dict[str, Any], optional): Keyword arguments for the reader's `load_data` method.
|
43
43
|
|
44
44
|
Returns:
|
45
|
-
|
45
|
+
Any: The documents or data loaded by the reader.
|
46
46
|
|
47
47
|
Raises:
|
48
|
-
|
48
|
+
ValueError: If there is an error initializing the reader or loading the data.
|
49
49
|
"""
|
50
50
|
from .reader import llama_index_read_data
|
51
51
|
|
@@ -60,16 +60,16 @@ class LlamaIndexBridge:
|
|
60
60
|
then parses documents using the node parser's `get_nodes_from_documents` method.
|
61
61
|
|
62
62
|
Args:
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
documents (Any): The documents to be parsed by the node parser.
|
64
|
+
node_parser (Any): The node parser to use. This can be a class, a string identifier, or None.
|
65
|
+
parser_args (Optional[List[Any]], optional): Positional arguments to initialize the node parser.
|
66
|
+
parser_kwargs (Optional[Dict[str, Any]], optional): Keyword arguments to initialize the node parser.
|
67
67
|
|
68
68
|
Returns:
|
69
|
-
|
69
|
+
Any: The nodes extracted from the documents by the node parser.
|
70
70
|
|
71
71
|
Raises:
|
72
|
-
|
72
|
+
ValueError: If there is an error initializing the node parser or parsing the documents.
|
73
73
|
"""
|
74
74
|
from .node_parser import llama_index_parse_node
|
75
75
|
|
@@ -87,7 +87,7 @@ class LlamaIndexBridge:
|
|
87
87
|
|
88
88
|
Args:
|
89
89
|
reader (Union[Any, str], optional): The reader identifier, which can be a reader class, a string alias
|
90
|
-
|
90
|
+
for a reader class, or None. If None, returns the SimpleDirectoryReader class.
|
91
91
|
|
92
92
|
Returns:
|
93
93
|
Any: The llama index reader class corresponding to the specified reader.
|
@@ -12,16 +12,16 @@ def get_llama_index_node_parser(node_parser: Any):
|
|
12
12
|
that the class is a subclass of NodeParser.
|
13
13
|
|
14
14
|
Args:
|
15
|
-
|
16
|
-
|
15
|
+
node_parser (Any): The node parser identifier, which can be a node parser class, a string alias
|
16
|
+
for a node parser class, or None.
|
17
17
|
|
18
18
|
Returns:
|
19
|
-
|
19
|
+
Any: The llama index node parser object corresponding to the specified node parser.
|
20
20
|
|
21
21
|
Raises:
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
TypeError: If the node_parser is neither a string nor a subclass of NodeParser.
|
23
|
+
AttributeError: If there is an issue importing the specified node parser due to it not being
|
24
|
+
found within the llama_index.core.node_parser module.
|
25
25
|
"""
|
26
26
|
|
27
27
|
SysUtil.check_import("llama_index", pip_name="llama-index")
|
@@ -57,16 +57,16 @@ def llama_index_parse_node(
|
|
57
57
|
then parses documents using the node parser's `get_nodes_from_documents` method.
|
58
58
|
|
59
59
|
Args:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
documents (Any): The documents to be parsed by the node parser.
|
61
|
+
node_parser (Any): The node parser to use. This can be a class, a string identifier, or None.
|
62
|
+
parser_args (Optional[List[Any]], optional): Positional arguments to initialize the node parser.
|
63
|
+
parser_kwargs (Optional[Dict[str, Any]], optional): Keyword arguments to initialize the node parser.
|
64
64
|
|
65
65
|
Returns:
|
66
|
-
|
66
|
+
Any: The nodes extracted from the documents by the node parser.
|
67
67
|
|
68
68
|
Raises:
|
69
|
-
|
69
|
+
ValueError: If there is an error initializing the node parser or parsing the documents.
|
70
70
|
"""
|
71
71
|
|
72
72
|
try:
|
@@ -15,7 +15,7 @@ def get_llama_index_reader(reader: Any | str = None) -> Any:
|
|
15
15
|
|
16
16
|
Args:
|
17
17
|
reader (Union[Any, str], optional): The reader identifier, which can be a reader class, a string alias
|
18
|
-
|
18
|
+
for a reader class, or None. If None, returns the SimpleDirectoryReader class.
|
19
19
|
|
20
20
|
Returns:
|
21
21
|
Any: The llama index reader class corresponding to the specified reader.
|
@@ -76,10 +76,10 @@ def parse_reader_name(reader_str):
|
|
76
76
|
to facilitate dynamic import and installation if necessary.
|
77
77
|
|
78
78
|
Args:
|
79
|
-
|
79
|
+
reader_str (str): The name of the reader as a string.
|
80
80
|
|
81
81
|
Returns:
|
82
|
-
|
82
|
+
Tuple[str, str]: A tuple containing the package name and the pip name corresponding to the reader.
|
83
83
|
"""
|
84
84
|
|
85
85
|
package_name = ""
|
@@ -172,18 +172,18 @@ def llama_index_read_data(
|
|
172
172
|
then loads data using the reader's `load_data` method with the provided loader arguments and keyword arguments.
|
173
173
|
|
174
174
|
Args:
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
175
|
+
reader (Union[None, str, Any], optional): The reader to use. This can be a class, a string identifier,
|
176
|
+
or None. If None, a default reader is used.
|
177
|
+
reader_args (List[Any], optional): Positional arguments to initialize the reader.
|
178
|
+
reader_kwargs (Dict[str, Any], optional): Keyword arguments to initialize the reader.
|
179
|
+
loader_args (List[Any], optional): Positional arguments for the reader's `load_data` method.
|
180
|
+
loader_kwargs (Dict[str, Any], optional): Keyword arguments for the reader's `load_data` method.
|
181
181
|
|
182
182
|
Returns:
|
183
|
-
|
183
|
+
Any: The documents or data loaded by the reader.
|
184
184
|
|
185
185
|
Raises:
|
186
|
-
|
186
|
+
ValueError: If there is an error initializing the reader or loading the data.
|
187
187
|
"""
|
188
188
|
try:
|
189
189
|
reader_args = reader_args or []
|