agent-lab-sdk 0.1.26__tar.gz → 0.1.28__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.
Potentially problematic release.
This version of agent-lab-sdk might be problematic. Click here for more details.
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/PKG-INFO +1 -1
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/llm/llm.py +15 -12
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/llm/throttled.py +67 -35
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk.egg-info/PKG-INFO +1 -1
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/pyproject.toml +1 -1
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/LICENSE +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/README.md +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/langgraph/checkpoint/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/langgraph/checkpoint/agw_saver.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/llm/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/llm/agw_token_manager.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/llm/gigachat_token_manager.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/metrics/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/metrics/metrics.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/schema/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/schema/input_types.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/schema/log_message.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/storage/__init__.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/storage/storage.py +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk.egg-info/SOURCES.txt +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk.egg-info/dependency_links.txt +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk.egg-info/requires.txt +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk.egg-info/top_level.txt +0 -0
- {agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/setup.cfg +0 -0
|
@@ -5,10 +5,16 @@ from agent_lab_sdk.llm.throttled import ThrottledGigaChat, ThrottledGigaChatEmbe
|
|
|
5
5
|
from typing import Union
|
|
6
6
|
import os
|
|
7
7
|
|
|
8
|
-
def get_model(
|
|
8
|
+
def get_model(
|
|
9
|
+
type: str = "chat",
|
|
10
|
+
throttled: bool = False,
|
|
11
|
+
manage_access_token: bool = True,
|
|
12
|
+
**kwargs
|
|
13
|
+
) -> Union[GigaChat, GigaChatEmbeddings, ThrottledGigaChat, ThrottledGigaChatEmbeddings]:
|
|
9
14
|
"""
|
|
10
15
|
* type - определяет тип моледи : chat | embeddings
|
|
11
16
|
* throttled - оборачивает модель в класс обертку с дополнительным регулированием через семафор
|
|
17
|
+
* manage_access_token - включает режим авто-обновления токена в обёртках (только если throttled=True)
|
|
12
18
|
* kwargs - прокидываются в модель
|
|
13
19
|
"""
|
|
14
20
|
access_token = kwargs.pop("access_token", None)
|
|
@@ -22,17 +28,14 @@ def get_model(type="chat", throttled = False, **kwargs) -> Union[GigaChat, GigaC
|
|
|
22
28
|
verify_ssl_certs = os.getenv("GIGACHAT_VERIFY_SSL_CERTS", verify_ssl_certs)
|
|
23
29
|
|
|
24
30
|
if type == "chat":
|
|
25
|
-
_class = GigaChat
|
|
26
|
-
if throttled:
|
|
27
|
-
_class = ThrottledGigaChat
|
|
31
|
+
_class = ThrottledGigaChat if throttled else GigaChat
|
|
28
32
|
elif type == "embeddings":
|
|
29
|
-
_class = GigaChatEmbeddings
|
|
30
|
-
if throttled:
|
|
31
|
-
_class = ThrottledGigaChatEmbeddings
|
|
33
|
+
_class = ThrottledGigaChatEmbeddings if throttled else GigaChatEmbeddings
|
|
32
34
|
else:
|
|
33
35
|
raise ValueError(f"unsupported type {type}. possible values: chat, embeddings")
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
if throttled and manage_access_token:
|
|
38
|
+
# Включаем режим авто-обновления токена в обёртках
|
|
39
|
+
kwargs["manage_access_token"] = True
|
|
40
|
+
|
|
41
|
+
return _class(verify_ssl_certs=verify_ssl_certs, **kwargs)
|
|
@@ -2,6 +2,7 @@ import os
|
|
|
2
2
|
import asyncio
|
|
3
3
|
import threading
|
|
4
4
|
import time
|
|
5
|
+
from pydantic import PrivateAttr
|
|
5
6
|
from langchain_gigachat.chat_models import GigaChat
|
|
6
7
|
from langchain_gigachat import GigaChatEmbeddings
|
|
7
8
|
import langchain_gigachat.embeddings.gigachat
|
|
@@ -13,6 +14,7 @@ MAX_EMBED_CONCURRENCY = int(os.getenv("MAX_EMBED_CONCURRENCY", "100000"))
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
from agent_lab_sdk.metrics import get_metric
|
|
17
|
+
from agent_lab_sdk.llm.gigachat_token_manager import GigaChatTokenManager
|
|
16
18
|
|
|
17
19
|
def create_metrics(prefix: str):
|
|
18
20
|
in_use = get_metric(
|
|
@@ -107,71 +109,101 @@ _semaphores = {
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
class ThrottledGigaChatEmbeddings(GigaChatEmbeddings):
|
|
112
|
+
_manage_access_token: bool = PrivateAttr(default=True)
|
|
113
|
+
_base_kwargs: bool = PrivateAttr(default=True)
|
|
114
|
+
|
|
115
|
+
def __init__(self, *args, manage_access_token=True, **kwargs):
|
|
116
|
+
print(self)
|
|
117
|
+
self._manage_access_token = manage_access_token
|
|
118
|
+
self._base_kwargs = dict(kwargs)
|
|
119
|
+
|
|
120
|
+
if self._manage_access_token and "access_token" not in kwargs:
|
|
121
|
+
token = GigaChatTokenManager.get_token()
|
|
122
|
+
super().__init__(access_token=token, **kwargs)
|
|
123
|
+
else:
|
|
124
|
+
super().__init__(**kwargs)
|
|
125
|
+
|
|
126
|
+
def _fresh(self) -> GigaChatEmbeddings:
|
|
127
|
+
if self._manage_access_token:
|
|
128
|
+
return GigaChatEmbeddings(access_token=GigaChatTokenManager, **self._base_kwargs)
|
|
129
|
+
else:
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
|
|
110
133
|
def embed_documents(self, *args, **kwargs):
|
|
111
134
|
with _semaphores["embed"]:
|
|
112
|
-
return
|
|
135
|
+
return self._fresh().embed_documents(*args, **kwargs)
|
|
113
136
|
|
|
114
137
|
def embed_query(self, *args, **kwargs):
|
|
115
|
-
|
|
116
|
-
|
|
138
|
+
with _semaphores["embed"]:
|
|
139
|
+
return self._fresh().embed_query(*args, **kwargs)
|
|
117
140
|
|
|
118
141
|
async def aembed_documents(self, *args, **kwargs):
|
|
119
142
|
async with _semaphores["embed"]:
|
|
120
|
-
return await
|
|
143
|
+
return await self._fresh().aembed_documents(*args, **kwargs)
|
|
121
144
|
|
|
122
145
|
async def aembed_query(self, *args, **kwargs):
|
|
123
|
-
|
|
124
|
-
|
|
146
|
+
async with _semaphores["embed"]:
|
|
147
|
+
return await self._fresh().aembed_query(*args, **kwargs)
|
|
125
148
|
|
|
126
|
-
# по хорошему бы переопределять клиент гигачата или манкипатчить его, но это не так просто
|
|
127
149
|
class ThrottledGigaChat(GigaChat):
|
|
150
|
+
_manage_access_token: bool = PrivateAttr(default=True)
|
|
151
|
+
_base_kwargs: bool = PrivateAttr(default=True)
|
|
152
|
+
|
|
153
|
+
def __init__(self, *args, manage_access_token=True, **kwargs):
|
|
154
|
+
print(self)
|
|
155
|
+
self._manage_access_token = manage_access_token
|
|
156
|
+
self._base_kwargs = dict(kwargs)
|
|
157
|
+
|
|
158
|
+
if self._manage_access_token and "access_token" not in kwargs:
|
|
159
|
+
token = GigaChatTokenManager.get_token()
|
|
160
|
+
super().__init__(access_token=token, **kwargs)
|
|
161
|
+
else:
|
|
162
|
+
super().__init__(**kwargs)
|
|
163
|
+
|
|
164
|
+
def _fresh(self) -> GigaChat:
|
|
165
|
+
if self._manage_access_token:
|
|
166
|
+
return GigaChat(access_token=GigaChatTokenManager, **self._base_kwargs)
|
|
167
|
+
else:
|
|
168
|
+
return self
|
|
169
|
+
|
|
128
170
|
def invoke(self, *args, **kwargs):
|
|
129
171
|
with _semaphores["chat"]:
|
|
130
|
-
return
|
|
172
|
+
return self._fresh().invoke(*args, **kwargs)
|
|
131
173
|
|
|
132
174
|
async def ainvoke(self, *args, **kwargs):
|
|
133
175
|
async with _semaphores["chat"]:
|
|
134
|
-
return await
|
|
176
|
+
return await self._fresh().ainvoke(*args, **kwargs)
|
|
135
177
|
|
|
136
178
|
def stream(self, *args, **kwargs):
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
yield chunk
|
|
141
|
-
else:
|
|
142
|
-
# здесь есть проблема когда внутри stream вызывается invoke, поэтому без семафора
|
|
143
|
-
for chunk in super().stream(*args, **kwargs):
|
|
144
|
-
yield chunk
|
|
179
|
+
with _semaphores["chat"]:
|
|
180
|
+
for chunk in self._fresh().stream(*args, **kwargs):
|
|
181
|
+
yield chunk
|
|
145
182
|
|
|
146
183
|
async def astream(self, *args, **kwargs):
|
|
147
|
-
|
|
148
|
-
async
|
|
149
|
-
async for chunk in super().astream(*args, **kwargs):
|
|
150
|
-
yield chunk
|
|
151
|
-
else:
|
|
152
|
-
# здесь есть проблема когда внутри stream вызывается ainvoke, поэтому без семафора
|
|
153
|
-
async for chunk in super().astream(*args, **kwargs):
|
|
184
|
+
async with _semaphores["chat"]:
|
|
185
|
+
async for chunk in self._fresh().astream(*args, **kwargs):
|
|
154
186
|
yield chunk
|
|
155
187
|
|
|
156
188
|
async def astream_events(self, *args, **kwargs):
|
|
157
189
|
async with _semaphores["chat"]:
|
|
158
|
-
async for ev in
|
|
190
|
+
async for ev in self._fresh().astream_events(*args, **kwargs):
|
|
159
191
|
yield ev
|
|
160
192
|
|
|
161
193
|
def batch(self, *args, **kwargs):
|
|
162
|
-
|
|
163
|
-
|
|
194
|
+
with _semaphores["chat"]:
|
|
195
|
+
return self._fresh().batch(*args, **kwargs)
|
|
164
196
|
|
|
165
197
|
async def abatch(self, *args, **kwargs):
|
|
166
|
-
|
|
167
|
-
|
|
198
|
+
async with _semaphores["chat"]:
|
|
199
|
+
return await self._fresh().abatch(*args, **kwargs)
|
|
168
200
|
|
|
169
201
|
def batch_as_completed(self, *args, **kwargs):
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
202
|
+
with _semaphores["chat"]:
|
|
203
|
+
for item in self._fresh().batch_as_completed(*args, **kwargs):
|
|
204
|
+
yield item
|
|
173
205
|
|
|
174
206
|
async def abatch_as_completed(self, *args, **kwargs):
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
207
|
+
async with _semaphores["chat"]:
|
|
208
|
+
async for item in self._fresh().abatch_as_completed(*args, **kwargs):
|
|
209
|
+
yield item
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/langgraph/checkpoint/__init__.py
RENAMED
|
File without changes
|
{agent_lab_sdk-0.1.26 → agent_lab_sdk-0.1.28}/agent_lab_sdk/langgraph/checkpoint/agw_saver.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|