mirror of
https://github.com/hwchase17/langchain
synced 2024-11-16 06:13:16 +00:00
community[patch]: invoke callback prior to yielding token (llama.cpp) (#19392)
**Description:** Invoke callback prior to yielding token for llama.cpp **Issue:** [Callback for on_llm_new_token should be invoked before the token is yielded by the model #16913](https://github.com/langchain-ai/langchain/issues/16913) **Dependencies:** None
This commit is contained in:
parent
c4599444ee
commit
4856a87261
@ -344,11 +344,11 @@ class LlamaCpp(LLM):
|
|||||||
text=part["choices"][0]["text"],
|
text=part["choices"][0]["text"],
|
||||||
generation_info={"logprobs": logprobs},
|
generation_info={"logprobs": logprobs},
|
||||||
)
|
)
|
||||||
yield chunk
|
|
||||||
if run_manager:
|
if run_manager:
|
||||||
run_manager.on_llm_new_token(
|
run_manager.on_llm_new_token(
|
||||||
token=chunk.text, verbose=self.verbose, log_probs=logprobs
|
token=chunk.text, verbose=self.verbose, log_probs=logprobs
|
||||||
)
|
)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
def get_num_tokens(self, text: str) -> int:
|
def get_num_tokens(self, text: str) -> int:
|
||||||
tokenized_text = self.client.tokenize(text.encode("utf-8"))
|
tokenized_text = self.client.tokenize(text.encode("utf-8"))
|
||||||
|
Loading…
Reference in New Issue
Block a user