Skip to content

The agent engineering platform.

community[patch]: Invoke callback prior to yielding token (ollama) (#18629)

Yudhajit Sinha280a91492099
diff --git a/libs/community/langchain_community/llms/ollama.py b/libs/community/langchain_community/llms/ollama.py
index c4747a4ebb..5c357ae967 100644
--- a/libs/community/langchain_community/llms/ollama.py
+++ b/libs/community/langchain_community/llms/ollama.py
@@ -475,12 +475,12 @@ class Ollama(BaseLLM, _OllamaCommon):
for stream_resp in self._create_generate_stream(prompt, stop, **kwargs):
if stream_resp:
chunk = _stream_response_to_generation_chunk(stream_resp)
- yield chunk
if run_manager:
run_manager.on_llm_new_token(
chunk.text,
verbose=self.verbose,
)
+ yield chunk
async def _astream(
self,
@@ -492,9 +492,9 @@ class Ollama(BaseLLM, _OllamaCommon):
async for stream_resp in self._acreate_generate_stream(prompt, stop, **kwargs):
if stream_resp:
chunk = _stream_response_to_generation_chunk(stream_resp)
- yield chunk
if run_manager:
await run_manager.on_llm_new_token(
chunk.text,
verbose=self.verbose,
)
+ yield chunk