-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathusing_openvino_streamer.py
More file actions
50 lines (31 loc) · 1.32 KB
/
using_openvino_streamer.py
File metadata and controls
50 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
""" This example illustrates the use of streaming with OpenVINO models, which
use a callback streaming function, rather than a generator - the example
shows how to stream text to console using the default streamer, and
how to modify and create a custom streamer function.
Prereqs:
-- pip install openvino_genai
If you want to use the web streamer:
-- pip install pywebio
"""
from llmware.models import ModelCatalog
import openvino_genai as ovg
try:
from pywebio.output import put_text
except:
pass
# this is the default streamer included in the OVGenerativeModel class -
# if no streamer explicitly passed, then this will be used
def ov_default_streamer(x):
print(x, end="", flush=True)
return ovg.StreamingStatus.RUNNING
# here is a simple example that will stream the text to local host
# to run this example: `pip install pywebio`
def web_streamer(x):
put_text(x,inline=True)
return ovg.StreamingStatus.RUNNING
model = ModelCatalog().load_model("llama-3.2-3b-instruct-ov",
max_output=500)
prompt = "What are the best sites to see in France?"
# streamer is None by default, pass custom streaming function here
response = model.stream(prompt, streamer=ov_default_streamer)
print("\n\ncompleted streaming response - ", response)