dm-aioaiagent 0.4.7__tar.gz → 0.4.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/PKG-INFO +28 -27
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/README.md +25 -24
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent/ai_agent.py +27 -25
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent/async_ai_agent.py +11 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent.egg-info/PKG-INFO +28 -27
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent.egg-info/requires.txt +1 -1
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/setup.py +2 -2
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent/__init__.py +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent/openai_image_message_content.py +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent/types.py +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent.egg-info/SOURCES.txt +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent.egg-info/dependency_links.txt +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/dm_aioaiagent.egg-info/top_level.txt +0 -0
- {dm_aioaiagent-0.4.7 → dm_aioaiagent-0.4.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: dm-aioaiagent
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.9
|
|
4
4
|
Summary: This is my custom aioaiagent client
|
|
5
5
|
Home-page: https://pypi.org/project/dm-aioaiagent
|
|
6
6
|
Author: dimka4621
|
|
@@ -12,7 +12,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Requires-Python: >=3.9
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
|
-
Requires-Dist: dm-logger~=0.
|
|
15
|
+
Requires-Dist: dm-logger~=0.6.2
|
|
16
16
|
Requires-Dist: python-dotenv>=1.0.0
|
|
17
17
|
Requires-Dist: pydantic<3.0.0,>=2.9.2
|
|
18
18
|
Requires-Dist: langchain~=0.3.0
|
|
@@ -48,6 +48,16 @@ Dynamic: summary
|
|
|
48
48
|
|
|
49
49
|
Analogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.
|
|
50
50
|
|
|
51
|
+
### Windows Setup
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
import sys
|
|
56
|
+
|
|
57
|
+
if sys.platform == "win32":
|
|
58
|
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
59
|
+
```
|
|
60
|
+
|
|
51
61
|
### Use agent *with* inner memory and run *single* message
|
|
52
62
|
|
|
53
63
|
By default, agent use inner memory to store the conversation history.
|
|
@@ -172,30 +182,21 @@ if __name__ == "__main__":
|
|
|
172
182
|
|
|
173
183
|
### Set custom logger
|
|
174
184
|
|
|
175
|
-
_If you want set up custom logger_
|
|
176
|
-
|
|
177
185
|
```python
|
|
178
|
-
from dm_aioaiagent import
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def error(self, message):
|
|
193
|
-
print(message)
|
|
194
|
-
|
|
186
|
+
from dm_aioaiagent import DMAIAgent
|
|
187
|
+
from dm_logger import FormatterConfig
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
# set up custom logger for all clients
|
|
191
|
+
DMAIAgent.set_logger_params(
|
|
192
|
+
{
|
|
193
|
+
"name": "my_name",
|
|
194
|
+
"formatter_config": FormatterConfig(
|
|
195
|
+
show_datetime=False,
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
```
|
|
195
200
|
|
|
196
|
-
|
|
197
|
-
ai_agent = DMAioAIAgent()
|
|
201
|
+
See more about DMLogger [here](https://github.com/MykhLibs/dm-logger)
|
|
198
202
|
|
|
199
|
-
# set up custom logger for this agent
|
|
200
|
-
ai_agent.set_logger(MyLogger())
|
|
201
|
-
```
|
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
Analogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.
|
|
13
13
|
|
|
14
|
+
### Windows Setup
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import asyncio
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
if sys.platform == "win32":
|
|
21
|
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
22
|
+
```
|
|
23
|
+
|
|
14
24
|
### Use agent *with* inner memory and run *single* message
|
|
15
25
|
|
|
16
26
|
By default, agent use inner memory to store the conversation history.
|
|
@@ -135,30 +145,21 @@ if __name__ == "__main__":
|
|
|
135
145
|
|
|
136
146
|
### Set custom logger
|
|
137
147
|
|
|
138
|
-
_If you want set up custom logger_
|
|
139
|
-
|
|
140
148
|
```python
|
|
141
|
-
from dm_aioaiagent import
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def error(self, message):
|
|
156
|
-
print(message)
|
|
157
|
-
|
|
149
|
+
from dm_aioaiagent import DMAIAgent
|
|
150
|
+
from dm_logger import FormatterConfig
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# set up custom logger for all clients
|
|
154
|
+
DMAIAgent.set_logger_params(
|
|
155
|
+
{
|
|
156
|
+
"name": "my_name",
|
|
157
|
+
"formatter_config": FormatterConfig(
|
|
158
|
+
show_datetime=False,
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
```
|
|
158
163
|
|
|
159
|
-
|
|
160
|
-
ai_agent = DMAioAIAgent()
|
|
164
|
+
See more about DMLogger [here](https://github.com/MykhLibs/dm-logger)
|
|
161
165
|
|
|
162
|
-
# set up custom logger for this agent
|
|
163
|
-
ai_agent.set_logger(MyLogger())
|
|
164
|
-
```
|
|
@@ -18,6 +18,7 @@ __all__ = ["DMAIAgent"]
|
|
|
18
18
|
class DMAIAgent:
|
|
19
19
|
MAX_MEMORY_MESSAGES = 20 # Only INT greater than 0
|
|
20
20
|
_ALLOWED_ROLES = ("user", "ai")
|
|
21
|
+
_logger_params = None
|
|
21
22
|
|
|
22
23
|
def __init__(
|
|
23
24
|
self,
|
|
@@ -25,8 +26,8 @@ class DMAIAgent:
|
|
|
25
26
|
tools: list[BaseTool] = None,
|
|
26
27
|
*,
|
|
27
28
|
model: str = "gpt-4o-mini",
|
|
28
|
-
temperature:
|
|
29
|
-
parallel_tool_calls: bool =
|
|
29
|
+
temperature: float = None,
|
|
30
|
+
parallel_tool_calls: bool = None,
|
|
30
31
|
agent_name: str = "AIAgent",
|
|
31
32
|
input_output_logging: bool = True,
|
|
32
33
|
is_memory_enabled: bool = True,
|
|
@@ -37,15 +38,15 @@ class DMAIAgent:
|
|
|
37
38
|
response_if_request_fail: str = "I can't provide a response right now. Please try again later.",
|
|
38
39
|
response_if_invalid_image: str = "The image is unavailable or the link is incorrect."
|
|
39
40
|
):
|
|
40
|
-
self.
|
|
41
|
+
self._set_logger(agent_name)
|
|
41
42
|
self._input_output_logging = bool(input_output_logging)
|
|
42
43
|
|
|
43
44
|
self._system_message = str(system_message)
|
|
44
45
|
self._tools = tools or []
|
|
45
46
|
self._is_tools_exists = bool(tools)
|
|
46
47
|
self._model = str(model)
|
|
47
|
-
self._temperature =
|
|
48
|
-
self._parallel_tool_calls =
|
|
48
|
+
self._temperature = temperature
|
|
49
|
+
self._parallel_tool_calls = parallel_tool_calls
|
|
49
50
|
self._llm_provider_api_key = str(llm_provider_api_key)
|
|
50
51
|
self._llm_provider_base_url = str(llm_provider_base_url)
|
|
51
52
|
|
|
@@ -193,27 +194,28 @@ class DMAIAgent:
|
|
|
193
194
|
return route
|
|
194
195
|
|
|
195
196
|
def _init_agent(self) -> None:
|
|
196
|
-
base_kwargs = {
|
|
197
|
-
|
|
198
|
-
"temperature"
|
|
199
|
-
"base_url": self._llm_provider_base_url if self._llm_provider_base_url else None
|
|
200
|
-
}
|
|
197
|
+
base_kwargs = {"model": self._model}
|
|
198
|
+
if isinstance(self._temperature, float):
|
|
199
|
+
base_kwargs["temperature"] = self._temperature
|
|
201
200
|
if self._llm_provider_api_key:
|
|
202
201
|
base_kwargs["api_key"] = SecretStr(self._llm_provider_api_key)
|
|
202
|
+
if self._llm_provider_base_url:
|
|
203
|
+
base_kwargs["base_url"] = self._llm_provider_base_url
|
|
203
204
|
|
|
204
205
|
if self._model.startswith("claude"):
|
|
205
206
|
from langchain_anthropic import ChatAnthropic
|
|
206
207
|
|
|
207
208
|
llm = ChatAnthropic(**base_kwargs)
|
|
208
|
-
bind_tool_kwargs = {"tool_choice": {
|
|
209
|
-
|
|
210
|
-
"disable_parallel_tool_use"
|
|
211
|
-
}}
|
|
209
|
+
bind_tool_kwargs = {"tool_choice": {"type": "auto"}}
|
|
210
|
+
if isinstance(self._parallel_tool_calls, bool):
|
|
211
|
+
bind_tool_kwargs["tool_choice"]["disable_parallel_tool_use"] = not self._parallel_tool_calls
|
|
212
212
|
else:
|
|
213
213
|
from langchain_openai import ChatOpenAI
|
|
214
214
|
|
|
215
215
|
llm = ChatOpenAI(**base_kwargs)
|
|
216
|
-
bind_tool_kwargs = {
|
|
216
|
+
bind_tool_kwargs = {}
|
|
217
|
+
if isinstance(self._parallel_tool_calls, bool):
|
|
218
|
+
bind_tool_kwargs["parallel_tool_calls"] = self._parallel_tool_calls
|
|
217
219
|
|
|
218
220
|
if self._is_tools_exists:
|
|
219
221
|
self._tool_map = {t.name: t for t in self._tools}
|
|
@@ -264,13 +266,13 @@ class DMAIAgent:
|
|
|
264
266
|
except Exception as e:
|
|
265
267
|
self._logger.error(e)
|
|
266
268
|
|
|
267
|
-
def
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
269
|
+
def _set_logger(self, agent_name: str) -> None:
|
|
270
|
+
params = {"name": agent_name}
|
|
271
|
+
if isinstance(self._logger_params, dict):
|
|
272
|
+
params.update(self._logger_params)
|
|
273
|
+
self._logger = DMLogger(**params)
|
|
274
|
+
|
|
275
|
+
@classmethod
|
|
276
|
+
def set_logger_params(cls, extra_params = None) -> None:
|
|
277
|
+
if isinstance(extra_params, dict) or extra_params is None:
|
|
278
|
+
cls._logger_params = extra_params
|
|
@@ -10,6 +10,17 @@ __all__ = ["DMAioAIAgent"]
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class DMAioAIAgent(DMAIAgent):
|
|
13
|
+
_logger_params = None
|
|
14
|
+
|
|
15
|
+
def __init__(self, *args, agent_name: str = "AioAIAgent", **kwargs):
|
|
16
|
+
super().__init__(*args, **kwargs)
|
|
17
|
+
|
|
18
|
+
if not isinstance(self._logger_params, dict):
|
|
19
|
+
self._logger_params = {}
|
|
20
|
+
if "name" not in self._logger_params:
|
|
21
|
+
self._logger_params["name"] = agent_name
|
|
22
|
+
self._set_logger(agent_name)
|
|
23
|
+
|
|
13
24
|
async def run(self, query: str, *args, **kwargs) -> str:
|
|
14
25
|
new_messages = await self.run_messages(messages=[{"role": "user", "content": query}], *args, **kwargs)
|
|
15
26
|
return new_messages[-1].content
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: dm-aioaiagent
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.9
|
|
4
4
|
Summary: This is my custom aioaiagent client
|
|
5
5
|
Home-page: https://pypi.org/project/dm-aioaiagent
|
|
6
6
|
Author: dimka4621
|
|
@@ -12,7 +12,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Requires-Python: >=3.9
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
|
-
Requires-Dist: dm-logger~=0.
|
|
15
|
+
Requires-Dist: dm-logger~=0.6.2
|
|
16
16
|
Requires-Dist: python-dotenv>=1.0.0
|
|
17
17
|
Requires-Dist: pydantic<3.0.0,>=2.9.2
|
|
18
18
|
Requires-Dist: langchain~=0.3.0
|
|
@@ -48,6 +48,16 @@ Dynamic: summary
|
|
|
48
48
|
|
|
49
49
|
Analogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.
|
|
50
50
|
|
|
51
|
+
### Windows Setup
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
import sys
|
|
56
|
+
|
|
57
|
+
if sys.platform == "win32":
|
|
58
|
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
59
|
+
```
|
|
60
|
+
|
|
51
61
|
### Use agent *with* inner memory and run *single* message
|
|
52
62
|
|
|
53
63
|
By default, agent use inner memory to store the conversation history.
|
|
@@ -172,30 +182,21 @@ if __name__ == "__main__":
|
|
|
172
182
|
|
|
173
183
|
### Set custom logger
|
|
174
184
|
|
|
175
|
-
_If you want set up custom logger_
|
|
176
|
-
|
|
177
185
|
```python
|
|
178
|
-
from dm_aioaiagent import
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def error(self, message):
|
|
193
|
-
print(message)
|
|
194
|
-
|
|
186
|
+
from dm_aioaiagent import DMAIAgent
|
|
187
|
+
from dm_logger import FormatterConfig
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
# set up custom logger for all clients
|
|
191
|
+
DMAIAgent.set_logger_params(
|
|
192
|
+
{
|
|
193
|
+
"name": "my_name",
|
|
194
|
+
"formatter_config": FormatterConfig(
|
|
195
|
+
show_datetime=False,
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
```
|
|
195
200
|
|
|
196
|
-
|
|
197
|
-
ai_agent = DMAioAIAgent()
|
|
201
|
+
See more about DMLogger [here](https://github.com/MykhLibs/dm-logger)
|
|
198
202
|
|
|
199
|
-
# set up custom logger for this agent
|
|
200
|
-
ai_agent.set_logger(MyLogger())
|
|
201
|
-
```
|
|
@@ -8,7 +8,7 @@ def readme():
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name='dm-aioaiagent',
|
|
11
|
-
version='v0.4.
|
|
11
|
+
version='v0.4.9',
|
|
12
12
|
author='dimka4621',
|
|
13
13
|
author_email='mismartconfig@gmail.com',
|
|
14
14
|
description='This is my custom aioaiagent client',
|
|
@@ -17,7 +17,7 @@ setup(
|
|
|
17
17
|
url='https://pypi.org/project/dm-aioaiagent',
|
|
18
18
|
packages=find_packages(),
|
|
19
19
|
install_requires=[
|
|
20
|
-
'dm-logger~=0.
|
|
20
|
+
'dm-logger~=0.6.2',
|
|
21
21
|
'python-dotenv>=1.0.0',
|
|
22
22
|
'pydantic>=2.9.2, < 3.0.0',
|
|
23
23
|
'langchain~=0.3.0',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|