scalebox-sdk 0.1.4__py3-none-any.whl → 0.1.25__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scalebox/__init__.py +1 -1
- scalebox/api/__init__.py +128 -128
- scalebox/api/client/__init__.py +8 -8
- scalebox/api/client/api/sandboxes/get_sandboxes.py +5 -3
- scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +2 -2
- scalebox/api/client/api/sandboxes/post_sandboxes.py +2 -2
- scalebox/api/client/client.py +288 -288
- scalebox/api/client/models/listed_sandbox.py +11 -9
- scalebox/api/client/models/new_sandbox.py +1 -1
- scalebox/api/client/models/sandbox.py +125 -125
- scalebox/api/client/models/sandbox_state.py +1 -0
- scalebox/api/client/types.py +46 -46
- scalebox/code_interpreter/code_interpreter_async.py +370 -369
- scalebox/code_interpreter/code_interpreter_sync.py +318 -317
- scalebox/connection_config.py +92 -92
- scalebox/csx_desktop/main.py +12 -12
- scalebox/generated/api_pb2_connect.py +17 -66
- scalebox/sandbox_async/commands/command.py +307 -307
- scalebox/sandbox_async/commands/command_handle.py +187 -187
- scalebox/sandbox_async/commands/pty.py +187 -187
- scalebox/sandbox_async/filesystem/filesystem.py +557 -557
- scalebox/sandbox_async/filesystem/watch_handle.py +61 -61
- scalebox/sandbox_async/main.py +647 -646
- scalebox/sandbox_async/sandbox_api.py +365 -365
- scalebox/sandbox_async/utils.py +7 -7
- scalebox/sandbox_sync/__init__.py +2 -2
- scalebox/sandbox_sync/commands/command.py +300 -300
- scalebox/sandbox_sync/commands/command_handle.py +150 -150
- scalebox/sandbox_sync/commands/pty.py +181 -181
- scalebox/sandbox_sync/filesystem/filesystem.py +543 -543
- scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
- scalebox/sandbox_sync/main.py +789 -790
- scalebox/sandbox_sync/sandbox_api.py +356 -356
- scalebox/test/CODE_INTERPRETER_TESTS_READY.md +256 -256
- scalebox/test/README.md +164 -164
- scalebox/test/aclient.py +72 -72
- scalebox/test/code_interpreter_centext.py +21 -21
- scalebox/test/code_interpreter_centext_sync.py +21 -21
- scalebox/test/code_interpreter_test.py +1 -1
- scalebox/test/code_interpreter_test_sync.py +1 -1
- scalebox/test/run_all_validation_tests.py +334 -334
- scalebox/test/test_basic.py +78 -78
- scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
- scalebox/test/{test_code_interpreter_e2bsync_comprehensive.py → test_code_interpreter_execcode.py} +328 -392
- scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
- scalebox/test/test_csx_desktop_examples.py +130 -0
- scalebox/test/test_sandbox_async_comprehensive.py +736 -738
- scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
- scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
- scalebox/test/test_sandbox_usage_examples.py +987 -987
- scalebox/test/testacreate.py +24 -24
- scalebox/test/testagetinfo.py +18 -18
- scalebox/test/testcodeinterpreter_async.py +508 -508
- scalebox/test/testcodeinterpreter_sync.py +239 -239
- scalebox/test/testcomputeuse.py +2 -2
- scalebox/test/testnovnc.py +12 -12
- scalebox/test/testsandbox_api.py +15 -0
- scalebox/test/testsandbox_async.py +202 -118
- scalebox/test/testsandbox_sync.py +71 -38
- scalebox/version.py +2 -2
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/METADATA +104 -103
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/RECORD +66 -66
- scalebox/test/test_code_interpreter_e2basync_comprehensive.py +0 -2655
- scalebox/test/test_e2b_first.py +0 -11
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/WHEEL +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/entry_points.txt +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/licenses/LICENSE +0 -0
- {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/top_level.txt +0 -0
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Simple sync CodeInterpreter test example.
|
|
4
|
-
Similar to testsandbox_sync.py but for code interpreter functionality.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from scalebox.code_interpreter import Context, Sandbox
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def output_handler(output):
|
|
11
|
-
"""处理输出的回调函数"""
|
|
12
|
-
print(f"输出: {output.content}")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def result_handler(result):
|
|
16
|
-
"""处理结果的回调函数"""
|
|
17
|
-
print(f"结果: {result}")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def error_handler(error):
|
|
21
|
-
"""处理错误的回调函数"""
|
|
22
|
-
print(f"错误: {error.name} - {error.value}")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# 创建代码解释器沙箱
|
|
26
|
-
sandbox = Sandbox(template="code-interpreter-v1")
|
|
27
|
-
|
|
28
|
-
print("=== 基础Python代码执行 ===")
|
|
29
|
-
# 基础Python代码执行
|
|
30
|
-
result = sandbox.run_code(
|
|
31
|
-
"""
|
|
32
|
-
print("Hello from CodeInterpreter!")
|
|
33
|
-
x = 1 + 2
|
|
34
|
-
y = x * 3
|
|
35
|
-
print(f"计算结果: x={x}, y={y}")
|
|
36
|
-
{"x": x, "y": y}
|
|
37
|
-
""",
|
|
38
|
-
language="python",
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
print(f"执行结果: {result}")
|
|
42
|
-
print(f"标准输出: {result.logs.stdout}")
|
|
43
|
-
if result.error:
|
|
44
|
-
print(f"错误: {result.error}")
|
|
45
|
-
|
|
46
|
-
print("\n=== 数学计算示例 ===")
|
|
47
|
-
# 数学计算
|
|
48
|
-
math_result = sandbox.run_code(
|
|
49
|
-
"""
|
|
50
|
-
import math
|
|
51
|
-
import numpy as np
|
|
52
|
-
|
|
53
|
-
# 计算圆的面积和周长
|
|
54
|
-
radius = 5
|
|
55
|
-
area = math.pi * radius ** 2
|
|
56
|
-
circumference = 2 * math.pi * radius
|
|
57
|
-
|
|
58
|
-
print(f"半径: {radius}")
|
|
59
|
-
print(f"面积: {area:.2f}")
|
|
60
|
-
print(f"周长: {circumference:.2f}")
|
|
61
|
-
|
|
62
|
-
# 使用numpy
|
|
63
|
-
arr = np.array([1, 2, 3, 4, 5])
|
|
64
|
-
mean_val = np.mean(arr)
|
|
65
|
-
print(f"数组平均值: {mean_val}")
|
|
66
|
-
|
|
67
|
-
{"radius": radius, "area": area, "mean": mean_val}
|
|
68
|
-
"""
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
print(f"数学计算结果: {math_result}")
|
|
72
|
-
|
|
73
|
-
print("\n=== 使用回调函数 ===")
|
|
74
|
-
# 使用回调函数
|
|
75
|
-
callback_result = sandbox.run_code(
|
|
76
|
-
"""
|
|
77
|
-
print("开始执行带回调的代码")
|
|
78
|
-
for i in range(3):
|
|
79
|
-
print(f"步骤 {i+1}")
|
|
80
|
-
|
|
81
|
-
result_data = {"steps": 3, "status": "completed"}
|
|
82
|
-
print(f"执行完成: {result_data}")
|
|
83
|
-
result_data
|
|
84
|
-
""",
|
|
85
|
-
on_stdout=output_handler,
|
|
86
|
-
on_result=result_handler,
|
|
87
|
-
on_error=error_handler,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
print("\n=== 创建和使用上下文 ===")
|
|
91
|
-
# 创建上下文
|
|
92
|
-
context = sandbox.create_code_context(language="python", cwd="/tmp")
|
|
93
|
-
print(f"创建上下文: {context.id}")
|
|
94
|
-
|
|
95
|
-
# 在上下文中执行代码
|
|
96
|
-
context_result1 = sandbox.run_code(
|
|
97
|
-
"""
|
|
98
|
-
# 在上下文中定义变量
|
|
99
|
-
context_var = "Hello from context"
|
|
100
|
-
numbers = [1, 2, 3, 4, 5]
|
|
101
|
-
print(f"定义了变量: {context_var}")
|
|
102
|
-
print(f"数组: {numbers}")
|
|
103
|
-
""",
|
|
104
|
-
context=context,
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
# 在同一上下文中使用变量
|
|
108
|
-
context_result2 = sandbox.run_code(
|
|
109
|
-
"""
|
|
110
|
-
print(f"从上下文读取: {context_var}")
|
|
111
|
-
numbers.append(6)
|
|
112
|
-
print(f"修改后的数组: {numbers}")
|
|
113
|
-
sum(numbers)
|
|
114
|
-
""",
|
|
115
|
-
context=context,
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
print(f"上下文测试结果: {context_result2}")
|
|
119
|
-
|
|
120
|
-
print("\n=== 错误处理示例 ===")
|
|
121
|
-
# 故意产生错误
|
|
122
|
-
error_result = sandbox.run_code(
|
|
123
|
-
"""
|
|
124
|
-
print("这行会执行")
|
|
125
|
-
x = 10 / 0 # 这里会产生除零错误
|
|
126
|
-
print("这行不会执行")
|
|
127
|
-
""",
|
|
128
|
-
on_error=error_handler,
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
print(f"错误处理结果: {error_result.error}")
|
|
132
|
-
|
|
133
|
-
print("\n=== 数据处理示例 ===")
|
|
134
|
-
# 数据处理
|
|
135
|
-
data_result = sandbox.run_code(
|
|
136
|
-
"""
|
|
137
|
-
import pandas as pd
|
|
138
|
-
|
|
139
|
-
# 创建示例数据
|
|
140
|
-
data = {
|
|
141
|
-
'name': ['Alice', 'Bob', 'Charlie'],
|
|
142
|
-
'age': [25, 30, 35],
|
|
143
|
-
'city': ['New York', 'London', 'Tokyo']
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
df = pd.DataFrame(data)
|
|
147
|
-
print("数据框:")
|
|
148
|
-
print(df)
|
|
149
|
-
|
|
150
|
-
# 简单分析
|
|
151
|
-
avg_age = df['age'].mean()
|
|
152
|
-
print(f"平均年龄: {avg_age}")
|
|
153
|
-
|
|
154
|
-
{"total_people": len(df), "avg_age": avg_age}
|
|
155
|
-
"""
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
print(f"数据处理结果: {data_result}")
|
|
159
|
-
|
|
160
|
-
print("\n=== 结果格式示例 ===")
|
|
161
|
-
# 展示不同格式的结果生成
|
|
162
|
-
format_result = sandbox.run_code(
|
|
163
|
-
"""
|
|
164
|
-
import matplotlib.pyplot as plt
|
|
165
|
-
import numpy as np
|
|
166
|
-
import json
|
|
167
|
-
import base64
|
|
168
|
-
import io
|
|
169
|
-
|
|
170
|
-
print("演示多种结果格式:")
|
|
171
|
-
|
|
172
|
-
# 1. 文本格式
|
|
173
|
-
text_result = "这是文本格式的结果示例"
|
|
174
|
-
print(f"文本: {text_result}")
|
|
175
|
-
|
|
176
|
-
# 2. JSON数据格式
|
|
177
|
-
json_data = {
|
|
178
|
-
"test_name": "CodeInterpreter格式测试",
|
|
179
|
-
"formats": ["text", "json", "html", "image"],
|
|
180
|
-
"timestamp": "2024-09-17T10:30:00Z",
|
|
181
|
-
"results": {
|
|
182
|
-
"success": True,
|
|
183
|
-
"format_count": 4
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
print(f"JSON: {json.dumps(json_data, ensure_ascii=False, indent=2)}")
|
|
187
|
-
|
|
188
|
-
# 3. HTML格式示例
|
|
189
|
-
html_content = \"\"\"
|
|
190
|
-
<div class="result-demo">
|
|
191
|
-
<h3>CodeInterpreter 结果格式演示</h3>
|
|
192
|
-
<p><strong>状态:</strong> <span style="color: green;">成功</span></p>
|
|
193
|
-
<ul>
|
|
194
|
-
<li>文本格式支持</li>
|
|
195
|
-
<li>JSON数据结构</li>
|
|
196
|
-
<li>HTML内容渲染</li>
|
|
197
|
-
<li>图像base64编码</li>
|
|
198
|
-
</ul>
|
|
199
|
-
</div>
|
|
200
|
-
\"\"\"
|
|
201
|
-
print(f"HTML: {html_content[:100]}...")
|
|
202
|
-
|
|
203
|
-
# 4. 简单图像生成
|
|
204
|
-
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
|
|
205
|
-
x = np.linspace(0, 2*np.pi, 50)
|
|
206
|
-
y = np.sin(x)
|
|
207
|
-
ax.plot(x, y, 'b-', linewidth=2)
|
|
208
|
-
ax.set_title('简单正弦波示例')
|
|
209
|
-
ax.grid(True)
|
|
210
|
-
|
|
211
|
-
# 转换为base64
|
|
212
|
-
img_buffer = io.BytesIO()
|
|
213
|
-
plt.savefig(img_buffer, format='png', dpi=80, bbox_inches='tight')
|
|
214
|
-
img_buffer.seek(0)
|
|
215
|
-
img_base64 = base64.b64encode(img_buffer.getvalue()).decode()
|
|
216
|
-
img_buffer.close()
|
|
217
|
-
plt.close()
|
|
218
|
-
|
|
219
|
-
print(f"图像: PNG base64编码 ({len(img_base64)} 字符)")
|
|
220
|
-
|
|
221
|
-
# 返回综合结果
|
|
222
|
-
{
|
|
223
|
-
"text": text_result,
|
|
224
|
-
"json_data": json_data,
|
|
225
|
-
"html": html_content,
|
|
226
|
-
"png_base64": img_base64[:50] + "...", # 只显示前50个字符
|
|
227
|
-
"summary": {
|
|
228
|
-
"formats_demonstrated": 4,
|
|
229
|
-
"total_size": len(text_result) + len(str(json_data)) + len(html_content) + len(img_base64),
|
|
230
|
-
"description": "多格式结果演示完成"
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
"""
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
print(f"结果格式测试: {format_result}")
|
|
237
|
-
|
|
238
|
-
print("\n=== 测试完成 ===")
|
|
239
|
-
print("CodeInterpreter基础功能测试完成!")
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Simple sync CodeInterpreter test example.
|
|
4
|
+
Similar to testsandbox_sync.py but for code interpreter functionality.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from scalebox.code_interpreter import Context, Sandbox
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def output_handler(output):
|
|
11
|
+
"""处理输出的回调函数"""
|
|
12
|
+
print(f"输出: {output.content}")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def result_handler(result):
|
|
16
|
+
"""处理结果的回调函数"""
|
|
17
|
+
print(f"结果: {result}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def error_handler(error):
|
|
21
|
+
"""处理错误的回调函数"""
|
|
22
|
+
print(f"错误: {error.name} - {error.value}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 创建代码解释器沙箱
|
|
26
|
+
sandbox = Sandbox(template="code-interpreter-v1")
|
|
27
|
+
|
|
28
|
+
print("=== 基础Python代码执行 ===")
|
|
29
|
+
# 基础Python代码执行
|
|
30
|
+
result = sandbox.run_code(
|
|
31
|
+
"""
|
|
32
|
+
print("Hello from CodeInterpreter!")
|
|
33
|
+
x = 1 + 2
|
|
34
|
+
y = x * 3
|
|
35
|
+
print(f"计算结果: x={x}, y={y}")
|
|
36
|
+
{"x": x, "y": y}
|
|
37
|
+
""",
|
|
38
|
+
language="python",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
print(f"执行结果: {result}")
|
|
42
|
+
print(f"标准输出: {result.logs.stdout}")
|
|
43
|
+
if result.error:
|
|
44
|
+
print(f"错误: {result.error}")
|
|
45
|
+
|
|
46
|
+
print("\n=== 数学计算示例 ===")
|
|
47
|
+
# 数学计算
|
|
48
|
+
math_result = sandbox.run_code(
|
|
49
|
+
"""
|
|
50
|
+
import math
|
|
51
|
+
import numpy as np
|
|
52
|
+
|
|
53
|
+
# 计算圆的面积和周长
|
|
54
|
+
radius = 5
|
|
55
|
+
area = math.pi * radius ** 2
|
|
56
|
+
circumference = 2 * math.pi * radius
|
|
57
|
+
|
|
58
|
+
print(f"半径: {radius}")
|
|
59
|
+
print(f"面积: {area:.2f}")
|
|
60
|
+
print(f"周长: {circumference:.2f}")
|
|
61
|
+
|
|
62
|
+
# 使用numpy
|
|
63
|
+
arr = np.array([1, 2, 3, 4, 5])
|
|
64
|
+
mean_val = np.mean(arr)
|
|
65
|
+
print(f"数组平均值: {mean_val}")
|
|
66
|
+
|
|
67
|
+
{"radius": radius, "area": area, "mean": mean_val}
|
|
68
|
+
"""
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
print(f"数学计算结果: {math_result}")
|
|
72
|
+
|
|
73
|
+
print("\n=== 使用回调函数 ===")
|
|
74
|
+
# 使用回调函数
|
|
75
|
+
callback_result = sandbox.run_code(
|
|
76
|
+
"""
|
|
77
|
+
print("开始执行带回调的代码")
|
|
78
|
+
for i in range(3):
|
|
79
|
+
print(f"步骤 {i+1}")
|
|
80
|
+
|
|
81
|
+
result_data = {"steps": 3, "status": "completed"}
|
|
82
|
+
print(f"执行完成: {result_data}")
|
|
83
|
+
result_data
|
|
84
|
+
""",
|
|
85
|
+
on_stdout=output_handler,
|
|
86
|
+
on_result=result_handler,
|
|
87
|
+
on_error=error_handler,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
print("\n=== 创建和使用上下文 ===")
|
|
91
|
+
# 创建上下文
|
|
92
|
+
context = sandbox.create_code_context(language="python", cwd="/tmp")
|
|
93
|
+
print(f"创建上下文: {context.id}")
|
|
94
|
+
|
|
95
|
+
# 在上下文中执行代码
|
|
96
|
+
context_result1 = sandbox.run_code(
|
|
97
|
+
"""
|
|
98
|
+
# 在上下文中定义变量
|
|
99
|
+
context_var = "Hello from context"
|
|
100
|
+
numbers = [1, 2, 3, 4, 5]
|
|
101
|
+
print(f"定义了变量: {context_var}")
|
|
102
|
+
print(f"数组: {numbers}")
|
|
103
|
+
""",
|
|
104
|
+
context=context,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# 在同一上下文中使用变量
|
|
108
|
+
context_result2 = sandbox.run_code(
|
|
109
|
+
"""
|
|
110
|
+
print(f"从上下文读取: {context_var}")
|
|
111
|
+
numbers.append(6)
|
|
112
|
+
print(f"修改后的数组: {numbers}")
|
|
113
|
+
sum(numbers)
|
|
114
|
+
""",
|
|
115
|
+
context=context,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
print(f"上下文测试结果: {context_result2}")
|
|
119
|
+
|
|
120
|
+
print("\n=== 错误处理示例 ===")
|
|
121
|
+
# 故意产生错误
|
|
122
|
+
error_result = sandbox.run_code(
|
|
123
|
+
"""
|
|
124
|
+
print("这行会执行")
|
|
125
|
+
x = 10 / 0 # 这里会产生除零错误
|
|
126
|
+
print("这行不会执行")
|
|
127
|
+
""",
|
|
128
|
+
on_error=error_handler,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
print(f"错误处理结果: {error_result.error}")
|
|
132
|
+
|
|
133
|
+
print("\n=== 数据处理示例 ===")
|
|
134
|
+
# 数据处理
|
|
135
|
+
data_result = sandbox.run_code(
|
|
136
|
+
"""
|
|
137
|
+
import pandas as pd
|
|
138
|
+
|
|
139
|
+
# 创建示例数据
|
|
140
|
+
data = {
|
|
141
|
+
'name': ['Alice', 'Bob', 'Charlie'],
|
|
142
|
+
'age': [25, 30, 35],
|
|
143
|
+
'city': ['New York', 'London', 'Tokyo']
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
df = pd.DataFrame(data)
|
|
147
|
+
print("数据框:")
|
|
148
|
+
print(df)
|
|
149
|
+
|
|
150
|
+
# 简单分析
|
|
151
|
+
avg_age = df['age'].mean()
|
|
152
|
+
print(f"平均年龄: {avg_age}")
|
|
153
|
+
|
|
154
|
+
{"total_people": len(df), "avg_age": avg_age}
|
|
155
|
+
"""
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
print(f"数据处理结果: {data_result}")
|
|
159
|
+
|
|
160
|
+
print("\n=== 结果格式示例 ===")
|
|
161
|
+
# 展示不同格式的结果生成
|
|
162
|
+
format_result = sandbox.run_code(
|
|
163
|
+
"""
|
|
164
|
+
import matplotlib.pyplot as plt
|
|
165
|
+
import numpy as np
|
|
166
|
+
import json
|
|
167
|
+
import base64
|
|
168
|
+
import io
|
|
169
|
+
|
|
170
|
+
print("演示多种结果格式:")
|
|
171
|
+
|
|
172
|
+
# 1. 文本格式
|
|
173
|
+
text_result = "这是文本格式的结果示例"
|
|
174
|
+
print(f"文本: {text_result}")
|
|
175
|
+
|
|
176
|
+
# 2. JSON数据格式
|
|
177
|
+
json_data = {
|
|
178
|
+
"test_name": "CodeInterpreter格式测试",
|
|
179
|
+
"formats": ["text", "json", "html", "image"],
|
|
180
|
+
"timestamp": "2024-09-17T10:30:00Z",
|
|
181
|
+
"results": {
|
|
182
|
+
"success": True,
|
|
183
|
+
"format_count": 4
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
print(f"JSON: {json.dumps(json_data, ensure_ascii=False, indent=2)}")
|
|
187
|
+
|
|
188
|
+
# 3. HTML格式示例
|
|
189
|
+
html_content = \"\"\"
|
|
190
|
+
<div class="result-demo">
|
|
191
|
+
<h3>CodeInterpreter 结果格式演示</h3>
|
|
192
|
+
<p><strong>状态:</strong> <span style="color: green;">成功</span></p>
|
|
193
|
+
<ul>
|
|
194
|
+
<li>文本格式支持</li>
|
|
195
|
+
<li>JSON数据结构</li>
|
|
196
|
+
<li>HTML内容渲染</li>
|
|
197
|
+
<li>图像base64编码</li>
|
|
198
|
+
</ul>
|
|
199
|
+
</div>
|
|
200
|
+
\"\"\"
|
|
201
|
+
print(f"HTML: {html_content[:100]}...")
|
|
202
|
+
|
|
203
|
+
# 4. 简单图像生成
|
|
204
|
+
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
|
|
205
|
+
x = np.linspace(0, 2*np.pi, 50)
|
|
206
|
+
y = np.sin(x)
|
|
207
|
+
ax.plot(x, y, 'b-', linewidth=2)
|
|
208
|
+
ax.set_title('简单正弦波示例')
|
|
209
|
+
ax.grid(True)
|
|
210
|
+
|
|
211
|
+
# 转换为base64
|
|
212
|
+
img_buffer = io.BytesIO()
|
|
213
|
+
plt.savefig(img_buffer, format='png', dpi=80, bbox_inches='tight')
|
|
214
|
+
img_buffer.seek(0)
|
|
215
|
+
img_base64 = base64.b64encode(img_buffer.getvalue()).decode()
|
|
216
|
+
img_buffer.close()
|
|
217
|
+
plt.close()
|
|
218
|
+
|
|
219
|
+
print(f"图像: PNG base64编码 ({len(img_base64)} 字符)")
|
|
220
|
+
|
|
221
|
+
# 返回综合结果
|
|
222
|
+
{
|
|
223
|
+
"text": text_result,
|
|
224
|
+
"json_data": json_data,
|
|
225
|
+
"html": html_content,
|
|
226
|
+
"png_base64": img_base64[:50] + "...", # 只显示前50个字符
|
|
227
|
+
"summary": {
|
|
228
|
+
"formats_demonstrated": 4,
|
|
229
|
+
"total_size": len(text_result) + len(str(json_data)) + len(html_content) + len(img_base64),
|
|
230
|
+
"description": "多格式结果演示完成"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
"""
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
print(f"结果格式测试: {format_result}")
|
|
237
|
+
|
|
238
|
+
print("\n=== 测试完成 ===")
|
|
239
|
+
print("CodeInterpreter基础功能测试完成!")
|
scalebox/test/testcomputeuse.py
CHANGED
|
@@ -108,7 +108,7 @@ def desktop_automation_demo():
|
|
|
108
108
|
|
|
109
109
|
# 创建测试文件
|
|
110
110
|
test_content = """Hello World!
|
|
111
|
-
This is a test file created from
|
|
111
|
+
This is a test file created from Scalebox Sandbox SDK.
|
|
112
112
|
Current time: {time}
|
|
113
113
|
""".format(
|
|
114
114
|
time=time.ctime()
|
|
@@ -192,7 +192,7 @@ print("success!")
|
|
|
192
192
|
# desktop.write("https://www.google.com")
|
|
193
193
|
# desktop.press("enter")
|
|
194
194
|
# time.sleep(2)
|
|
195
|
-
# desktop.write("
|
|
195
|
+
# desktop.write("Scalebox Sandbox Automation")
|
|
196
196
|
# desktop.press("enter")
|
|
197
197
|
# # 更多网页自动化操作...
|
|
198
198
|
#
|
scalebox/test/testnovnc.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
from email.mime import application
|
|
2
|
-
|
|
3
|
-
from csx_desktop.main import Sandbox
|
|
4
|
-
|
|
5
|
-
sandbox = Sandbox()
|
|
6
|
-
sandbox.stream.start()
|
|
7
|
-
|
|
8
|
-
print(sandbox.get_screen_size())
|
|
9
|
-
sandbox.launch("firefox-esr")
|
|
10
|
-
windpws_id = sandbox.get_current_window_id()
|
|
11
|
-
print(windpws_id)
|
|
12
|
-
print(sandbox.get_window_title(window_id=windpws_id))
|
|
1
|
+
from email.mime import application
|
|
2
|
+
|
|
3
|
+
from csx_desktop.main import Sandbox
|
|
4
|
+
|
|
5
|
+
sandbox = Sandbox()
|
|
6
|
+
sandbox.stream.start()
|
|
7
|
+
|
|
8
|
+
print(sandbox.get_screen_size())
|
|
9
|
+
sandbox.launch("firefox-esr")
|
|
10
|
+
windpws_id = sandbox.get_current_window_id()
|
|
11
|
+
print(windpws_id)
|
|
12
|
+
print(sandbox.get_window_title(window_id=windpws_id))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from scalebox.sandbox.commands.command_handle import PtySize
|
|
4
|
+
from scalebox.sandbox_sync.main import Sandbox
|
|
5
|
+
|
|
6
|
+
def output_handler(output):
|
|
7
|
+
"""处理 输出的回调函数"""
|
|
8
|
+
print(f"PTY 输出: {output}")
|
|
9
|
+
|
|
10
|
+
sandboxes=Sandbox.list()
|
|
11
|
+
print(sandboxes)
|
|
12
|
+
box=Sandbox.connect(sandbox_id="sbx-0b3ccqezz67asn3ax")
|
|
13
|
+
print(box)
|
|
14
|
+
result=box.commands.run("ls")
|
|
15
|
+
print(result)
|