lionagi 0.0.106__tar.gz → 0.0.107__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {lionagi-0.0.106 → lionagi-0.0.107}/PKG-INFO +7 -12
- {lionagi-0.0.106 → lionagi-0.0.107}/README.md +6 -11
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/api/oai_service.py +25 -13
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/session/conversation.py +18 -9
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/session/message.py +38 -14
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/session/session.py +122 -55
- lionagi-0.0.107/lionagi/utils/__init__.py +7 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/utils/api_util.py +91 -45
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/utils/doc_util.py +69 -26
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/utils/log_util.py +15 -4
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/utils/sys_util.py +74 -11
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/utils/tool_util.py +39 -24
- lionagi-0.0.107/lionagi/version.py +1 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi.egg-info/PKG-INFO +7 -12
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi.egg-info/SOURCES.txt +0 -1
- lionagi-0.0.106/lionagi/tools/__init__.py +0 -0
- lionagi-0.0.106/lionagi/utils/__init__.py +0 -10
- lionagi-0.0.106/lionagi/version.py +0 -1
- {lionagi-0.0.106 → lionagi-0.0.107}/LICENSE +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/README.rst +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/__init__.py +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/api/__init__.py +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/api/oai_config.py +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi/session/__init__.py +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi.egg-info/dependency_links.txt +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi.egg-info/requires.txt +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/lionagi.egg-info/top_level.txt +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/pyproject.toml +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/setup.cfg +0 -0
- {lionagi-0.0.106 → lionagi-0.0.107}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lionagi
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.107
|
4
4
|
Summary: Towards automated general intelligence.
|
5
5
|
Author: HaiyangLi
|
6
6
|
Author-email: Haiyang Li <ocean@lionagi.ai>
|
@@ -222,18 +222,13 @@ Requires-Dist: httpx==0.25.1
|
|
222
222
|
|
223
223
|
![PyPI - Version](https://img.shields.io/pypi/v/lionagi?labelColor=233476aa&color=231fc935) ![PyPI - Downloads](https://img.shields.io/pypi/dm/lionagi?labelColor=233476aa&color=231fc935) ![GitHub License](https://img.shields.io/github/license/lion-agi/lionagi?labelColor=233476aa&color=231fc935)
|
224
224
|
|
225
|
-
|
226
|
-
|
227
|
-
- PyPI: https://pypi.org/project/lionagi/
|
228
|
-
- Documentation: https://lionagi.readthedocs.io/en/latest/ (still a lot TODO)
|
229
|
-
- Website: TODO
|
230
|
-
- Discord: [Join Our Discord](https://discord.gg/7RGWqpSxze)
|
225
|
+
[PyPI](https://pypi.org/project/lionagi/) | [Documentation](https://lionagi.readthedocs.io/en/latest/) | [Website](https://www.lionagi.ai) | [Discord](https://discord.gg/7RGWqpSxze)
|
231
226
|
|
232
227
|
|
233
228
|
# LionAGI
|
234
229
|
**Towards Automated General Intelligence**
|
235
230
|
|
236
|
-
LionAGI is a Python
|
231
|
+
LionAGI is a Python intelligent agent framework that combines data manipulation with AI tools, aiming to simplify the integration of advanced machine learning tools, such as Large Language Models (i.e. OpenAI's GPT), with production-level data-centric projects.
|
237
232
|
|
238
233
|
Install LionAGI with pip:
|
239
234
|
|
@@ -244,13 +239,13 @@ Download the `.env_template` file, input your OPENAI_API_KEY, save the file, ren
|
|
244
239
|
|
245
240
|
### Features
|
246
241
|
|
247
|
-
- Robust performance. LionAGI is written in almost pure python. With minimum external dependency (aiohttp
|
242
|
+
- Robust performance. LionAGI is written in almost pure python. With minimum external dependency (`aiohttp`, `httpx`, `python-dotenv`, `tiktoken`)
|
248
243
|
- Efficient data operations for reading, chunking, binning, writing, storing and managing data.
|
249
|
-
- Fast interaction with LLM services like OpenAI with configurable rate limiting concurrent API calls for maximum throughput.
|
250
|
-
- Create a production ready LLM application in hours
|
244
|
+
- Fast interaction with LLM services like OpenAI with **configurable rate limiting concurrent API calls** for maximum throughput.
|
245
|
+
- Create a production ready LLM application **in hours**. Intuitive workflow management to streamline and expedite the process from idea to market.
|
251
246
|
|
252
247
|
---
|
253
|
-
Currently, LionAGI only natively support OpenAI API calls, support for other LLM providers as well as open source models will be integrated in future releases. LionAGI is designed to be async only, please check python documentation [here](https://docs.python.org/3/library/asyncio.html)
|
248
|
+
Currently, LionAGI only natively support OpenAI API calls, support for other LLM providers as well as open source models will be integrated in future releases. LionAGI is designed to be async only, please check python official documentation on how `async` work: [here](https://docs.python.org/3/library/asyncio.html)
|
254
249
|
|
255
250
|
|
256
251
|
**Notice**:
|
@@ -1,17 +1,12 @@
|
|
1
1
|
![PyPI - Version](https://img.shields.io/pypi/v/lionagi?labelColor=233476aa&color=231fc935) ![PyPI - Downloads](https://img.shields.io/pypi/dm/lionagi?labelColor=233476aa&color=231fc935) ![GitHub License](https://img.shields.io/github/license/lion-agi/lionagi?labelColor=233476aa&color=231fc935)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
- PyPI: https://pypi.org/project/lionagi/
|
6
|
-
- Documentation: https://lionagi.readthedocs.io/en/latest/ (still a lot TODO)
|
7
|
-
- Website: TODO
|
8
|
-
- Discord: [Join Our Discord](https://discord.gg/7RGWqpSxze)
|
3
|
+
[PyPI](https://pypi.org/project/lionagi/) | [Documentation](https://lionagi.readthedocs.io/en/latest/) | [Website](https://www.lionagi.ai) | [Discord](https://discord.gg/7RGWqpSxze)
|
9
4
|
|
10
5
|
|
11
6
|
# LionAGI
|
12
7
|
**Towards Automated General Intelligence**
|
13
8
|
|
14
|
-
LionAGI is a Python
|
9
|
+
LionAGI is a Python intelligent agent framework that combines data manipulation with AI tools, aiming to simplify the integration of advanced machine learning tools, such as Large Language Models (i.e. OpenAI's GPT), with production-level data-centric projects.
|
15
10
|
|
16
11
|
Install LionAGI with pip:
|
17
12
|
|
@@ -22,13 +17,13 @@ Download the `.env_template` file, input your OPENAI_API_KEY, save the file, ren
|
|
22
17
|
|
23
18
|
### Features
|
24
19
|
|
25
|
-
- Robust performance. LionAGI is written in almost pure python. With minimum external dependency (aiohttp
|
20
|
+
- Robust performance. LionAGI is written in almost pure python. With minimum external dependency (`aiohttp`, `httpx`, `python-dotenv`, `tiktoken`)
|
26
21
|
- Efficient data operations for reading, chunking, binning, writing, storing and managing data.
|
27
|
-
- Fast interaction with LLM services like OpenAI with configurable rate limiting concurrent API calls for maximum throughput.
|
28
|
-
- Create a production ready LLM application in hours
|
22
|
+
- Fast interaction with LLM services like OpenAI with **configurable rate limiting concurrent API calls** for maximum throughput.
|
23
|
+
- Create a production ready LLM application **in hours**. Intuitive workflow management to streamline and expedite the process from idea to market.
|
29
24
|
|
30
25
|
---
|
31
|
-
Currently, LionAGI only natively support OpenAI API calls, support for other LLM providers as well as open source models will be integrated in future releases. LionAGI is designed to be async only, please check python documentation [here](https://docs.python.org/3/library/asyncio.html)
|
26
|
+
Currently, LionAGI only natively support OpenAI API calls, support for other LLM providers as well as open source models will be integrated in future releases. LionAGI is designed to be async only, please check python official documentation on how `async` work: [here](https://docs.python.org/3/library/asyncio.html)
|
32
27
|
|
33
28
|
|
34
29
|
**Notice**:
|
@@ -19,20 +19,25 @@ class OpenAIRateLimiter(RateLimiter):
|
|
19
19
|
and replenishing these limits at regular intervals.
|
20
20
|
|
21
21
|
Attributes:
|
22
|
-
max_requests_per_minute (int):
|
23
|
-
|
22
|
+
max_requests_per_minute (int):
|
23
|
+
Maximum number of requests allowed per minute.
|
24
|
+
max_tokens_per_minute (int):
|
25
|
+
Maximum number of tokens allowed per minute.
|
24
26
|
|
25
27
|
Methods:
|
26
|
-
rate_limit_replenisher:
|
27
|
-
|
28
|
+
rate_limit_replenisher:
|
29
|
+
Coroutine to replenish rate limits over time.
|
30
|
+
calculate_num_token:
|
31
|
+
Calculates the required tokens for a request.
|
28
32
|
"""
|
29
33
|
|
30
34
|
def __init__(self, max_requests_per_minute: int, max_tokens_per_minute: int) -> None:
|
31
35
|
"""
|
32
36
|
Initializes the rate limiter with specific limits for OpenAI API.
|
33
37
|
|
34
|
-
|
38
|
+
Parameters:
|
35
39
|
max_requests_per_minute (int): The maximum number of requests allowed per minute.
|
40
|
+
|
36
41
|
max_tokens_per_minute (int): The maximum number of tokens that can accumulate per minute.
|
37
42
|
"""
|
38
43
|
super().__init__(max_requests_per_minute, max_tokens_per_minute)
|
@@ -66,8 +71,9 @@ class OpenAIRateLimiter(RateLimiter):
|
|
66
71
|
This method should be implemented in a subclass to provide the specific calculation logic
|
67
72
|
for the OpenAI API.
|
68
73
|
|
69
|
-
|
74
|
+
Parameters:
|
70
75
|
payload (Dict[str, Any]): The payload of the request.
|
76
|
+
|
71
77
|
api_endpoint (str): The specific API endpoint for the request.
|
72
78
|
|
73
79
|
Returns:
|
@@ -160,12 +166,17 @@ class OpenAIService(BaseAPIService):
|
|
160
166
|
"""
|
161
167
|
Initializes the OpenAI service with configuration for API interaction.
|
162
168
|
|
163
|
-
|
169
|
+
Parameters:
|
164
170
|
api_key (str): The API key for authenticating with OpenAI.
|
171
|
+
|
165
172
|
token_encoding_name (str): The name of the text encoding used by OpenAI.
|
173
|
+
|
166
174
|
max_attempts (int): The maximum number of attempts for calling an API endpoint.
|
175
|
+
|
167
176
|
status_tracker (Optional[StatusTracker]): Tracker for API call outcomes.
|
168
|
-
|
177
|
+
|
178
|
+
ratelimiter (Optional[OpenAIRateLimiter]): Rate limiter for OpenAI's limits.
|
179
|
+
|
169
180
|
queue (Optional[AsyncQueue]): Queue for managing asynchronous API calls.
|
170
181
|
|
171
182
|
Example:
|
@@ -183,15 +194,16 @@ class OpenAIService(BaseAPIService):
|
|
183
194
|
super().__init__(api_key, token_encoding_name, max_attempts,
|
184
195
|
max_requests_per_minute, max_tokens_per_minute,
|
185
196
|
ratelimiter, status_tracker, queue)
|
186
|
-
|
187
197
|
|
188
|
-
async def call_api(self, http_session, endpoint, payload: Dict[str, any] =None) -> Optional[Dict[str, any]]:
|
198
|
+
async def call_api(self, http_session, endpoint, payload: Dict[str, any] = None) -> Optional[Dict[str, any]]:
|
189
199
|
"""
|
190
200
|
Call an OpenAI API endpoint with a specific payload and handle the response.
|
191
201
|
|
192
|
-
|
193
|
-
|
194
|
-
|
202
|
+
Parameters:
|
203
|
+
http_session: The session object for making HTTP requests.
|
204
|
+
|
205
|
+
endpoint (str): The full URL of the OpenAI API endpoint to be called.
|
206
|
+
|
195
207
|
payload (Dict[str, any]): The payload to send with the API request.
|
196
208
|
|
197
209
|
Returns:
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from .message import Message
|
2
2
|
|
3
|
+
|
3
4
|
class Conversation:
|
4
5
|
"""
|
5
6
|
A class representing a conversation between users and the assistant.
|
@@ -8,21 +9,22 @@ class Conversation:
|
|
8
9
|
user instructions, and assistant responses.
|
9
10
|
|
10
11
|
Attributes:
|
11
|
-
response_counts (int):
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
response_counts (int):
|
13
|
+
The count of assistant responses in the conversation.
|
14
|
+
messages (list):
|
15
|
+
A list to store messages in the conversation.
|
16
|
+
msg (Message):
|
17
|
+
An instance of the Message class for creating messages.
|
18
|
+
responses (list):
|
19
|
+
A list to store assistant responses in the conversation.
|
15
20
|
|
16
21
|
Methods:
|
17
22
|
initiate_conversation(system, instruction, context=None, name=None):
|
18
23
|
Initiate a conversation with a system setting and user instruction.
|
19
|
-
|
20
24
|
add_messages(system, instruction, context=None, response=None, tool=None, name=None):
|
21
25
|
Add messages to the conversation, including system setting, user instruction, and assistant response.
|
22
|
-
|
23
26
|
change_system(system):
|
24
27
|
Change the system setting in the conversation.
|
25
|
-
|
26
28
|
keep_last_n_exchanges(n: int):
|
27
29
|
Keep the last n exchanges in the conversation.
|
28
30
|
"""
|
@@ -46,8 +48,11 @@ class Conversation:
|
|
46
48
|
|
47
49
|
Parameters:
|
48
50
|
system (str): The system setting for the conversation.
|
51
|
+
|
49
52
|
instruction (str): The user instruction to initiate the conversation.
|
53
|
+
|
50
54
|
context (dict): Additional context for the conversation. Default is None.
|
55
|
+
|
51
56
|
name (str): The name associated with the user. Default is None.
|
52
57
|
"""
|
53
58
|
self.messages, self.responses = [], []
|
@@ -61,10 +66,13 @@ class Conversation:
|
|
61
66
|
|
62
67
|
Parameters:
|
63
68
|
system (str): The system setting for the message. Default is None.
|
69
|
+
|
64
70
|
instruction (str): The instruction content for the message. Default is None.
|
71
|
+
|
65
72
|
context (dict): Additional context for the message. Default is None.
|
73
|
+
|
66
74
|
response (dict): The response content for the message. Default is None.
|
67
|
-
|
75
|
+
|
68
76
|
name (str): The name associated with the message. Default is None.
|
69
77
|
"""
|
70
78
|
msg = self.msg(system=system, instruction=instruction, context=context,
|
@@ -93,4 +101,5 @@ class Conversation:
|
|
93
101
|
]
|
94
102
|
if len(response_indices) >= n:
|
95
103
|
first_index_to_keep = response_indices[-n] + 1
|
96
|
-
self.messages =
|
104
|
+
self.messages = self.messages[0] + self.messages[first_index_to_keep:]
|
105
|
+
|
@@ -11,11 +11,16 @@ class Message:
|
|
11
11
|
This class encapsulates messages from users, the assistant, systems, and external tools.
|
12
12
|
|
13
13
|
Attributes:
|
14
|
-
role (str):
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
role (str):
|
15
|
+
The role of the message, indicating if it's from the user, assistant, system, or tool.
|
16
|
+
content:
|
17
|
+
The content of the message, which can be an instruction, response, system setting, or tool information.
|
18
|
+
name (str):
|
19
|
+
The name associated with the message, specifying the source (user, assistant, system, or tool).
|
20
|
+
metadata (dict):
|
21
|
+
Additional metadata including id, timestamp, and name.
|
22
|
+
_logger (DataLogger):
|
23
|
+
An instance of the DataLogger class for logging message details.
|
19
24
|
|
20
25
|
Methods:
|
21
26
|
create_message(system, instruction, context, response, tool, name):
|
@@ -47,10 +52,13 @@ class Message:
|
|
47
52
|
|
48
53
|
Parameters:
|
49
54
|
system (str): The system setting for the message. Default is None.
|
55
|
+
|
50
56
|
instruction (str): The instruction content for the message. Default is None.
|
57
|
+
|
51
58
|
context (dict): Additional context for the message. Default is None.
|
59
|
+
|
52
60
|
response (dict): The response content for the message. Default is None.
|
53
|
-
|
61
|
+
|
54
62
|
name (str): The name associated with the message. Default is None.
|
55
63
|
"""
|
56
64
|
if sum(l_call([system, instruction, response], bool)) > 1:
|
@@ -63,10 +71,17 @@ class Message:
|
|
63
71
|
response = response["message"]
|
64
72
|
if str(response['content']) == "None":
|
65
73
|
try:
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
tool_count = 0
|
75
|
+
func_list = []
|
76
|
+
while tool_count < len(response['tool_calls']):
|
77
|
+
if response['tool_calls'][tool_count]['type'] == 'function':
|
78
|
+
func_content = {"function": ("func_" + response['tool_calls'][tool_count]['function']['name']),
|
79
|
+
"arguments": response['tool_calls'][tool_count]['function']['arguments']}
|
80
|
+
func_list.append(func_content)
|
81
|
+
tool_count += 1
|
82
|
+
|
83
|
+
self.name = name or "func_request"
|
84
|
+
self.content = {'function_list': func_list}
|
70
85
|
except:
|
71
86
|
raise ValueError("Response message must be one of regular response or function calling")
|
72
87
|
else:
|
@@ -74,7 +89,7 @@ class Message:
|
|
74
89
|
self.name = name or "assistant"
|
75
90
|
except:
|
76
91
|
self.name = name or "func_call"
|
77
|
-
self.content =
|
92
|
+
self.content = response
|
78
93
|
|
79
94
|
elif instruction:
|
80
95
|
self.role = "user"
|
@@ -92,7 +107,7 @@ class Message:
|
|
92
107
|
Convert the message to a JSON format.
|
93
108
|
|
94
109
|
Returns:
|
95
|
-
|
110
|
+
dict: The message in JSON format.
|
96
111
|
"""
|
97
112
|
out = {
|
98
113
|
"role": self.role,
|
@@ -114,11 +129,14 @@ class Message:
|
|
114
129
|
|
115
130
|
Parameters:
|
116
131
|
system (str): The system setting for the message. Default is None.
|
132
|
+
|
117
133
|
instruction (str): The instruction content for the message. Default is None.
|
134
|
+
|
118
135
|
context (dict): Additional context for the message. Default is None.
|
136
|
+
|
119
137
|
response (dict): The response content for the message. Default is None.
|
138
|
+
|
120
139
|
name (str): The name associated with the message. Default is None.
|
121
|
-
tool (dict): The tool information for the message. Default is None.
|
122
140
|
|
123
141
|
Returns:
|
124
142
|
dict: The message in JSON format.
|
@@ -133,10 +151,16 @@ class Message:
|
|
133
151
|
|
134
152
|
Parameters:
|
135
153
|
dir (str): The directory path for saving the CSV file. Default is None.
|
154
|
+
|
136
155
|
filename (str): The filename for the CSV file. Default is None.
|
156
|
+
|
137
157
|
verbose (bool): Whether to include verbose information in the CSV. Default is True.
|
158
|
+
|
138
159
|
timestamp (bool): Whether to include timestamps in the CSV. Default is True.
|
160
|
+
|
139
161
|
dir_exist_ok (bool): Whether to allow the directory to exist. Default is True.
|
162
|
+
|
140
163
|
file_exist_ok (bool): Whether to allow the file to exist. Default is False.
|
141
164
|
"""
|
142
|
-
self._logger.to_csv(dir, filename, verbose, timestamp, dir_exist_ok, file_exist_ok)
|
165
|
+
self._logger.to_csv(dir, filename, verbose, timestamp, dir_exist_ok, file_exist_ok)
|
166
|
+
|