mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-01 10:54:15 +00:00
community[patch]: Invoke callback prior to yielding token (#18454)
## PR title community[patch]: Invoke callback prior to yielding token ## PR message - Description: Invoke callback prior to yielding token in _stream and _astream methods in llms/baidu_qianfan_endpoint. - Issue: https://github.com/langchain-ai/langchain/issues/16913 - Dependencies: None
This commit is contained in:
parent
7c2f3f6f95
commit
371bec79bc
@ -213,9 +213,9 @@ class QianfanLLMEndpoint(LLM):
|
|||||||
for res in self.client.do(**params):
|
for res in self.client.do(**params):
|
||||||
if res:
|
if res:
|
||||||
chunk = GenerationChunk(text=res["result"])
|
chunk = GenerationChunk(text=res["result"])
|
||||||
yield chunk
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
run_manager.on_llm_new_token(chunk.text)
|
run_manager.on_llm_new_token(chunk.text)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
async def _astream(
|
async def _astream(
|
||||||
self,
|
self,
|
||||||
@ -228,7 +228,6 @@ class QianfanLLMEndpoint(LLM):
|
|||||||
async for res in await self.client.ado(**params):
|
async for res in await self.client.ado(**params):
|
||||||
if res:
|
if res:
|
||||||
chunk = GenerationChunk(text=res["result"])
|
chunk = GenerationChunk(text=res["result"])
|
||||||
|
|
||||||
yield chunk
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
await run_manager.on_llm_new_token(chunk.text)
|
await run_manager.on_llm_new_token(chunk.text)
|
||||||
|
yield chunk
|
||||||
|
Loading…
Reference in New Issue
Block a user