mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
[community] fix anthropic streaming (#16682)
This commit is contained in:
parent
5975bf39ec
commit
27665e3546
@ -142,9 +142,10 @@ class ChatAnthropic(BaseChatModel, _AnthropicCommon):
|
||||
stream_resp = self.client.completions.create(**params, stream=True)
|
||||
for data in stream_resp:
|
||||
delta = data.completion
|
||||
yield ChatGenerationChunk(message=AIMessageChunk(content=delta))
|
||||
chunk = ChatGenerationChunk(message=AIMessageChunk(content=delta))
|
||||
yield chunk
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(delta)
|
||||
run_manager.on_llm_new_token(delta, chunk=chunk)
|
||||
|
||||
async def _astream(
|
||||
self,
|
||||
@ -161,9 +162,10 @@ class ChatAnthropic(BaseChatModel, _AnthropicCommon):
|
||||
stream_resp = await self.async_client.completions.create(**params, stream=True)
|
||||
async for data in stream_resp:
|
||||
delta = data.completion
|
||||
yield ChatGenerationChunk(message=AIMessageChunk(content=delta))
|
||||
chunk = ChatGenerationChunk(message=AIMessageChunk(content=delta))
|
||||
yield chunk
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(delta)
|
||||
await run_manager.on_llm_new_token(delta, chunk=chunk)
|
||||
|
||||
def _generate(
|
||||
self,
|
||||
|
Loading…
Reference in New Issue
Block a user