Skip to content

The agent engineering platform.

community[patch]: invoke callback prior to yielding token (llama.cpp) (#19392)

aditya thomas4856a872616f
diff --git a/libs/community/langchain_community/llms/llamacpp.py b/libs/community/langchain_community/llms/llamacpp.py
index 85acfb999e..b06e6d8cf7 100644
--- a/libs/community/langchain_community/llms/llamacpp.py
+++ b/libs/community/langchain_community/llms/llamacpp.py
@@ -344,11 +344,11 @@ class LlamaCpp(LLM):
text=part["choices"][0]["text"],
generation_info={"logprobs": logprobs},
)
- yield chunk
if run_manager:
run_manager.on_llm_new_token(
token=chunk.text, verbose=self.verbose, log_probs=logprobs
)
+ yield chunk
def get_num_tokens(self, text: str) -> int:
tokenized_text = self.client.tokenize(text.encode("utf-8"))