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.
Files changed (123) hide show
  1. lionagi/__init__.py +1 -2
  2. lionagi/_services/__init__.py +5 -0
  3. lionagi/_services/anthropic.py +79 -0
  4. lionagi/_services/base_service.py +414 -0
  5. lionagi/_services/oai.py +98 -0
  6. lionagi/_services/openrouter.py +44 -0
  7. lionagi/_services/services.py +91 -0
  8. lionagi/_services/transformers.py +46 -0
  9. lionagi/bridge/langchain.py +26 -16
  10. lionagi/bridge/llama_index.py +50 -20
  11. lionagi/configs/oai_configs.py +2 -14
  12. lionagi/configs/openrouter_configs.py +2 -2
  13. lionagi/core/__init__.py +7 -8
  14. lionagi/core/branch/branch.py +589 -0
  15. lionagi/core/branch/branch_manager.py +139 -0
  16. lionagi/core/branch/conversation.py +484 -0
  17. lionagi/core/core_util.py +59 -0
  18. lionagi/core/flow/flow.py +19 -0
  19. lionagi/core/flow/flow_util.py +62 -0
  20. lionagi/core/instruction_set/__init__.py +0 -5
  21. lionagi/core/instruction_set/instruction_set.py +343 -0
  22. lionagi/core/messages/messages.py +176 -0
  23. lionagi/core/sessions/__init__.py +0 -5
  24. lionagi/core/sessions/session.py +428 -0
  25. lionagi/loaders/chunker.py +51 -47
  26. lionagi/loaders/load_util.py +2 -2
  27. lionagi/loaders/reader.py +45 -39
  28. lionagi/models/imodel.py +53 -0
  29. lionagi/schema/async_queue.py +158 -0
  30. lionagi/schema/base_node.py +318 -147
  31. lionagi/schema/base_tool.py +31 -1
  32. lionagi/schema/data_logger.py +74 -38
  33. lionagi/schema/data_node.py +57 -6
  34. lionagi/structures/graph.py +132 -10
  35. lionagi/structures/relationship.py +58 -20
  36. lionagi/structures/structure.py +36 -25
  37. lionagi/tests/test_utils/test_api_util.py +219 -0
  38. lionagi/tests/test_utils/test_call_util.py +785 -0
  39. lionagi/tests/test_utils/test_encrypt_util.py +323 -0
  40. lionagi/tests/test_utils/test_io_util.py +238 -0
  41. lionagi/tests/test_utils/test_nested_util.py +338 -0
  42. lionagi/tests/test_utils/test_sys_util.py +358 -0
  43. lionagi/tools/tool_manager.py +186 -0
  44. lionagi/tools/tool_util.py +266 -3
  45. lionagi/utils/__init__.py +21 -61
  46. lionagi/utils/api_util.py +359 -71
  47. lionagi/utils/call_util.py +839 -264
  48. lionagi/utils/encrypt_util.py +283 -16
  49. lionagi/utils/io_util.py +178 -93
  50. lionagi/utils/nested_util.py +672 -0
  51. lionagi/utils/pd_util.py +57 -0
  52. lionagi/utils/sys_util.py +284 -156
  53. lionagi/utils/url_util.py +55 -0
  54. lionagi/version.py +1 -1
  55. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/METADATA +21 -17
  56. lionagi-0.0.204.dist-info/RECORD +106 -0
  57. lionagi/core/conversations/__init__.py +0 -5
  58. lionagi/core/conversations/conversation.py +0 -107
  59. lionagi/core/flows/__init__.py +0 -8
  60. lionagi/core/flows/flow.py +0 -8
  61. lionagi/core/flows/flow_util.py +0 -62
  62. lionagi/core/instruction_set/instruction_sets.py +0 -7
  63. lionagi/core/sessions/sessions.py +0 -185
  64. lionagi/endpoints/__init__.py +0 -5
  65. lionagi/endpoints/audio.py +0 -17
  66. lionagi/endpoints/chatcompletion.py +0 -54
  67. lionagi/messages/__init__.py +0 -11
  68. lionagi/messages/instruction.py +0 -15
  69. lionagi/messages/message.py +0 -110
  70. lionagi/messages/response.py +0 -33
  71. lionagi/messages/system.py +0 -12
  72. lionagi/objs/__init__.py +0 -11
  73. lionagi/objs/abc_objs.py +0 -39
  74. lionagi/objs/async_queue.py +0 -135
  75. lionagi/objs/messenger.py +0 -85
  76. lionagi/objs/tool_manager.py +0 -253
  77. lionagi/services/__init__.py +0 -11
  78. lionagi/services/base_api_service.py +0 -230
  79. lionagi/services/oai.py +0 -34
  80. lionagi/services/openrouter.py +0 -31
  81. lionagi/tests/test_api_util.py +0 -46
  82. lionagi/tests/test_call_util.py +0 -115
  83. lionagi/tests/test_convert_util.py +0 -202
  84. lionagi/tests/test_encrypt_util.py +0 -33
  85. lionagi/tests/test_flat_util.py +0 -426
  86. lionagi/tests/test_sys_util.py +0 -0
  87. lionagi/utils/convert_util.py +0 -229
  88. lionagi/utils/flat_util.py +0 -599
  89. lionagi-0.0.115.dist-info/RECORD +0 -110
  90. /lionagi/{services → _services}/anyscale.py +0 -0
  91. /lionagi/{services → _services}/azure.py +0 -0
  92. /lionagi/{services → _services}/bedrock.py +0 -0
  93. /lionagi/{services → _services}/everlyai.py +0 -0
  94. /lionagi/{services → _services}/gemini.py +0 -0
  95. /lionagi/{services → _services}/gpt4all.py +0 -0
  96. /lionagi/{services → _services}/huggingface.py +0 -0
  97. /lionagi/{services → _services}/litellm.py +0 -0
  98. /lionagi/{services → _services}/localai.py +0 -0
  99. /lionagi/{services → _services}/mistralai.py +0 -0
  100. /lionagi/{services → _services}/ollama.py +0 -0
  101. /lionagi/{services → _services}/openllm.py +0 -0
  102. /lionagi/{services → _services}/perplexity.py +0 -0
  103. /lionagi/{services → _services}/predibase.py +0 -0
  104. /lionagi/{services → _services}/rungpt.py +0 -0
  105. /lionagi/{services → _services}/vllm.py +0 -0
  106. /lionagi/{services → _services}/xinference.py +0 -0
  107. /lionagi/{endpoints/assistants.py → agents/__init__.py} +0 -0
  108. /lionagi/{tools → agents}/planner.py +0 -0
  109. /lionagi/{tools → agents}/prompter.py +0 -0
  110. /lionagi/{tools → agents}/scorer.py +0 -0
  111. /lionagi/{tools → agents}/summarizer.py +0 -0
  112. /lionagi/{tools → agents}/validator.py +0 -0
  113. /lionagi/{endpoints/embeddings.py → core/branch/__init__.py} +0 -0
  114. /lionagi/{services/anthropic.py → core/branch/cluster.py} +0 -0
  115. /lionagi/{endpoints/finetune.py → core/flow/__init__.py} +0 -0
  116. /lionagi/{endpoints/image.py → core/messages/__init__.py} +0 -0
  117. /lionagi/{endpoints/moderation.py → models/__init__.py} +0 -0
  118. /lionagi/{endpoints/vision.py → models/base_model.py} +0 -0
  119. /lionagi/{objs → schema}/status_tracker.py +0 -0
  120. /lionagi/tests/{test_io_util.py → test_utils/__init__.py} +0 -0
  121. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/LICENSE +0 -0
  122. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/WHEEL +0 -0
  123. {lionagi-0.0.115.dist-info → lionagi-0.0.204.dist-info}/top_level.txt +0 -0
