lionagi 0.0.115__py3-none-any.whl → 0.0.204__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +1 -2
- lionagi/_services/__init__.py +5 -0
- lionagi/_services/anthropic.py +79 -0
- lionagi/_services/base_service.py +414 -0
- lionagi/_services/oai.py +98 -0
- lionagi/_services/openrouter.py +44 -0
- lionagi/_services/services.py +91 -0
- lionagi/_services/transformers.py +46 -0
- lionagi/bridge/langchain.py +26 -16
- lionagi/bridge/llama_index.py +50 -20
- lionagi/configs/oai_configs.py +2 -14
- lionagi/configs/openrouter_configs.py +2 -2
- lionagi/core/__init__.py +7 -8
- lionagi/core/branch/branch.py +589 -0
- lionagi/core/branch/branch_manager.py +139 -0
- lionagi/core/branch/conversation.py +484 -0
- lionagi/core/core_util.py +59 -0
- lionagi/core/flow/flow.py +19 -0
- lionagi/core/flow/flow_util.py +62 -0
- lionagi/core/instruction_set/__init__.py +0 -5
- lionagi/core/instruction_set/instruction_set.py +343 -0
- lionagi/core/messages/messages.py +176 -0
- lionagi/core/sessions/__init__.py +0 -5
- lionagi/core/sessions/session.py +428 -0
- lionagi/loaders/chunker.py +51 -47
- lionagi/loaders/load_util.py +2 -2
- lionagi/loaders/reader.py +45 -39
- lionagi/models/imodel.py +53 -0
- lionagi/schema/async_queue.py +158 -0
- lionagi/schema/base_node.py +318 -147
- lionagi/schema/base_tool.py +31 -1
- lionagi/schema/data_logger.py +74 -38
- lionagi/schema/data_node.py +57 -6
- lionagi/structures/graph.py +132 -10
- lionagi/structures/relationship.py +58 -20
- lionagi/structures/structure.py +36 -25
- lionagi/tests/test_utils/test_api_util.py +219 -0
- lionagi/tests/test_utils/test_call_util.py +785 -0
- lionagi/tests/test_utils/test_encrypt_util.py +323 -0
- lionagi/tests/test_utils/test_io_util.py +238 -0
- lionagi/tests/test_utils/test_nested_util.py +338 -0
- lionagi/tests/test_utils/test_sys_util.py +358 -0
- lionagi/tools/tool_manager.py +186 -0
- lionagi/tools/tool_util.py +266 -3
- lionagi/utils/__init__.py +21 -61
- lionagi/utils/api_util.py +359 -71
- lionagi/utils/call_util.py +839 -264
- lionagi/utils/encrypt_util.py +283 -16
- lionagi/utils/io_util.py +178 -93
- lionagi/utils/nested_util.py +672 -0
- lionagi/utils/pd_util.py +57 -0
- lionagi/utils/sys_util.py +284 -156
- lionagi/utils/url_util.py +55 -0
- lionagi/version.py +1 -1
- {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/METADATA +21 -17
- lionagi-0.0.204.dist-info/RECORD +106 -0
- lionagi/core/conversations/__init__.py +0 -5
- lionagi/core/conversations/conversation.py +0 -107
- lionagi/core/flows/__init__.py +0 -8
- lionagi/core/flows/flow.py +0 -8
- lionagi/core/flows/flow_util.py +0 -62
- lionagi/core/instruction_set/instruction_sets.py +0 -7
- lionagi/core/sessions/sessions.py +0 -185
- lionagi/endpoints/__init__.py +0 -5
- lionagi/endpoints/audio.py +0 -17
- lionagi/endpoints/chatcompletion.py +0 -54
- lionagi/messages/__init__.py +0 -11
- lionagi/messages/instruction.py +0 -15
- lionagi/messages/message.py +0 -110
- lionagi/messages/response.py +0 -33
- lionagi/messages/system.py +0 -12
- lionagi/objs/__init__.py +0 -11
- lionagi/objs/abc_objs.py +0 -39
- lionagi/objs/async_queue.py +0 -135
- lionagi/objs/messenger.py +0 -85
- lionagi/objs/tool_manager.py +0 -253
- lionagi/services/__init__.py +0 -11
- lionagi/services/base_api_service.py +0 -230
- lionagi/services/oai.py +0 -34
- lionagi/services/openrouter.py +0 -31
- lionagi/tests/test_api_util.py +0 -46
- lionagi/tests/test_call_util.py +0 -115
- lionagi/tests/test_convert_util.py +0 -202
- lionagi/tests/test_encrypt_util.py +0 -33
- lionagi/tests/test_flat_util.py +0 -426
- lionagi/tests/test_sys_util.py +0 -0
- lionagi/utils/convert_util.py +0 -229
- lionagi/utils/flat_util.py +0 -599
- lionagi-0.0.115.dist-info/RECORD +0 -110
- /lionagi/{services → _services}/anyscale.py +0 -0
- /lionagi/{services → _services}/azure.py +0 -0
- /lionagi/{services → _services}/bedrock.py +0 -0
- /lionagi/{services → _services}/everlyai.py +0 -0
- /lionagi/{services → _services}/gemini.py +0 -0
- /lionagi/{services → _services}/gpt4all.py +0 -0
- /lionagi/{services → _services}/huggingface.py +0 -0
- /lionagi/{services → _services}/litellm.py +0 -0
- /lionagi/{services → _services}/localai.py +0 -0
- /lionagi/{services → _services}/mistralai.py +0 -0
- /lionagi/{services → _services}/ollama.py +0 -0
- /lionagi/{services → _services}/openllm.py +0 -0
- /lionagi/{services → _services}/perplexity.py +0 -0
- /lionagi/{services → _services}/predibase.py +0 -0
- /lionagi/{services → _services}/rungpt.py +0 -0
- /lionagi/{services → _services}/vllm.py +0 -0
- /lionagi/{services → _services}/xinference.py +0 -0
- /lionagi/{endpoints/assistants.py → agents/__init__.py} +0 -0
- /lionagi/{tools → agents}/planner.py +0 -0
- /lionagi/{tools → agents}/prompter.py +0 -0
- /lionagi/{tools → agents}/scorer.py +0 -0
- /lionagi/{tools → agents}/summarizer.py +0 -0
- /lionagi/{tools → agents}/validator.py +0 -0
- /lionagi/{endpoints/embeddings.py → core/branch/__init__.py} +0 -0
- /lionagi/{services/anthropic.py → core/branch/cluster.py} +0 -0
- /lionagi/{endpoints/finetune.py → core/flow/__init__.py} +0 -0
- /lionagi/{endpoints/image.py → core/messages/__init__.py} +0 -0
- /lionagi/{endpoints/moderation.py → models/__init__.py} +0 -0
- /lionagi/{endpoints/vision.py → models/base_model.py} +0 -0
- /lionagi/{objs → schema}/status_tracker.py +0 -0
- /lionagi/tests/{test_io_util.py → test_utils/__init__.py} +0 -0
- {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/LICENSE +0 -0
- {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/WHEEL +0 -0
- {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/top_level.txt +0 -0
lionagi/loaders/reader.py
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
-
# use utils, schema, and bridge
|
2
1
|
from typing import Union, Callable
|
3
2
|
|
4
|
-
from
|
5
|
-
from
|
3
|
+
from ..utils import lcall
|
4
|
+
from ..bridge import langchain_loader, from_langchain, llama_index_reader, from_llama_index
|
6
5
|
from .load_util import dir_to_nodes, ReaderType
|
7
6
|
|
8
7
|
|
9
8
|
def _datanode_parser(nodes, parser):
|
10
9
|
"""
|
11
|
-
Parses
|
12
|
-
|
13
|
-
|
14
|
-
nodes
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
Parses raw data into DataNode instances using the provided parser function.
|
11
|
+
|
12
|
+
Args:
|
13
|
+
nodes: The list of raw data to be parsed.
|
14
|
+
parser: The parser function to transform nodes into DataNode instances.
|
15
|
+
|
18
16
|
Returns:
|
19
|
-
|
20
|
-
|
17
|
+
A list of parsed DataNode instances.
|
18
|
+
|
21
19
|
Raises:
|
22
20
|
ValueError: If the parser function fails.
|
21
|
+
|
22
|
+
Example usage:
|
23
|
+
>>> raw_nodes = [{'content': 'Example content'}]
|
24
|
+
>>> parser = lambda x: [DataNode(**node) for node in x]
|
25
|
+
>>> datanodes = _datanode_parser(raw_nodes, parser)
|
23
26
|
"""
|
24
27
|
try:
|
25
28
|
nodes = parser(nodes)
|
@@ -27,18 +30,21 @@ def _datanode_parser(nodes, parser):
|
|
27
30
|
raise ValueError(f'DataNode parser {parser} failed. Error:{e}')
|
28
31
|
return nodes
|
29
32
|
|
30
|
-
|
31
33
|
def text_reader(args, kwargs):
|
32
34
|
"""
|
33
35
|
Reads text files from a directory and converts them to DataNode instances.
|
34
|
-
|
35
|
-
|
36
|
-
args
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
|
37
|
+
Args:
|
38
|
+
args: Positional arguments for the dir_to_nodes function.
|
39
|
+
kwargs: Keyword arguments for the dir_to_nodes function.
|
40
|
+
|
40
41
|
Returns:
|
41
|
-
|
42
|
+
A list of DataNode instances.
|
43
|
+
|
44
|
+
Example usage:
|
45
|
+
>>> args = ['path/to/text/files']
|
46
|
+
>>> kwargs = {'file_extension': 'txt'}
|
47
|
+
>>> nodes = text_reader(args, kwargs)
|
42
48
|
"""
|
43
49
|
return dir_to_nodes(*args, **kwargs)
|
44
50
|
|
@@ -52,28 +58,28 @@ def load(reader: Union[str, Callable],
|
|
52
58
|
to_datanode: Union[bool, Callable] = True):
|
53
59
|
"""
|
54
60
|
Loads documents using the specified reader and reader type.
|
55
|
-
|
56
|
-
|
57
|
-
reader
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
load_kwargs (dict): Keyword arguments for the loader function. Defaults to an empty dict.
|
68
|
-
|
69
|
-
to_datanode (Union[bool, Callable]): Determines whether to convert the result into DataNode instances, or
|
70
|
-
a callable to convert the result. Defaults to True.
|
71
|
-
|
61
|
+
|
62
|
+
Args:
|
63
|
+
reader: The reader function or its name as a string.
|
64
|
+
reader_type: The type of the reader. Defaults to ReaderType.PLAIN.
|
65
|
+
reader_args: Positional arguments for the reader function. Defaults to an empty list.
|
66
|
+
reader_kwargs: Keyword arguments for the reader function. Defaults to an empty dict.
|
67
|
+
load_args: Positional arguments for the loader function. Defaults to an empty list.
|
68
|
+
load_kwargs: Keyword arguments for the loader function. Defaults to an empty dict.
|
69
|
+
to_datanode: Determines whether to convert the result into DataNode instances, or
|
70
|
+
a callable to convert the result. Defaults to True.
|
71
|
+
|
72
72
|
Returns:
|
73
|
-
|
74
|
-
|
73
|
+
A list of loaded and potentially parsed documents.
|
74
|
+
|
75
75
|
Raises:
|
76
76
|
ValueError: If the reader fails or an unsupported reader type is provided.
|
77
|
+
|
78
|
+
Example usage:
|
79
|
+
>>> reader = 'text_reader'
|
80
|
+
>>> reader_args = ['path/to/text/files']
|
81
|
+
>>> reader_kwargs = {'file_extension': 'txt'}
|
82
|
+
>>> nodes = load(reader, reader_args=reader_args, reader_kwargs=reader_kwargs)
|
77
83
|
"""
|
78
84
|
if reader_type == ReaderType.PLAIN:
|
79
85
|
try:
|
lionagi/models/imodel.py
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# from ..configs import oai_schema
|
2
|
+
|
3
|
+
# class BaseIntelligentModel:
|
4
|
+
|
5
|
+
# def __init__(
|
6
|
+
# self,
|
7
|
+
# service=None,
|
8
|
+
# default_config=oai_schema['chat']['config'],
|
9
|
+
# **kwargs
|
10
|
+
# ) -> None:
|
11
|
+
# # kwargs are the individual parameters that the model can take
|
12
|
+
# # different for different models
|
13
|
+
# self.service=service,
|
14
|
+
# self.config = {**default_config, **kwargs},
|
15
|
+
|
16
|
+
# async def __call__(
|
17
|
+
# self,
|
18
|
+
# payload,
|
19
|
+
# service=None,
|
20
|
+
# endpoint_='chat/completions',
|
21
|
+
# method='post'
|
22
|
+
# ):
|
23
|
+
# service = service or self.service
|
24
|
+
# return await service.serve(
|
25
|
+
# payload=payload, endpoint_=endpoint_, method=method
|
26
|
+
# )
|
27
|
+
|
28
|
+
# def set_service(self, service):
|
29
|
+
# self.service = service
|
30
|
+
|
31
|
+
# def set_config(self, config):
|
32
|
+
# self.config=config
|
33
|
+
|
34
|
+
# def change_model(self, model):
|
35
|
+
# self.config['model'] = model
|
36
|
+
|
37
|
+
# def change_temperature(self, temperature):
|
38
|
+
# self.config['temperature'] = temperature
|
39
|
+
|
40
|
+
# def revert_to_default_config(self):
|
41
|
+
# self.config = oai_schema['chat']['config']
|
42
|
+
|
43
|
+
# def modify_config(self, **kwargs):
|
44
|
+
# self.config = {**self.config, **kwargs}
|
45
|
+
|
46
|
+
|
47
|
+
# class IModel(BaseIntelligentModel):
|
48
|
+
|
49
|
+
# def __init__(
|
50
|
+
# self, service=None, default_model_kwargs=None, **kwargs
|
51
|
+
# ) -> None:
|
52
|
+
# super().__init__(service, default_model_kwargs, **kwargs)
|
53
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# import asyncio
|
2
|
+
# from typing import Any, Callable
|
3
|
+
# from ..utils.call_util import tcall
|
4
|
+
|
5
|
+
# class AsyncQueue:
|
6
|
+
# """
|
7
|
+
# A queue class that handles asynchronous operations using asyncio.
|
8
|
+
|
9
|
+
# This class provides an asynchronous queue that can enqueue items, process them
|
10
|
+
# asynchronously, and support graceful shutdowns. It is designed to facilitate
|
11
|
+
# concurrent task processing in an orderly and controlled manner.
|
12
|
+
|
13
|
+
# Attributes:
|
14
|
+
# queue (asyncio.Queue):
|
15
|
+
# A queue to hold items for asynchronous processing.
|
16
|
+
# _stop_event (asyncio.Event):
|
17
|
+
# An event to signal when the queue should stop processing.
|
18
|
+
|
19
|
+
# Methods:
|
20
|
+
# enqueue(item):
|
21
|
+
# Add an item to the queue for processing.
|
22
|
+
# dequeue():
|
23
|
+
# Remove and return an item from the queue.
|
24
|
+
# join():
|
25
|
+
# Wait until all items in the queue have been processed.
|
26
|
+
# stop():
|
27
|
+
# Signal to stop processing new items in the queue.
|
28
|
+
# stopped():
|
29
|
+
# Check if the queue has been signaled to stop.
|
30
|
+
# process_requests(func):
|
31
|
+
# Process items using a provided function.
|
32
|
+
# """
|
33
|
+
|
34
|
+
# def __init__(self) -> None:
|
35
|
+
# """
|
36
|
+
# Initializes an AsyncQueue object with an empty asyncio Queue and a stop event.
|
37
|
+
# """
|
38
|
+
# self.queue = asyncio.Queue()
|
39
|
+
# self._stop_event = asyncio.Event()
|
40
|
+
|
41
|
+
# async def enqueue(self, item: Any) -> None:
|
42
|
+
# """
|
43
|
+
# Asynchronously add an item to the queue for processing.
|
44
|
+
|
45
|
+
# Parameters:
|
46
|
+
# item (Any): The item to be added to the queue.
|
47
|
+
|
48
|
+
# Example:
|
49
|
+
# >>> async_queue = AsyncQueue()
|
50
|
+
# >>> asyncio.run(async_queue.enqueue('Task 1'))
|
51
|
+
# """
|
52
|
+
# await self.queue.put(item)
|
53
|
+
|
54
|
+
# async def dequeue(self) -> Any:
|
55
|
+
# """
|
56
|
+
# Asynchronously remove and return an item from the queue.
|
57
|
+
|
58
|
+
# If the queue is empty, this method will wait until an item is available.
|
59
|
+
|
60
|
+
# Returns:
|
61
|
+
# Any: The next item from the queue.
|
62
|
+
|
63
|
+
# Example:
|
64
|
+
# >>> async_queue = AsyncQueue()
|
65
|
+
# >>> asyncio.run(async_queue.enqueue('Task 1'))
|
66
|
+
# >>> asyncio.run(async_queue.dequeue())
|
67
|
+
# 'Task 1'
|
68
|
+
# """
|
69
|
+
# return await self.queue.get()
|
70
|
+
|
71
|
+
# async def join(self) -> None:
|
72
|
+
# """
|
73
|
+
# Asynchronously wait until all items in the queue have been processed.
|
74
|
+
|
75
|
+
# This method blocks until every item that has been enqueued is processed,
|
76
|
+
# ensuring that all tasks are completed.
|
77
|
+
|
78
|
+
# Example:
|
79
|
+
# >>> async_queue = AsyncQueue()
|
80
|
+
# >>> asyncio.run(async_queue.enqueue('Task 1'))
|
81
|
+
# >>> asyncio.run(async_queue.join()) # This will block until 'Task 1' is processed.
|
82
|
+
# """
|
83
|
+
# await self.queue.join()
|
84
|
+
|
85
|
+
# async def stop(self) -> None:
|
86
|
+
# """
|
87
|
+
# Signal the queue to stop processing new items.
|
88
|
+
|
89
|
+
# Once called, the queue will not process any new items after the current ones
|
90
|
+
# are completed, allowing for a graceful shutdown.
|
91
|
+
|
92
|
+
# Example:
|
93
|
+
# >>> async_queue = AsyncQueue()
|
94
|
+
# >>> asyncio.run(async_queue.stop()) # This signals the queue to stop processing.
|
95
|
+
# """
|
96
|
+
# self._stop_event.set()
|
97
|
+
|
98
|
+
# def stopped(self) -> bool:
|
99
|
+
# """
|
100
|
+
# Check if the queue has been signaled to stop processing.
|
101
|
+
|
102
|
+
# Returns:
|
103
|
+
# bool: True if a stop has been signaled, False otherwise.
|
104
|
+
|
105
|
+
# Example:
|
106
|
+
# >>> async_queue = AsyncQueue()
|
107
|
+
# >>> asyncio.run(async_queue.stop())
|
108
|
+
# >>> async_queue.stopped()
|
109
|
+
# True
|
110
|
+
# """
|
111
|
+
# return self._stop_event.is_set()
|
112
|
+
|
113
|
+
# # async def process_requests(self, func: Callable[[Any], Any]) -> None:
|
114
|
+
# # """
|
115
|
+
# # Asynchronously process items from the queue using the provided function.
|
116
|
+
|
117
|
+
# # Continuously dequeues items and applies the given function to each.
|
118
|
+
# # The processing stops when the queue is signaled to stop or a sentinel value (`None`) is dequeued.
|
119
|
+
|
120
|
+
# # Parameters:
|
121
|
+
# # func (Callable[[Any], Any]): A coroutine function to process items from the queue.
|
122
|
+
|
123
|
+
# # Example:
|
124
|
+
# # >>> async def sample_processing(task):
|
125
|
+
# # ... print("Processing:", task)
|
126
|
+
# # >>> async_queue = AsyncQueue()
|
127
|
+
# # >>> asyncio.run(async_queue.enqueue('Task 1'))
|
128
|
+
# # >>> asyncio.run(async_queue.process_requests(sample_processing))
|
129
|
+
# # Processing: Task 1
|
130
|
+
# # """
|
131
|
+
# # while not self.stopped():
|
132
|
+
# # item = await self.dequeue()
|
133
|
+
# # if item is None: # Using `None` as a sentinel value to cease processing.
|
134
|
+
# # await self.stop()
|
135
|
+
# # break
|
136
|
+
# # await func(item)
|
137
|
+
|
138
|
+
# async def process_requests(self, func, timeout=None):
|
139
|
+
# """
|
140
|
+
# Process items with timeout management for each task.
|
141
|
+
# """
|
142
|
+
# tasks = set()
|
143
|
+
# while not self.stopped():
|
144
|
+
# if len(tasks) >= self.max_concurrent_tasks:
|
145
|
+
# done, tasks = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
146
|
+
|
147
|
+
# item = await self.dequeue()
|
148
|
+
# if item is None:
|
149
|
+
# await self.stop()
|
150
|
+
# break
|
151
|
+
|
152
|
+
# # Wrap the function call with tcall for timeout handling
|
153
|
+
# task = asyncio.create_task(tcall(item, func, timeout=timeout))
|
154
|
+
# tasks.add(task)
|
155
|
+
|
156
|
+
# if tasks:
|
157
|
+
# await asyncio.wait(tasks)
|
158
|
+
|