forked from shroominic/codeinterpreter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
general_test.py
82 lines (63 loc) · 2.04 KB
/
general_test.py
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
import asyncio
from codeinterpreterapi import CodeInterpreterSession, File
def test_codebox():
session = CodeInterpreterSession()
assert run_sync(session), "Failed to run sync CodeInterpreterSession remotely"
assert asyncio.run(
run_async(session)
), "Failed to run async CodeInterpreterSession remotely"
def test_localbox():
session = CodeInterpreterSession(local=True)
assert run_sync(session), "Failed to run sync CodeInterpreterSession locally"
assert asyncio.run(
run_async(session)
), "Failed to run async CodeInterpreterSession locally"
def run_sync(session: CodeInterpreterSession) -> bool:
try:
assert session.start() == "started"
assert (
"3.1"
in session.generate_response(
"Compute pi using Monte Carlo simulation in Python and show me the result."
).content
)
assert (
".xlsx"
in session.generate_response(
"Convert this csv file to excel.",
files=[File.from_path("examples/assets/iris.csv")],
)
.files[0]
.name
)
finally:
assert session.stop() == "stopped"
return True
async def run_async(session: CodeInterpreterSession) -> bool:
try:
assert (await session.astart()) == "started"
assert (
"3.1"
in (
await session.agenerate_response(
"Compute pi using Monte Carlo simulation in Python and show me the result."
)
).content
)
assert (
".xlsx"
in (
await session.agenerate_response(
"Convert this csv file to excel.",
files=[File.from_path("examples/assets/iris.csv")],
)
)
.files[0]
.name
)
finally:
assert await session.astop() == "stopped"
return True
if __name__ == "__main__":
test_codebox()
test_localbox()