@@ -1,11 +0,0 @@
1
- from .message import Message
2
- from .system import System
3
- from .instruction import Instruction
4
- from .response import Response
5
-
6
- __all__ = [
7
- "Message",
8
- "System",
9
- "Instruction",
10
- "Response"
11
- ]
@@ -1,15 +0,0 @@
1
- from typing import Any, Optional
2
- from .message import Message
3
-
4
- class Instruction(Message):
5
-
6
- def _create_message(self, instruction: Any, context=None ,name: Optional[str] = None) -> None:
7
- self._create_roled_message(
8
- role_="user",
9
- content_key="instruction",
10
- content=instruction,
11
- name=name
12
- )
13
- if context:
14
- self.content.update({"context": context})
15
-
@@ -1,110 +0,0 @@
1
- import json
2
- from typing import Any, Optional
3
- from lionagi.schema import BaseNode
4
-
5
- class Message(BaseNode):
6
- """
7
- Represents a message within a communication system, extending from BaseNode.
8
-
9
- This class encapsulates the details of a message, including its role, content, and name.
10
- It provides methods to manipulate and retrieve message information.
11
-
12
- Attributes:
13
- role (Optional[str]): The role associated with the message (e.g., 'user', 'system'). Defaults to None.
14
- name (Optional[str]): The name associated with the message, often reflecting the role. Defaults to None.
15
-
16
- Properties:
17
- message: Returns the message as a dictionary including role and content.
18
- message_content: Returns only the content part of the message.
19
-
20
- Methods:
21
- to_message: Converts the message object into a dictionary format.
22
- create_role_message: Sets the role, content, and name of the message.
23
- get_role: Retrieves the role of the message, formatted as a lowercase string.
24
- get_name: Retrieves the name of the message, formatted as a lowercase string.
25
- """
26
-
27
- role: Optional[str] = None
28
- name: Optional[str] = None
29
-
30
- @property
31
- def message(self):
32
- """
33
- Property that returns the message as a dictionary.
34
-
35
- Returns:
36
- dict: A dictionary representation of the message with 'role' and 'content'.
37
- """
38
- return self._to_message()
39
-
40
- @property
41
- def message_content(self):
42
- """
43
- Property that returns the content part of the message.
44
-
45
- Returns:
46
- Any: The content of the message.
47
- """
48
- return self.message['content']
49
-
50
- def _to_message(self):
51
- """
52
- Converts the message object into a dictionary format, including role and content.
53
-
54
- Returns:
55
- dict: A dictionary with 'role' and 'content' keys.
56
- """
57
- out = {
58
- "role": self.role,
59
- "content": json.dumps(self.content) if isinstance(self.content, dict) else self.content
60
- }
61
- return out
62
-
63
- def _create_roled_message(
64
- self, role_: str, content: Any, content_key: str,
65
- name: Optional[str] = None
66
- ) -> None:
67
- """
68
- Sets the role, content, and name of the message.
69
-
70
- Parameters:
71
- role_ (str): The role to assign to the message.
72
- content (Any): The content of the message.
73
- content_key (str): The key under which the content is stored.
74
- name (Optional[str]): The name associated with the message. Defaults to the role if not provided.
75
- """
76
- self.role = role_
77
- self.content = {content_key: content}
78
- self.name = name or role_
79
-
80
- def get_role(self):
81
- """
82
- Retrieves the role of the message, formatted as a lowercase string.
83
-
84
- Returns:
85
- str: The message's role in lowercase.
86
- """
87
- return str(self.role).strip().lower()
88
-
89
- def get_name(self):
90
- """
91
- Retrieves the name of the message, formatted as a lowercase string.
92
-
93
- Returns:
94
- str: The message's name in lowercase.
95
- """
96
- return str(self.name).strip().lower()
97
-
98
- def __str__(self):
99
- """
100
- Informal string representation of Message object, intended to be readable.
101
- Includes role, name, and a brief preview of the content.
102
- """
103
- content_preview = (
104
- (str(self.content)[:75] + '...') if self.content and len(self.content) > 75
105
- else str(self.content)
106
- )
107
- return f"Message(role={self.role}, name={self.name}, content='{content_preview}')"
108
-
109
-
110
-
@@ -1,33 +0,0 @@
1
- from typing import Any, Optional
2
- from .message import Message
3
-
4
- class Response(Message):
5
-
6
- def _create_message(self, response: Any, name: Optional[str] = None) -> None:
7
- self.role = "assistant"
8
- try:
9
- response = response["message"]
10
- if str(response['content']) == "None":
11
- try:
12
- tool_count = 0
13
- func_list = []
14
- while tool_count < len(response['tool_calls']):
15
- if response['tool_calls'][tool_count]['type'] == 'function':
16
- func_content = {
17
- "function": ("func_" + response['tool_calls'][tool_count]['function']['name']),
18
- "arguments": response['tool_calls'][tool_count]['function']['arguments']
19
- }
20
- func_list.append(func_content)
21
- tool_count += 1
22
-
23
- self.name = name or "func_request"
24
- self.content = {'function_list': func_list}
25
- except:
26
- raise ValueError("Response message must be one of regular response or function calling")
27
- else:
28
- self.content = response['content']
29
- self.name = name or "assistant"
30
- except:
31
- self.name = name or "func_call"
32
- self.content = response
33
-
@@ -1,12 +0,0 @@
1
- from typing import Any, Optional
2
- from .message import Message
3
-
4
- class System(Message):
5
-
6
- def _create_message(self, system: Any, name: Optional[str] = None) -> None:
7
- self._create_roled_message(
8
- role_="system",
9
- content_key="system",
10
- content=system,
11
- name=name
12
- )
lionagi/objs/__init__.py DELETED
@@ -1,11 +0,0 @@
1
- from .messenger import Messenger
2
- from .tool_manager import ToolManager
3
- from .async_queue import AsyncQueue
4
- from .status_tracker import StatusTracker
5
-
6
- __all__ = [
7
- 'Messenger',
8
- 'ToolManager',
9
- 'AsyncQueue',
10
- 'StatusTracker'
11
- ]
lionagi/objs/abc_objs.py DELETED
@@ -1,39 +0,0 @@
1
- from abc import abstractmethod, ABC, abstractproperty
2
- from typing import Any, Dict, NoReturn
3
-
4
-
5
- class BaseService(ABC):
6
-
7
- @abstractmethod
8
- def __init__(self) -> None:
9
- ...
10
-
11
- @abstractmethod
12
- async def serve(self) -> Any:
13
- ...
14
-
15
-
16
- class RateLimiter(ABC):
17
-
18
- def __init__(self, max_requests_per_minute: int, max_tokens_per_minute: int) -> None:
19
- self.max_requests_per_minute = max_requests_per_minute
20
- self.max_tokens_per_minute = max_tokens_per_minute
21
- self.available_request_capacity = max_requests_per_minute
22
- self.available_token_capacity = max_tokens_per_minute
23
-
24
- @abstractmethod
25
- async def rate_limit_replenisher(self) -> NoReturn:
26
- ...
27
-
28
- @abstractmethod
29
- def calculate_num_token(self, payload: Dict[str, Any], api_endpoint: str) -> int:
30
- ...
31
-
32
-
33
- class BaseEndpoint(ABC):
34
-
35
- endpoint: str = abstractproperty()
36
-
37
- @abstractmethod
38
- def create_payload(self, **kwargs):
39
- ...
@@ -1,135 +0,0 @@
1
- import asyncio
2
- from typing import Any, Callable
3
-
4
- class AsyncQueue:
5
- """
6
- A queue class that handles asynchronous operations using asyncio.
7
-
8
- This class provides an asynchronous queue that can enqueue items, process them
9
- asynchronously, and support graceful shutdowns. It is designed to facilitate
10
- concurrent task processing in an orderly and controlled manner.
11
-
12
- Attributes:
13
- queue (asyncio.Queue):
14
- A queue to hold items for asynchronous processing.
15
- _stop_event (asyncio.Event):
16
- An event to signal when the queue should stop processing.
17
-
18
- Methods:
19
- enqueue(item):
20
- Add an item to the queue for processing.
21
- dequeue():
22
- Remove and return an item from the queue.
23
- join():
24
- Wait until all items in the queue have been processed.
25
- stop():
26
- Signal to stop processing new items in the queue.
27
- stopped():
28
- Check if the queue has been signaled to stop.
29
- process_requests(func):
30
- Process items using a provided function.
31
- """
32
-
33
- def __init__(self) -> None:
34
- """
35
- Initializes an AsyncQueue object with an empty asyncio Queue and a stop event.
36
- """
37
- self.queue = asyncio.Queue()
38
- self._stop_event = asyncio.Event()
39
-
40
- async def enqueue(self, item: Any) -> None:
41
- """
42
- Asynchronously add an item to the queue for processing.
43
-
44
- Parameters:
45
- item (Any): The item to be added to the queue.
46
-
47
- Example:
48
- >>> async_queue = AsyncQueue()
49
- >>> asyncio.run(async_queue.enqueue('Task 1'))
50
- """
51
- await self.queue.put(item)
52
-
53
- async def dequeue(self) -> Any:
54
- """
55
- Asynchronously remove and return an item from the queue.
56
-
57
- If the queue is empty, this method will wait until an item is available.
58
-
59
- Returns:
60
- Any: The next item from the queue.
61
-
62
- Example:
63
- >>> async_queue = AsyncQueue()
64
- >>> asyncio.run(async_queue.enqueue('Task 1'))
65
- >>> asyncio.run(async_queue.dequeue())
66
- 'Task 1'
67
- """
68
- return await self.queue.get()
69
-
70
- async def join(self) -> None:
71
- """
72
- Asynchronously wait until all items in the queue have been processed.
73
-
74
- This method blocks until every item that has been enqueued is processed,
75
- ensuring that all tasks are completed.
76
-
77
- Example:
78
- >>> async_queue = AsyncQueue()
79
- >>> asyncio.run(async_queue.enqueue('Task 1'))
80
- >>> asyncio.run(async_queue.join()) # This will block until 'Task 1' is processed.
81
- """
82
- await self.queue.join()
83
-
84
- async def stop(self) -> None:
85
- """
86
- Signal the queue to stop processing new items.
87
-
88
- Once called, the queue will not process any new items after the current ones
89
- are completed, allowing for a graceful shutdown.
90
-
91
- Example:
92
- >>> async_queue = AsyncQueue()
93
- >>> asyncio.run(async_queue.stop()) # This signals the queue to stop processing.
94
- """
95
- self._stop_event.set()
96
-
97
- def stopped(self) -> bool:
98
- """
99
- Check if the queue has been signaled to stop processing.
100
-
101
- Returns:
102
- bool: True if a stop has been signaled, False otherwise.
103
-
104
- Example:
105
- >>> async_queue = AsyncQueue()
106
- >>> asyncio.run(async_queue.stop())
107
- >>> async_queue.stopped()
108
- True
109
- """
110
- return self._stop_event.is_set()
111
-
112
- async def process_requests(self, func: Callable[[Any], Any]) -> None:
113
- """
114
- Asynchronously process items from the queue using the provided function.
115
-
116
- Continuously dequeues items and applies the given function to each.
117
- The processing stops when the queue is signaled to stop or a sentinel value (`None`) is dequeued.
118
-
119
- Parameters:
120
- func (Callable[[Any], Any]): A coroutine function to process items from the queue.
121
-
122
- Example:
123
- >>> async def sample_processing(task):
124
- ... print("Processing:", task)
125
- >>> async_queue = AsyncQueue()
126
- >>> asyncio.run(async_queue.enqueue('Task 1'))
127
- >>> asyncio.run(async_queue.process_requests(sample_processing))
128
- Processing: Task 1
129
- """
130
- while not self.stopped():
131
- item = await self.dequeue()
132
- if item is None: # Using `None` as a sentinel value to cease processing.
133
- await self.stop()
134
- break
135
- await func(item)
lionagi/objs/messenger.py DELETED
@@ -1,85 +0,0 @@
1
- from collections import deque
2
- from typing import Optional, Any, Union, Dict, Tuple
3
-
4
- from lionagi.utils.call_util import lcall
5
- from lionagi.schema.data_logger import DataLogger
6
- from lionagi.messages import Message, Response, Instruction, System
7
-
8
-
9
- class Messenger:
10
-
11
- def __init__(self) -> None:
12
- self._logger = DataLogger()
13
-
14
- def set_dir(self, dir: str) -> None:
15
- self._logger.dir = dir
16
-
17
- def set_log(self, log) -> None:
18
- self._logger.log = log
19
-
20
- def log_message(self, msg: Message) -> None:
21
- self._logger(msg.to_json())
22
-
23
- def to_csv(self, **kwargs) -> None:
24
- self._logger.to_csv(**kwargs)
25
-
26
- def clear_log(self):
27
- self._logger.log = deque()
28
-
29
- def _create_message(
30
- self,
31
- system: Optional[Any] = None,
32
- instruction: Optional[Any] = None,
33
- context: Optional[Any] = None,
34
- response: Optional[Any] = None,
35
- name: Optional[str] = None
36
- ) -> Message:
37
-
38
- if sum(lcall([system, instruction, response], bool)) != 1:
39
- raise ValueError("Error: Message must have one and only one role.")
40
-
41
- else:
42
- msg = 0
43
-
44
- if response:
45
- msg = Response()
46
- msg._create_message(
47
- response=response, name=name,
48
- )
49
- elif instruction:
50
- msg = Instruction()
51
- msg._create_message(
52
- instruction=instruction, context=context,
53
- name=name,
54
- )
55
- elif system:
56
- msg = System()
57
- msg._create_message(
58
- system=system, name=name,
59
- )
60
- return msg
61
-
62
- def create_message(
63
- self,
64
- system: Optional[Any] = None,
65
- instruction: Optional[Any] = None,
66
- context: Optional[Any] = None,
67
- response: Optional[Any] = None,
68
- name: Optional[str] = None,
69
- obj: bool = True,
70
- log_: bool = True
71
- ) -> Union[Message, Tuple[Message, Dict]]:
72
-
73
- msg = self._create_message(
74
- system=system,
75
- instruction=instruction,
76
- context=context,
77
- response=response,
78
- name=name
79
- )
80
-
81
- if log_:
82
- self.log_message(msg)
83
- if obj:
84
- return msg
85
-