mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 14:18:52 +00:00
community[patch]: callback before yield for textgen (#26929)
**Description:** Moves callback to before yield for `_stream` and `_astream` function for the textgen model in the community llm package **Issue:** #16913
This commit is contained in:
parent
5f2cc4ecb2
commit
adcfecdb67
@ -335,14 +335,13 @@ class TextGen(LLM):
|
||||
text=result["text"], # type: ignore[call-overload, index]
|
||||
generation_info=None,
|
||||
)
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(token=chunk.text)
|
||||
yield chunk
|
||||
elif result["event"] == "stream_end": # type: ignore[call-overload, index]
|
||||
websocket_client.close()
|
||||
return
|
||||
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(token=chunk.text)
|
||||
|
||||
async def _astream(
|
||||
self,
|
||||
prompt: str,
|
||||
@ -408,10 +407,9 @@ class TextGen(LLM):
|
||||
text=result["text"], # type: ignore[call-overload, index]
|
||||
generation_info=None,
|
||||
)
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(token=chunk.text)
|
||||
yield chunk
|
||||
elif result["event"] == "stream_end": # type: ignore[call-overload, index]
|
||||
websocket_client.close()
|
||||
return
|
||||
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(token=chunk.text)
|
||||
|
Loading…
Reference in New Issue
Block a user