langchain-b12 0.1.7__py3-none-any.whl → 0.1.8__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
|
@@ -75,6 +75,8 @@ class ChatGenAI(BaseChatModel):
|
|
|
75
75
|
"""How many completions to generate for each prompt."""
|
|
76
76
|
seed: int | None = None
|
|
77
77
|
"""Random seed for the generation."""
|
|
78
|
+
max_retries: int | None = Field(default=3)
|
|
79
|
+
"""Maximum number of retries when generation fails. None disables retries."""
|
|
78
80
|
safety_settings: list[types.SafetySetting] | None = None
|
|
79
81
|
"""The default safety settings to use for all generations.
|
|
80
82
|
|
|
@@ -173,10 +175,24 @@ class ChatGenAI(BaseChatModel):
|
|
|
173
175
|
run_manager: CallbackManagerForLLMRun | None = None,
|
|
174
176
|
**kwargs: Any,
|
|
175
177
|
) -> ChatResult:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
attempts = 0
|
|
179
|
+
while True:
|
|
180
|
+
try:
|
|
181
|
+
stream_iter = self._stream(
|
|
182
|
+
messages, stop=stop, run_manager=run_manager, **kwargs
|
|
183
|
+
)
|
|
184
|
+
return generate_from_stream(stream_iter)
|
|
185
|
+
except Exception as e: # noqa: BLE001
|
|
186
|
+
if self.max_retries is None or attempts >= self.max_retries:
|
|
187
|
+
raise
|
|
188
|
+
attempts += 1
|
|
189
|
+
logger.warning(
|
|
190
|
+
"ChatGenAI._generate failed (attempt %d/%d). "
|
|
191
|
+
"Retrying... Error: %s",
|
|
192
|
+
attempts,
|
|
193
|
+
self.max_retries,
|
|
194
|
+
e,
|
|
195
|
+
)
|
|
180
196
|
|
|
181
197
|
async def _agenerate(
|
|
182
198
|
self,
|
|
@@ -185,10 +201,24 @@ class ChatGenAI(BaseChatModel):
|
|
|
185
201
|
run_manager: AsyncCallbackManagerForLLMRun | None = None,
|
|
186
202
|
**kwargs: Any,
|
|
187
203
|
) -> ChatResult:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
204
|
+
attempts = 0
|
|
205
|
+
while True:
|
|
206
|
+
try:
|
|
207
|
+
stream_iter = self._astream(
|
|
208
|
+
messages, stop=stop, run_manager=run_manager, **kwargs
|
|
209
|
+
)
|
|
210
|
+
return await agenerate_from_stream(stream_iter)
|
|
211
|
+
except Exception as e: # noqa: BLE001
|
|
212
|
+
if self.max_retries is None or attempts >= self.max_retries:
|
|
213
|
+
raise
|
|
214
|
+
attempts += 1
|
|
215
|
+
logger.warning(
|
|
216
|
+
"ChatGenAI._agenerate failed (attempt %d/%d). "
|
|
217
|
+
"Retrying... Error: %s",
|
|
218
|
+
attempts,
|
|
219
|
+
self.max_retries,
|
|
220
|
+
e,
|
|
221
|
+
)
|
|
192
222
|
|
|
193
223
|
def _stream(
|
|
194
224
|
self,
|
|
@@ -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=4Q0j2YsAPLrHhIy_pYXoncb4hqJJkEUpxB3oD3qaECI,18120
|
|
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.8.dist-info/METADATA,sha256=0-KZr-PXjE16ar4LpQbdWHX8CrViLBxlfV9uGwE0Qw0,1204
|
|
8
|
+
langchain_b12-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
langchain_b12-0.1.8.dist-info/RECORD,,
|
|
File without changes
|