mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
langchain_nvidia_ai_endpoints[patch]: Invoke callback prior to yielding token (#18271)
## PR title langchain_nvidia_ai_endpoints[patch]: Invoke callback prior to yielding ## PR message **Description:** Invoke callback prior to yielding token in _stream and _astream methods for nvidia_ai_endpoints. **Issue:** https://github.com/langchain-ai/langchain/issues/16913 **Dependencies:** None
This commit is contained in:
parent
b4f6066a57
commit
7ac74f291e
@ -161,9 +161,9 @@ class ChatNVIDIA(nvidia_ai_endpoints._NVIDIAClient, SimpleChatModel):
|
||||
inputs = self.custom_preprocess(messages)
|
||||
for response in self.get_stream(inputs=inputs, stop=stop, **kwargs):
|
||||
chunk = self._get_filled_chunk(self.custom_postprocess(response))
|
||||
yield chunk
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
async def _astream(
|
||||
self,
|
||||
@ -175,9 +175,9 @@ class ChatNVIDIA(nvidia_ai_endpoints._NVIDIAClient, SimpleChatModel):
|
||||
inputs = self.custom_preprocess(messages)
|
||||
async for response in self.get_astream(inputs=inputs, stop=stop, **kwargs):
|
||||
chunk = self._get_filled_chunk(self.custom_postprocess(response))
|
||||
yield chunk
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
def custom_preprocess(
|
||||
self, msg_list: Sequence[BaseMessage]
|
||||
|
Loading…
Reference in New Issue
Block a user