langchain-b12 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl
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.
langchain_b12/genai/genai.py
CHANGED
|
@@ -7,10 +7,6 @@ from typing import Any, Literal, cast
|
|
|
7
7
|
from google import genai
|
|
8
8
|
from google.genai import types
|
|
9
9
|
from google.oauth2 import service_account
|
|
10
|
-
from langchain_b12.genai.genai_utils import (
|
|
11
|
-
convert_messages_to_contents,
|
|
12
|
-
parse_response_candidate,
|
|
13
|
-
)
|
|
14
10
|
from langchain_core.callbacks import (
|
|
15
11
|
AsyncCallbackManagerForLLMRun,
|
|
16
12
|
CallbackManagerForLLMRun,
|
|
@@ -40,6 +36,18 @@ from langchain_core.utils.function_calling import (
|
|
|
40
36
|
convert_to_openai_tool,
|
|
41
37
|
)
|
|
42
38
|
from pydantic import BaseModel, ConfigDict, Field
|
|
39
|
+
from tenacity import (
|
|
40
|
+
retry,
|
|
41
|
+
retry_if_exception_type,
|
|
42
|
+
stop_after_attempt,
|
|
43
|
+
stop_never,
|
|
44
|
+
wait_exponential_jitter,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from langchain_b12.genai.genai_utils import (
|
|
48
|
+
convert_messages_to_contents,
|
|
49
|
+
parse_response_candidate,
|
|
50
|
+
)
|
|
43
51
|
|
|
44
52
|
logger = logging.getLogger(__name__)
|
|
45
53
|
|
|
@@ -175,24 +183,29 @@ class ChatGenAI(BaseChatModel):
|
|
|
175
183
|
run_manager: CallbackManagerForLLMRun | None = None,
|
|
176
184
|
**kwargs: Any,
|
|
177
185
|
) -> ChatResult:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
@retry(
|
|
187
|
+
reraise=True,
|
|
188
|
+
stop=stop_after_attempt(self.max_retries + 1)
|
|
189
|
+
if self.max_retries is not None
|
|
190
|
+
else stop_never,
|
|
191
|
+
wait=wait_exponential_jitter(initial=1, max=60),
|
|
192
|
+
retry=retry_if_exception_type(Exception),
|
|
193
|
+
before_sleep=lambda retry_state: logger.warning(
|
|
194
|
+
"ChatGenAI._generate failed (attempt %d/%s). "
|
|
195
|
+
"Retrying in %.2fs... Error: %s",
|
|
196
|
+
retry_state.attempt_number,
|
|
197
|
+
self.max_retries + 1 if self.max_retries is not None else "∞",
|
|
198
|
+
retry_state.next_action.sleep,
|
|
199
|
+
retry_state.outcome.exception(),
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
def _generate_with_retry() -> ChatResult:
|
|
203
|
+
stream_iter = self._stream(
|
|
204
|
+
messages, stop=stop, run_manager=run_manager, **kwargs
|
|
205
|
+
)
|
|
206
|
+
return generate_from_stream(stream_iter)
|
|
207
|
+
|
|
208
|
+
return _generate_with_retry()
|
|
196
209
|
|
|
197
210
|
async def _agenerate(
|
|
198
211
|
self,
|
|
@@ -201,24 +214,29 @@ class ChatGenAI(BaseChatModel):
|
|
|
201
214
|
run_manager: AsyncCallbackManagerForLLMRun | None = None,
|
|
202
215
|
**kwargs: Any,
|
|
203
216
|
) -> ChatResult:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
@retry(
|
|
218
|
+
reraise=True,
|
|
219
|
+
stop=stop_after_attempt(self.max_retries + 1)
|
|
220
|
+
if self.max_retries is not None
|
|
221
|
+
else stop_never,
|
|
222
|
+
wait=wait_exponential_jitter(initial=1, max=60),
|
|
223
|
+
retry=retry_if_exception_type(Exception),
|
|
224
|
+
before_sleep=lambda retry_state: logger.warning(
|
|
225
|
+
"ChatGenAI._agenerate failed (attempt %d/%s). "
|
|
226
|
+
"Retrying in %.2fs... Error: %s",
|
|
227
|
+
retry_state.attempt_number,
|
|
228
|
+
self.max_retries + 1 if self.max_retries is not None else "∞",
|
|
229
|
+
retry_state.next_action.sleep,
|
|
230
|
+
retry_state.outcome.exception(),
|
|
231
|
+
),
|
|
232
|
+
)
|
|
233
|
+
async def _agenerate_with_retry() -> ChatResult:
|
|
234
|
+
stream_iter = self._astream(
|
|
235
|
+
messages, stop=stop, run_manager=run_manager, **kwargs
|
|
236
|
+
)
|
|
237
|
+
return await agenerate_from_stream(stream_iter)
|
|
238
|
+
|
|
239
|
+
return await _agenerate_with_retry()
|
|
222
240
|
|
|
223
241
|
def _stream(
|
|
224
242
|
self,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langchain-b12
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
4
4
|
Summary: A reusable collection of tools and implementations for Langchain
|
|
5
5
|
Author-email: Vincent Min <vincent.min@b12-consulting.com>
|
|
6
6
|
Requires-Python: >=3.11
|
|
7
7
|
Requires-Dist: langchain-core>=0.3.60
|
|
8
|
+
Requires-Dist: tenacity>=9.1.2
|
|
8
9
|
Description-Content-Type: text/markdown
|
|
9
10
|
|
|
10
11
|
# Langchain B12
|
|
@@ -2,8 +2,8 @@ langchain_b12/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
langchain_b12/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
langchain_b12/citations/citations.py,sha256=ZQvYayjQXIUaRosJ0qwL3Nc7kC8sBzmaIkE-BOslaVI,12261
|
|
4
4
|
langchain_b12/genai/embeddings.py,sha256=h0Z-5PltDW9q79AjSrLemsz-_QKMB-043XXDvYSRQds,3483
|
|
5
|
-
langchain_b12/genai/genai.py,sha256=
|
|
5
|
+
langchain_b12/genai/genai.py,sha256=zZdGwkkaxobnA1jT07MvWHaIHKeBis4X1zJ8o5KrnHk,18841
|
|
6
6
|
langchain_b12/genai/genai_utils.py,sha256=tA6UiJURK25-11vtaX4768UV47jDCYwVKIIWydD4Egw,10736
|
|
7
|
-
langchain_b12-0.1.
|
|
8
|
-
langchain_b12-0.1.
|
|
9
|
-
langchain_b12-0.1.
|
|
7
|
+
langchain_b12-0.1.9.dist-info/METADATA,sha256=CpmYdZwkej43d-DvTOR8FU65QSHAZ4iiFu7Ale8Gy0I,1235
|
|
8
|
+
langchain_b12-0.1.9.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
+
langchain_b12-0.1.9.dist-info/RECORD,,
|