scalebox-sdk 0.1.25__py3-none-any.whl → 1.0.1__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 +2 -2
- scalebox/api/__init__.py +3 -1
- scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_connect.py +193 -0
- scalebox/api/client/models/connect_sandbox.py +59 -0
- scalebox/api/client/models/error.py +2 -2
- scalebox/api/client/models/listed_sandbox.py +19 -1
- scalebox/api/client/models/new_sandbox.py +10 -0
- scalebox/api/client/models/sandbox.py +13 -0
- scalebox/api/client/models/sandbox_detail.py +24 -0
- scalebox/cli.py +125 -125
- scalebox/client/aclient.py +57 -57
- scalebox/client/client.py +102 -102
- scalebox/code_interpreter/__init__.py +12 -12
- scalebox/code_interpreter/charts.py +230 -230
- scalebox/code_interpreter/constants.py +3 -3
- scalebox/code_interpreter/exceptions.py +13 -13
- scalebox/code_interpreter/models.py +485 -485
- scalebox/connection_config.py +34 -1
- scalebox/csx_connect/__init__.py +1 -1
- scalebox/csx_connect/client.py +485 -485
- scalebox/csx_desktop/main.py +651 -651
- scalebox/exceptions.py +83 -83
- scalebox/generated/api.py +61 -61
- scalebox/generated/api_pb2.py +203 -203
- scalebox/generated/api_pb2.pyi +956 -956
- scalebox/generated/api_pb2_connect.py +1407 -1407
- scalebox/generated/rpc.py +50 -50
- scalebox/sandbox/main.py +146 -139
- scalebox/sandbox/sandbox_api.py +105 -91
- scalebox/sandbox/signature.py +40 -40
- scalebox/sandbox/utils.py +34 -34
- scalebox/sandbox_async/main.py +226 -44
- scalebox/sandbox_async/sandbox_api.py +124 -3
- scalebox/sandbox_sync/main.py +205 -130
- scalebox/sandbox_sync/sandbox_api.py +119 -3
- scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -323
- scalebox/test/README.md +329 -329
- scalebox/test/bedrock_openai_adapter.py +67 -0
- scalebox/test/code_interpreter_test.py +34 -34
- scalebox/test/code_interpreter_test_sync.py +34 -34
- scalebox/test/run_stress_code_interpreter_sync.py +166 -0
- scalebox/test/simple_upload_example.py +123 -0
- scalebox/test/stabitiy_test.py +310 -0
- scalebox/test/test_browser_use.py +25 -0
- scalebox/test/test_browser_use_scalebox.py +61 -0
- scalebox/test/test_code_interpreter_sync_comprehensive.py +115 -65
- scalebox/test/test_connect_pause_async.py +277 -0
- scalebox/test/test_connect_pause_sync.py +267 -0
- scalebox/test/test_desktop_sandbox_sf.py +117 -0
- scalebox/test/test_download_url.py +49 -0
- scalebox/test/test_sandbox_async_comprehensive.py +1 -1
- scalebox/test/test_sandbox_object_storage_example.py +146 -0
- scalebox/test/test_sandbox_object_storage_example_async.py +156 -0
- scalebox/test/test_sf.py +137 -0
- scalebox/test/test_watch_dir_async.py +56 -0
- scalebox/test/testacreate.py +1 -1
- scalebox/test/testagetinfo.py +1 -1
- scalebox/test/testcomputeuse.py +243 -243
- scalebox/test/testsandbox_api.py +1 -3
- scalebox/test/testsandbox_sync.py +1 -1
- scalebox/test/upload_100mb_example.py +355 -0
- scalebox/utils/httpcoreclient.py +297 -297
- scalebox/utils/httpxclient.py +403 -403
- scalebox/version.py +2 -2
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/METADATA +1 -1
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/RECORD +70 -53
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/WHEEL +1 -1
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/entry_points.txt +0 -0
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/licenses/LICENSE +0 -0
- {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/top_level.txt +0 -0
scalebox/cli.py
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Command-line interface for ScaleBox Python SDK
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import argparse
|
|
6
|
-
import asyncio
|
|
7
|
-
import sys
|
|
8
|
-
from typing import Optional
|
|
9
|
-
|
|
10
|
-
from . import __version__
|
|
11
|
-
from .code_interpreter import AsyncSandbox, Sandbox
|
|
12
|
-
from .connection_config import ConnectionConfig
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def create_parser() -> argparse.ArgumentParser:
|
|
16
|
-
"""Create the command-line argument parser."""
|
|
17
|
-
parser = argparse.ArgumentParser(
|
|
18
|
-
prog="scalebox",
|
|
19
|
-
description="ScaleBox Python SDK - Multi-language code execution sandbox",
|
|
20
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
parser.add_argument(
|
|
24
|
-
"--version",
|
|
25
|
-
action="version",
|
|
26
|
-
version=f"ScaleBox Python SDK {__version__}",
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
30
|
-
|
|
31
|
-
# Sandbox command
|
|
32
|
-
sandbox_parser = subparsers.add_parser("sandbox", help="Sandbox operations")
|
|
33
|
-
sandbox_parser.add_argument(
|
|
34
|
-
"--create", action="store_true", help="Create a new sandbox"
|
|
35
|
-
)
|
|
36
|
-
sandbox_parser.add_argument("--list", action="store_true", help="List sandboxes")
|
|
37
|
-
sandbox_parser.add_argument("--destroy", help="Destroy a sandbox by ID")
|
|
38
|
-
|
|
39
|
-
# Code execution command
|
|
40
|
-
exec_parser = subparsers.add_parser("exec", help="Execute code")
|
|
41
|
-
exec_parser.add_argument("--code", required=True, help="Code to execute")
|
|
42
|
-
exec_parser.add_argument(
|
|
43
|
-
"--language", default="python", help="Programming language"
|
|
44
|
-
)
|
|
45
|
-
exec_parser.add_argument("--sandbox-id", help="Sandbox ID to use")
|
|
46
|
-
exec_parser.add_argument(
|
|
47
|
-
"--async-mode", action="store_true", help="Use async execution"
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
# Configuration
|
|
51
|
-
parser.add_argument("--api-key", help="API key for authentication")
|
|
52
|
-
parser.add_argument("--domain", help="API domain")
|
|
53
|
-
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
|
|
54
|
-
|
|
55
|
-
return parser
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
async def async_main():
|
|
59
|
-
"""Async main function."""
|
|
60
|
-
parser = create_parser()
|
|
61
|
-
args = parser.parse_args()
|
|
62
|
-
|
|
63
|
-
if not args.command:
|
|
64
|
-
parser.print_help()
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
# Create connection config
|
|
68
|
-
config = ConnectionConfig(
|
|
69
|
-
api_key=args.api_key,
|
|
70
|
-
domain=args.domain,
|
|
71
|
-
debug=args.debug,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
if args.command == "sandbox":
|
|
75
|
-
if args.create:
|
|
76
|
-
print("Creating sandbox...")
|
|
77
|
-
if args.async_mode:
|
|
78
|
-
sandbox = await AsyncSandbox.create()
|
|
79
|
-
print(f"Created async sandbox: {sandbox.id}")
|
|
80
|
-
else:
|
|
81
|
-
sandbox = Sandbox.create()
|
|
82
|
-
print(f"Created sandbox: {sandbox.id}")
|
|
83
|
-
elif args.list:
|
|
84
|
-
print("Listing sandboxes...")
|
|
85
|
-
# TODO: Implement sandbox listing
|
|
86
|
-
print("Sandbox listing not implemented yet")
|
|
87
|
-
elif args.destroy:
|
|
88
|
-
print(f"Destroying sandbox: {args.destroy}")
|
|
89
|
-
# TODO: Implement sandbox destruction
|
|
90
|
-
print("Sandbox destruction not implemented yet")
|
|
91
|
-
|
|
92
|
-
elif args.command == "exec":
|
|
93
|
-
print(f"Executing {args.language} code...")
|
|
94
|
-
print(f"Code: {args.code}")
|
|
95
|
-
|
|
96
|
-
if args.async_mode:
|
|
97
|
-
sandbox = await AsyncSandbox.create()
|
|
98
|
-
try:
|
|
99
|
-
result = await sandbox.run_code(args.code, language=args.language)
|
|
100
|
-
print(f"Result: {result.logs.stdout}")
|
|
101
|
-
finally:
|
|
102
|
-
await sandbox.close()
|
|
103
|
-
else:
|
|
104
|
-
sandbox = Sandbox.create()
|
|
105
|
-
try:
|
|
106
|
-
result = sandbox.run_code(args.code, language=args.language)
|
|
107
|
-
print(f"Result: {result.logs.stdout}")
|
|
108
|
-
finally:
|
|
109
|
-
sandbox.close()
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def main():
|
|
113
|
-
"""Main entry point."""
|
|
114
|
-
try:
|
|
115
|
-
asyncio.run(async_main())
|
|
116
|
-
except KeyboardInterrupt:
|
|
117
|
-
print("\nOperation cancelled by user")
|
|
118
|
-
sys.exit(1)
|
|
119
|
-
except Exception as e:
|
|
120
|
-
print(f"Error: {e}")
|
|
121
|
-
sys.exit(1)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if __name__ == "__main__":
|
|
125
|
-
main()
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for ScaleBox Python SDK
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import sys
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .code_interpreter import AsyncSandbox, Sandbox
|
|
12
|
+
from .connection_config import ConnectionConfig
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create_parser() -> argparse.ArgumentParser:
|
|
16
|
+
"""Create the command-line argument parser."""
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="scalebox",
|
|
19
|
+
description="ScaleBox Python SDK - Multi-language code execution sandbox",
|
|
20
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"--version",
|
|
25
|
+
action="version",
|
|
26
|
+
version=f"ScaleBox Python SDK {__version__}",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
30
|
+
|
|
31
|
+
# Sandbox command
|
|
32
|
+
sandbox_parser = subparsers.add_parser("sandbox", help="Sandbox operations")
|
|
33
|
+
sandbox_parser.add_argument(
|
|
34
|
+
"--create", action="store_true", help="Create a new sandbox"
|
|
35
|
+
)
|
|
36
|
+
sandbox_parser.add_argument("--list", action="store_true", help="List sandboxes")
|
|
37
|
+
sandbox_parser.add_argument("--destroy", help="Destroy a sandbox by ID")
|
|
38
|
+
|
|
39
|
+
# Code execution command
|
|
40
|
+
exec_parser = subparsers.add_parser("exec", help="Execute code")
|
|
41
|
+
exec_parser.add_argument("--code", required=True, help="Code to execute")
|
|
42
|
+
exec_parser.add_argument(
|
|
43
|
+
"--language", default="python", help="Programming language"
|
|
44
|
+
)
|
|
45
|
+
exec_parser.add_argument("--sandbox-id", help="Sandbox ID to use")
|
|
46
|
+
exec_parser.add_argument(
|
|
47
|
+
"--async-mode", action="store_true", help="Use async execution"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Configuration
|
|
51
|
+
parser.add_argument("--api-key", help="API key for authentication")
|
|
52
|
+
parser.add_argument("--domain", help="API domain")
|
|
53
|
+
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
|
|
54
|
+
|
|
55
|
+
return parser
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def async_main():
|
|
59
|
+
"""Async main function."""
|
|
60
|
+
parser = create_parser()
|
|
61
|
+
args = parser.parse_args()
|
|
62
|
+
|
|
63
|
+
if not args.command:
|
|
64
|
+
parser.print_help()
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
# Create connection config
|
|
68
|
+
config = ConnectionConfig(
|
|
69
|
+
api_key=args.api_key,
|
|
70
|
+
domain=args.domain,
|
|
71
|
+
debug=args.debug,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if args.command == "sandbox":
|
|
75
|
+
if args.create:
|
|
76
|
+
print("Creating sandbox...")
|
|
77
|
+
if args.async_mode:
|
|
78
|
+
sandbox = await AsyncSandbox.create()
|
|
79
|
+
print(f"Created async sandbox: {sandbox.id}")
|
|
80
|
+
else:
|
|
81
|
+
sandbox = Sandbox.create()
|
|
82
|
+
print(f"Created sandbox: {sandbox.id}")
|
|
83
|
+
elif args.list:
|
|
84
|
+
print("Listing sandboxes...")
|
|
85
|
+
# TODO: Implement sandbox listing
|
|
86
|
+
print("Sandbox listing not implemented yet")
|
|
87
|
+
elif args.destroy:
|
|
88
|
+
print(f"Destroying sandbox: {args.destroy}")
|
|
89
|
+
# TODO: Implement sandbox destruction
|
|
90
|
+
print("Sandbox destruction not implemented yet")
|
|
91
|
+
|
|
92
|
+
elif args.command == "exec":
|
|
93
|
+
print(f"Executing {args.language} code...")
|
|
94
|
+
print(f"Code: {args.code}")
|
|
95
|
+
|
|
96
|
+
if args.async_mode:
|
|
97
|
+
sandbox = await AsyncSandbox.create()
|
|
98
|
+
try:
|
|
99
|
+
result = await sandbox.run_code(args.code, language=args.language)
|
|
100
|
+
print(f"Result: {result.logs.stdout}")
|
|
101
|
+
finally:
|
|
102
|
+
await sandbox.close()
|
|
103
|
+
else:
|
|
104
|
+
sandbox = Sandbox.create()
|
|
105
|
+
try:
|
|
106
|
+
result = sandbox.run_code(args.code, language=args.language)
|
|
107
|
+
print(f"Result: {result.logs.stdout}")
|
|
108
|
+
finally:
|
|
109
|
+
sandbox.close()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main():
|
|
113
|
+
"""Main entry point."""
|
|
114
|
+
try:
|
|
115
|
+
asyncio.run(async_main())
|
|
116
|
+
except KeyboardInterrupt:
|
|
117
|
+
print("\nOperation cancelled by user")
|
|
118
|
+
sys.exit(1)
|
|
119
|
+
except Exception as e:
|
|
120
|
+
print(f"Error: {e}")
|
|
121
|
+
sys.exit(1)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
main()
|
scalebox/client/aclient.py
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
# import sys, os
|
|
2
|
-
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../scalebox'))
|
|
3
|
-
import asyncio
|
|
4
|
-
|
|
5
|
-
import aiohttp
|
|
6
|
-
from generated import api_pb2
|
|
7
|
-
from generated.api_pb2_connect import AsyncFilesystemClient
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async def watch_directory_example():
|
|
11
|
-
# 创建 aiohttp 客户端会话
|
|
12
|
-
async with aiohttp.ClientSession() as session:
|
|
13
|
-
# 创建文件系统客户端
|
|
14
|
-
client = AsyncFilesystemClient(
|
|
15
|
-
base_url="http://localhost:8080",
|
|
16
|
-
http_client=session,
|
|
17
|
-
# protocol=ConnectProtocol.CONNECT_PROTOBUF # 如果需要指定协议
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
# 创建监视请求
|
|
21
|
-
request = api_pb2.WatchDirRequest(path="/root")
|
|
22
|
-
|
|
23
|
-
# 可选:添加额外的请求头
|
|
24
|
-
extra_headers = {
|
|
25
|
-
"Authorization": "Bearer root",
|
|
26
|
-
"X-Custom-Header": "custom-value",
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try:
|
|
30
|
-
# 使用 async for 循环处理流式响应
|
|
31
|
-
async for response in client.watch_dir(
|
|
32
|
-
request, extra_headers=extra_headers
|
|
33
|
-
):
|
|
34
|
-
print(f"Received event: {response}")
|
|
35
|
-
# 在这里处理每个事件
|
|
36
|
-
# 例如,根据事件类型执行不同的操作
|
|
37
|
-
|
|
38
|
-
# 如果收到特定事件,可以中断循环
|
|
39
|
-
# if response.event_type == api_pb2.WatchDirResponse.EVENT_TYPE_STOP:
|
|
40
|
-
# break
|
|
41
|
-
|
|
42
|
-
except Exception as e:
|
|
43
|
-
print(f"Error during directory watching: {e}")
|
|
44
|
-
|
|
45
|
-
finally:
|
|
46
|
-
# 关闭会话(在 with 语句中会自动关闭,但这里为了清晰展示)
|
|
47
|
-
await session.close()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
async def main():
|
|
51
|
-
# 运行监视示例
|
|
52
|
-
await watch_directory_example()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if __name__ == "__main__":
|
|
56
|
-
# 运行异步主函数
|
|
57
|
-
asyncio.run(main())
|
|
1
|
+
# import sys, os
|
|
2
|
+
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../scalebox'))
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
from generated import api_pb2
|
|
7
|
+
from generated.api_pb2_connect import AsyncFilesystemClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def watch_directory_example():
|
|
11
|
+
# 创建 aiohttp 客户端会话
|
|
12
|
+
async with aiohttp.ClientSession() as session:
|
|
13
|
+
# 创建文件系统客户端
|
|
14
|
+
client = AsyncFilesystemClient(
|
|
15
|
+
base_url="http://localhost:8080",
|
|
16
|
+
http_client=session,
|
|
17
|
+
# protocol=ConnectProtocol.CONNECT_PROTOBUF # 如果需要指定协议
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# 创建监视请求
|
|
21
|
+
request = api_pb2.WatchDirRequest(path="/root")
|
|
22
|
+
|
|
23
|
+
# 可选:添加额外的请求头
|
|
24
|
+
extra_headers = {
|
|
25
|
+
"Authorization": "Bearer root",
|
|
26
|
+
"X-Custom-Header": "custom-value",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
# 使用 async for 循环处理流式响应
|
|
31
|
+
async for response in client.watch_dir(
|
|
32
|
+
request, extra_headers=extra_headers
|
|
33
|
+
):
|
|
34
|
+
print(f"Received event: {response}")
|
|
35
|
+
# 在这里处理每个事件
|
|
36
|
+
# 例如,根据事件类型执行不同的操作
|
|
37
|
+
|
|
38
|
+
# 如果收到特定事件,可以中断循环
|
|
39
|
+
# if response.event_type == api_pb2.WatchDirResponse.EVENT_TYPE_STOP:
|
|
40
|
+
# break
|
|
41
|
+
|
|
42
|
+
except Exception as e:
|
|
43
|
+
print(f"Error during directory watching: {e}")
|
|
44
|
+
|
|
45
|
+
finally:
|
|
46
|
+
# 关闭会话(在 with 语句中会自动关闭,但这里为了清晰展示)
|
|
47
|
+
await session.close()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def main():
|
|
51
|
+
# 运行监视示例
|
|
52
|
+
await watch_directory_example()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
# 运行异步主函数
|
|
57
|
+
asyncio.run(main())
|
scalebox/client/client.py
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
from utils.httpxclient import HTTPXClient
|
|
5
|
-
|
|
6
|
-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "generated"))
|
|
7
|
-
|
|
8
|
-
import asyncio
|
|
9
|
-
|
|
10
|
-
import httpx
|
|
11
|
-
from generated import api_pb2
|
|
12
|
-
from generated.api_pb2_connect import AsyncFilesystemClient
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# 自定义 HTTP 客户端适配器
|
|
16
|
-
class CustomHTTPClient:
|
|
17
|
-
def __init__(self):
|
|
18
|
-
self.client = httpx.Client()
|
|
19
|
-
|
|
20
|
-
def request(self, method, url, headers, content, timeout, extensions):
|
|
21
|
-
# 移除可能导致问题的参数或调整调用方式
|
|
22
|
-
# 根据 ConnectRPC 的实际需求调整
|
|
23
|
-
try:
|
|
24
|
-
response = self.client.request(
|
|
25
|
-
method=method,
|
|
26
|
-
url=url,
|
|
27
|
-
headers=headers,
|
|
28
|
-
content=content,
|
|
29
|
-
timeout=timeout,
|
|
30
|
-
)
|
|
31
|
-
return response
|
|
32
|
-
except TypeError as e:
|
|
33
|
-
# 如果仍然有参数问题,尝试不同的调用方式
|
|
34
|
-
if "unexpected keyword argument" in str(e):
|
|
35
|
-
# 移除有问题的参数
|
|
36
|
-
kwargs = {
|
|
37
|
-
"method": method,
|
|
38
|
-
"url": url,
|
|
39
|
-
"headers": headers,
|
|
40
|
-
"content": content,
|
|
41
|
-
"timeout": timeout,
|
|
42
|
-
}
|
|
43
|
-
# 移除可能引起问题的参数
|
|
44
|
-
if "body" in str(e):
|
|
45
|
-
kwargs.pop("content", None)
|
|
46
|
-
|
|
47
|
-
response = self.client.request(**kwargs)
|
|
48
|
-
return response
|
|
49
|
-
raise
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
async def main():
|
|
53
|
-
# 创建客户端
|
|
54
|
-
client = AsyncFilesystemClient(
|
|
55
|
-
base_url="http://localhost:8080", http_client=HTTPXClient
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
# 调用服务器流式方法
|
|
59
|
-
# extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
|
|
60
|
-
# "Keepalive-Ping-Interval":1000}
|
|
61
|
-
extra = {"Authorization": "Bearer root"}
|
|
62
|
-
# resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
|
|
63
|
-
# print(resp)
|
|
64
|
-
# print(resp.entry)
|
|
65
|
-
# stream = fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"), extra_headers=extra)
|
|
66
|
-
# request = RequestType(your_field="value")
|
|
67
|
-
|
|
68
|
-
# 处理流式响应
|
|
69
|
-
async for response in client.watch_dir(
|
|
70
|
-
api_pb2.WatchDirRequest(path="/root"), extra_headers=extra
|
|
71
|
-
):
|
|
72
|
-
print(f"Received: {response}")
|
|
73
|
-
# 处理每个响应项
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if __name__ == "__main__":
|
|
77
|
-
asyncio.run(main())
|
|
78
|
-
|
|
79
|
-
# print("Available protocol options:")
|
|
80
|
-
# print(f"CONNECT_PROTOBUF: {ConnectProtocol.CONNECT_PROTOBUF}")
|
|
81
|
-
# print(f"CONNECT_JSON: {ConnectProtocol.CONNECT_JSON}")
|
|
82
|
-
# # print(f"GRPC_PROTOBUF: {ConnectProtocol.GRPC_PROTOBUF}")
|
|
83
|
-
# # print(f"GRPC_JSON: {ConnectProtocol.GRPC_JSON}")
|
|
84
|
-
# BASE = "http://localhost:8080"
|
|
85
|
-
# # client = CustomHTTPClient()
|
|
86
|
-
# fs_cli=FilesystemClient(base_url=BASE,protocol=ConnectProtocol.CONNECT_PROTOBUF)
|
|
87
|
-
# # extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
|
|
88
|
-
# # "Keepalive-Ping-Interval":1000}
|
|
89
|
-
# extra = {"Authorization": "Bearer root"}
|
|
90
|
-
# # resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
|
|
91
|
-
# # print(resp)
|
|
92
|
-
# # print(resp.entry)
|
|
93
|
-
# stream=fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"),extra_headers=extra)
|
|
94
|
-
# # 3. 消费流
|
|
95
|
-
# print("-------------------------")
|
|
96
|
-
# for resp in stream:
|
|
97
|
-
# # resp 就是 api_pb2.WatchDirResponse
|
|
98
|
-
# print(resp)
|
|
99
|
-
#
|
|
100
|
-
# # 4. 检查错误(可选)
|
|
101
|
-
# if stream.error():
|
|
102
|
-
# raise stream.error()
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from utils.httpxclient import HTTPXClient
|
|
5
|
+
|
|
6
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "generated"))
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
from generated import api_pb2
|
|
12
|
+
from generated.api_pb2_connect import AsyncFilesystemClient
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# 自定义 HTTP 客户端适配器
|
|
16
|
+
class CustomHTTPClient:
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self.client = httpx.Client()
|
|
19
|
+
|
|
20
|
+
def request(self, method, url, headers, content, timeout, extensions):
|
|
21
|
+
# 移除可能导致问题的参数或调整调用方式
|
|
22
|
+
# 根据 ConnectRPC 的实际需求调整
|
|
23
|
+
try:
|
|
24
|
+
response = self.client.request(
|
|
25
|
+
method=method,
|
|
26
|
+
url=url,
|
|
27
|
+
headers=headers,
|
|
28
|
+
content=content,
|
|
29
|
+
timeout=timeout,
|
|
30
|
+
)
|
|
31
|
+
return response
|
|
32
|
+
except TypeError as e:
|
|
33
|
+
# 如果仍然有参数问题,尝试不同的调用方式
|
|
34
|
+
if "unexpected keyword argument" in str(e):
|
|
35
|
+
# 移除有问题的参数
|
|
36
|
+
kwargs = {
|
|
37
|
+
"method": method,
|
|
38
|
+
"url": url,
|
|
39
|
+
"headers": headers,
|
|
40
|
+
"content": content,
|
|
41
|
+
"timeout": timeout,
|
|
42
|
+
}
|
|
43
|
+
# 移除可能引起问题的参数
|
|
44
|
+
if "body" in str(e):
|
|
45
|
+
kwargs.pop("content", None)
|
|
46
|
+
|
|
47
|
+
response = self.client.request(**kwargs)
|
|
48
|
+
return response
|
|
49
|
+
raise
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def main():
|
|
53
|
+
# 创建客户端
|
|
54
|
+
client = AsyncFilesystemClient(
|
|
55
|
+
base_url="http://localhost:8080", http_client=HTTPXClient
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# 调用服务器流式方法
|
|
59
|
+
# extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
|
|
60
|
+
# "Keepalive-Ping-Interval":1000}
|
|
61
|
+
extra = {"Authorization": "Bearer root"}
|
|
62
|
+
# resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
|
|
63
|
+
# print(resp)
|
|
64
|
+
# print(resp.entry)
|
|
65
|
+
# stream = fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"), extra_headers=extra)
|
|
66
|
+
# request = RequestType(your_field="value")
|
|
67
|
+
|
|
68
|
+
# 处理流式响应
|
|
69
|
+
async for response in client.watch_dir(
|
|
70
|
+
api_pb2.WatchDirRequest(path="/root"), extra_headers=extra
|
|
71
|
+
):
|
|
72
|
+
print(f"Received: {response}")
|
|
73
|
+
# 处理每个响应项
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
asyncio.run(main())
|
|
78
|
+
|
|
79
|
+
# print("Available protocol options:")
|
|
80
|
+
# print(f"CONNECT_PROTOBUF: {ConnectProtocol.CONNECT_PROTOBUF}")
|
|
81
|
+
# print(f"CONNECT_JSON: {ConnectProtocol.CONNECT_JSON}")
|
|
82
|
+
# # print(f"GRPC_PROTOBUF: {ConnectProtocol.GRPC_PROTOBUF}")
|
|
83
|
+
# # print(f"GRPC_JSON: {ConnectProtocol.GRPC_JSON}")
|
|
84
|
+
# BASE = "http://localhost:8080"
|
|
85
|
+
# # client = CustomHTTPClient()
|
|
86
|
+
# fs_cli=FilesystemClient(base_url=BASE,protocol=ConnectProtocol.CONNECT_PROTOBUF)
|
|
87
|
+
# # extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
|
|
88
|
+
# # "Keepalive-Ping-Interval":1000}
|
|
89
|
+
# extra = {"Authorization": "Bearer root"}
|
|
90
|
+
# # resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
|
|
91
|
+
# # print(resp)
|
|
92
|
+
# # print(resp.entry)
|
|
93
|
+
# stream=fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"),extra_headers=extra)
|
|
94
|
+
# # 3. 消费流
|
|
95
|
+
# print("-------------------------")
|
|
96
|
+
# for resp in stream:
|
|
97
|
+
# # resp 就是 api_pb2.WatchDirResponse
|
|
98
|
+
# print(resp)
|
|
99
|
+
#
|
|
100
|
+
# # 4. 检查错误(可选)
|
|
101
|
+
# if stream.error():
|
|
102
|
+
# raise stream.error()
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
from .code_interpreter_async import AsyncSandbox
|
|
2
|
-
from .code_interpreter_sync import Sandbox
|
|
3
|
-
from .models import (
|
|
4
|
-
Context,
|
|
5
|
-
Execution,
|
|
6
|
-
ExecutionError,
|
|
7
|
-
Logs,
|
|
8
|
-
MIMEType,
|
|
9
|
-
OutputHandler,
|
|
10
|
-
OutputMessage,
|
|
11
|
-
Result,
|
|
12
|
-
)
|
|
1
|
+
from .code_interpreter_async import AsyncSandbox
|
|
2
|
+
from .code_interpreter_sync import Sandbox
|
|
3
|
+
from .models import (
|
|
4
|
+
Context,
|
|
5
|
+
Execution,
|
|
6
|
+
ExecutionError,
|
|
7
|
+
Logs,
|
|
8
|
+
MIMEType,
|
|
9
|
+
OutputHandler,
|
|
10
|
+
OutputMessage,
|
|
11
|
+
Result,
|
|
12
|
+
)
|