mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
community: update openvino doc with streaming support (#21519)
Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
7022260bc5
commit
e44b448ec3
@ -216,6 +216,42 @@
|
|||||||
"}"
|
"}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "7574c6f0",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Streaming\n",
|
||||||
|
"\n",
|
||||||
|
"To get streaming of LLM output, you can create a Huggingface `TextIteratorStreamer` for `_forward_params`."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "548c9489",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from threading import Thread\n",
|
||||||
|
"\n",
|
||||||
|
"from transformers import TextIteratorStreamer\n",
|
||||||
|
"\n",
|
||||||
|
"streamer = TextIteratorStreamer(\n",
|
||||||
|
" ov_llm.pipeline.tokenizer,\n",
|
||||||
|
" timeout=30.0,\n",
|
||||||
|
" skip_prompt=True,\n",
|
||||||
|
" skip_special_tokens=True,\n",
|
||||||
|
")\n",
|
||||||
|
"ov_llm.pipeline._forward_params = {\"streamer\": streamer, \"max_new_tokens\": 100}\n",
|
||||||
|
"\n",
|
||||||
|
"t1 = Thread(target=chain.invoke, args=({\"question\": question},))\n",
|
||||||
|
"t1.start()\n",
|
||||||
|
"\n",
|
||||||
|
"for new_text in streamer:\n",
|
||||||
|
" print(new_text, end=\"\", flush=True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "da9a9239",
|
"id": "da9a9239",
|
||||||
|
@ -212,7 +212,7 @@ class HuggingFacePipeline(BaseLLM):
|
|||||||
cuda_device_count,
|
cuda_device_count,
|
||||||
)
|
)
|
||||||
if device is not None and device_map is not None and backend == "openvino":
|
if device is not None and device_map is not None and backend == "openvino":
|
||||||
logger.warning("Please set device for OpenVINO through: " "'model_kwargs'")
|
logger.warning("Please set device for OpenVINO through: `model_kwargs`")
|
||||||
if "trust_remote_code" in _model_kwargs:
|
if "trust_remote_code" in _model_kwargs:
|
||||||
_model_kwargs = {
|
_model_kwargs = {
|
||||||
k: v for k, v in _model_kwargs.items() if k != "trust_remote_code"
|
k: v for k, v in _model_kwargs.items() if k != "trust_remote_code"
|
||||||
|
Loading…
Reference in New Issue
Block a user