community[patch]: callback before yield for gigachat (#26881)

**Description:** Moves yield to after callback for `_stream` and
`_astream` function for the gigachat model in the community llm package
**Issue:** #16913
This commit is contained in:
Subhrajyoty Roy 2024-09-26 22:17:28 +05:30 committed by GitHub
parent 11e703a97e
commit ba467f1a36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -311,9 +311,9 @@ class GigaChat(_BaseGigaChat, BaseLLM):
for chunk in self._client.stream(payload):
if chunk.choices:
content = chunk.choices[0].delta.content
yield GenerationChunk(text=content)
if run_manager:
run_manager.on_llm_new_token(content)
yield GenerationChunk(text=content)
async def _astream(
self,
@ -327,9 +327,9 @@ class GigaChat(_BaseGigaChat, BaseLLM):
async for chunk in self._client.astream(payload):
if chunk.choices:
content = chunk.choices[0].delta.content
yield GenerationChunk(text=content)
if run_manager:
await run_manager.on_llm_new_token(content)
yield GenerationChunk(text=content)
model_config = ConfigDict(
extra="allow",