Skip to content

Commit

Permalink
langchain_nvidia_ai_endpoints[patch]: Invoke callback prior to yieldi…
Browse files Browse the repository at this point in the history
…ng 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:** #16913
**Dependencies:** None
  • Loading branch information
williamdevena committed Feb 28, 2024
1 parent b4f6066 commit 7ac74f2
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def _stream(
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,
Expand All @@ -175,9 +175,9 @@ async def _astream(
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]
Expand Down

0 comments on commit 7ac74f2

Please sign in to comment.