forked from replicate/replicate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stream.py
More file actions
55 lines (40 loc) · 1.28 KB
/
Copy pathtest_stream.py
File metadata and controls
55 lines (40 loc) · 1.28 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
48
49
50
51
52
53
54
55
import pytest
import replicate
@pytest.mark.asyncio
@pytest.mark.parametrize("async_flag", [True, False])
async def test_stream(async_flag, record_mode):
if record_mode == "none":
return
version = "02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3"
input = {
"prompt": "Please write a haiku about llamas.",
}
events = []
if async_flag:
async for event in await replicate.async_stream(
f"meta/llama-2-70b-chat:{version}",
input=input,
):
events.append(event)
else:
for event in replicate.stream(
f"meta/llama-2-70b-chat:{version}",
input=input,
):
events.append(event)
assert len(events) > 0
assert events[0].event == "output"
@pytest.mark.asyncio
async def test_stream_prediction(record_mode):
if record_mode == "none":
return
version = "02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3"
input = {
"prompt": "Please write a haiku about llamas.",
}
prediction = replicate.predictions.create(version=version, input=input)
events = []
for event in prediction.stream():
events.append(event)
assert len(events) > 0
assert events[0].event == "output"