forked from opper-ai/opper-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatasets.py
More file actions
143 lines (104 loc) · 2.79 KB
/
datasets.py
File metadata and controls
143 lines (104 loc) · 2.79 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from opperai import AsyncOpper, Opper
from opperai.types.datasets import DatasetEntry
def _sync_call():
opper = Opper()
name = "test_sync_call"
def setup():
opper.call(
name=name,
input="Hello, world!",
)
f = opper.functions.get(name=name)
return f
def populate():
f = setup()
dataset = f.dataset()
dataset.add(
DatasetEntry(
input="Hello, world!",
output="Hello, world!",
)
)
for entry in dataset.get_entries():
print(entry)
populate()
def _sync_function():
opper = Opper()
def setup():
f = opper.functions.create(
name="test_sync",
instructions="given an input, return the same input",
)
return f
def populate():
f = setup()
dataset = f.dataset()
dataset.add(
DatasetEntry(
input="Hello, world!",
output="Hello, world!",
)
)
for entry in dataset.get_entries():
print(entry)
populate()
async def _async_call():
opper = AsyncOpper()
name = "test_async_call"
async def setup():
await opper.call(name=name, input="Hello, world!")
f = await opper.functions.get(name=name)
return f
async def populate():
f = await setup()
dataset = f.dataset()
await dataset.add(
DatasetEntry(
input="Hello, world!",
output="Hello, world!",
)
)
for entry in await dataset.get_entries():
print(entry)
await populate()
async def _async_function():
opper = AsyncOpper()
async def setup():
f = await opper.functions.create(
name="test_async",
instructions="given an input, return the same input",
)
return f
async def populate():
f = await setup()
dataset = f.dataset()
await dataset.add(
DatasetEntry(
input="Hello, world!",
output="Hello, world!",
)
)
for entry in await dataset.get_entries():
print(entry)
await populate()
def run_sync():
_sync_call()
_sync_function()
async def run_async():
await _async_call()
await _async_function()
if __name__ == "__main__":
import asyncio
import sys
if len(sys.argv) == 2:
if sys.argv[1] == "sync":
print("Sync function")
run_sync()
elif sys.argv[1] == "async":
print("Async function")
asyncio.run(run_async())
else:
print("Sync call")
run_sync()
print("Async call")
asyncio.run(run_async())