mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
langchain_anthropic[patch]: Invoke callback prior to yielding token (#18274)
## PR title langchain_anthropic[patch]: Invoke callback prior to yielding ## PR message - Description: Invoke callback prior to yielding token in _stream and _astream methods for anthropic. - Issue: https://github.com/langchain-ai/langchain/issues/16913 - Dependencies: None - Twitter handle: None
This commit is contained in:
parent
af35e2525a
commit
a37dc83a9e
@ -300,9 +300,10 @@ class AnthropicLLM(LLM, _AnthropicCommon):
|
||||
prompt=self._wrap_prompt(prompt), stop_sequences=stop, stream=True, **params
|
||||
):
|
||||
chunk = GenerationChunk(text=token.completion)
|
||||
yield chunk
|
||||
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
async def _astream(
|
||||
self,
|
||||
@ -336,9 +337,10 @@ class AnthropicLLM(LLM, _AnthropicCommon):
|
||||
**params,
|
||||
):
|
||||
chunk = GenerationChunk(text=token.completion)
|
||||
yield chunk
|
||||
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
def get_num_tokens(self, text: str) -> int:
|
||||
"""Calculate number of tokens."""
|
||||
|
Loading…
Reference in New Issue
Block a user