agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.0__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.
- agentscope_runtime/adapters/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
- agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
- agentscope_runtime/adapters/agentscope/message.py +535 -0
- agentscope_runtime/adapters/agentscope/stream.py +506 -0
- agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
- agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
- agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
- agentscope_runtime/adapters/autogen/__init__.py +0 -0
- agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
- agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
- agentscope_runtime/adapters/text/__init__.py +0 -0
- agentscope_runtime/adapters/text/stream.py +29 -0
- agentscope_runtime/common/collections/redis_mapping.py +4 -1
- agentscope_runtime/common/container_clients/fc_client.py +855 -0
- agentscope_runtime/common/utils/__init__.py +0 -0
- agentscope_runtime/common/utils/lazy_loader.py +57 -0
- agentscope_runtime/engine/__init__.py +25 -18
- agentscope_runtime/engine/app/agent_app.py +161 -91
- agentscope_runtime/engine/app/base_app.py +4 -118
- agentscope_runtime/engine/constant.py +8 -0
- agentscope_runtime/engine/deployers/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
- agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
- agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
- agentscope_runtime/engine/deployers/local_deployer.py +47 -74
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
- agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
- agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
- agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
- agentscope_runtime/engine/deployers/utils/package.py +693 -0
- agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +301 -282
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
- agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
- agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
- agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
- agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
- agentscope_runtime/engine/helpers/runner.py +40 -0
- agentscope_runtime/engine/runner.py +171 -130
- agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
- agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
- agentscope_runtime/engine/schemas/oai_llm.py +23 -23
- agentscope_runtime/engine/schemas/response_api.py +65 -0
- agentscope_runtime/engine/schemas/session.py +24 -0
- agentscope_runtime/engine/services/__init__.py +0 -9
- agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
- agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
- agentscope_runtime/engine/services/memory/__init__.py +24 -0
- agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
- agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
- agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
- agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
- agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
- agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
- agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
- agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
- agentscope_runtime/engine/services/session_history/__init__.py +23 -0
- agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
- agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
- agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
- agentscope_runtime/engine/tracing/base.py +10 -9
- agentscope_runtime/engine/tracing/message_util.py +1 -1
- agentscope_runtime/engine/tracing/tracing_util.py +7 -2
- agentscope_runtime/engine/tracing/wrapper.py +49 -31
- agentscope_runtime/sandbox/__init__.py +10 -2
- agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
- agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
- agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
- agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
- agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
- agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +15 -2
- agentscope_runtime/sandbox/manager/server/app.py +12 -0
- agentscope_runtime/sandbox/manager/server/config.py +19 -0
- agentscope_runtime/sandbox/model/manager_config.py +79 -2
- agentscope_runtime/sandbox/utils.py +0 -18
- agentscope_runtime/tools/RAGs/__init__.py +0 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
- agentscope_runtime/tools/__init__.py +119 -0
- agentscope_runtime/tools/_constants.py +18 -0
- agentscope_runtime/tools/alipay/__init__.py +4 -0
- agentscope_runtime/tools/alipay/base.py +334 -0
- agentscope_runtime/tools/alipay/payment.py +835 -0
- agentscope_runtime/tools/alipay/subscribe.py +551 -0
- agentscope_runtime/tools/base.py +264 -0
- agentscope_runtime/tools/cli/__init__.py +0 -0
- agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
- agentscope_runtime/tools/generations/__init__.py +75 -0
- agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
- agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
- agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
- agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
- agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
- agentscope_runtime/tools/generations/image_edit.py +208 -0
- agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
- agentscope_runtime/tools/generations/image_generation.py +202 -0
- agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
- agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
- agentscope_runtime/tools/generations/image_to_video.py +233 -0
- agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
- agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
- agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
- agentscope_runtime/tools/generations/speech_to_text.py +260 -0
- agentscope_runtime/tools/generations/speech_to_video.py +314 -0
- agentscope_runtime/tools/generations/text_to_video.py +221 -0
- agentscope_runtime/tools/mcp_wrapper.py +215 -0
- agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
- agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
- agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
- agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
- agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
- agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
- agentscope_runtime/tools/searches/__init__.py +3 -0
- agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
- agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
- agentscope_runtime/tools/utils/__init__.py +0 -0
- agentscope_runtime/tools/utils/api_key_util.py +45 -0
- agentscope_runtime/tools/utils/crypto_utils.py +99 -0
- agentscope_runtime/tools/utils/mcp_util.py +35 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +240 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/entry_points.txt +1 -0
- agentscope_runtime/engine/agents/__init__.py +0 -2
- agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
- agentscope_runtime/engine/agents/agno_agent.py +0 -220
- agentscope_runtime/engine/agents/autogen_agent.py +0 -250
- agentscope_runtime/engine/agents/base_agent.py +0 -29
- agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
- agentscope_runtime/engine/agents/utils.py +0 -53
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
- agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
- agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
- agentscope_runtime/engine/helpers/helper.py +0 -179
- agentscope_runtime/engine/schemas/context.py +0 -54
- agentscope_runtime/engine/services/context_manager.py +0 -164
- agentscope_runtime/engine/services/environment_manager.py +0 -50
- agentscope_runtime/engine/services/manager.py +0 -174
- agentscope_runtime/engine/services/rag_service.py +0 -195
- agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
- agentscope_runtime/sandbox/tools/__init__.py +0 -12
- agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
- agentscope_runtime/sandbox/tools/base/tool.py +0 -52
- agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
- agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
- agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
- agentscope_runtime/sandbox/tools/function_tool.py +0 -321
- agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
- agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
- agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
- agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
- agentscope_runtime/sandbox/tools/tool.py +0 -238
- agentscope_runtime/sandbox/tools/utils.py +0 -68
- agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -4,27 +4,25 @@
|
|
|
4
4
|
# pylint:disable=ungrouped-imports, arguments-renamed, protected-access
|
|
5
5
|
#
|
|
6
6
|
# flake8: noqa: E501
|
|
7
|
+
import json
|
|
7
8
|
import logging
|
|
8
9
|
import os
|
|
9
10
|
import time
|
|
10
|
-
import uuid
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
from typing import Dict, Optional, List, Union, Tuple
|
|
13
13
|
|
|
14
|
+
import requests
|
|
14
15
|
from pydantic import BaseModel, Field
|
|
15
16
|
|
|
16
17
|
from .adapter.protocol_adapter import ProtocolAdapter
|
|
17
18
|
from .base import DeployManager
|
|
18
19
|
from .local_deployer import LocalDeployManager
|
|
19
|
-
from .utils.
|
|
20
|
-
ServicesConfig,
|
|
21
|
-
)
|
|
20
|
+
from .utils.detached_app import get_bundle_entry_script
|
|
22
21
|
from .utils.wheel_packager import (
|
|
23
22
|
generate_wrapper_project,
|
|
24
23
|
build_wheel,
|
|
25
24
|
default_deploy_name,
|
|
26
25
|
)
|
|
27
|
-
from ..runner import Runner
|
|
28
26
|
|
|
29
27
|
logger = logging.getLogger(__name__)
|
|
30
28
|
|
|
@@ -90,12 +88,15 @@ class ModelstudioConfig(BaseModel):
|
|
|
90
88
|
|
|
91
89
|
@classmethod
|
|
92
90
|
def from_env(cls) -> "ModelstudioConfig":
|
|
91
|
+
raw_ws = os.environ.get("MODELSTUDIO_WORKSPACE_ID")
|
|
92
|
+
ws = raw_ws.strip() if isinstance(raw_ws, str) else ""
|
|
93
|
+
resolved_ws = ws if ws else "default"
|
|
93
94
|
return cls(
|
|
94
95
|
endpoint=os.environ.get(
|
|
95
96
|
"MODELSTUDIO_ENDPOINT",
|
|
96
97
|
"bailian.cn-beijing.aliyuncs.com",
|
|
97
98
|
),
|
|
98
|
-
workspace_id=
|
|
99
|
+
workspace_id=resolved_ws,
|
|
99
100
|
access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
|
|
100
101
|
access_key_secret=os.environ.get(
|
|
101
102
|
"ALIBABA_CLOUD_ACCESS_KEY_SECRET",
|
|
@@ -107,8 +108,6 @@ class ModelstudioConfig(BaseModel):
|
|
|
107
108
|
|
|
108
109
|
def ensure_valid(self) -> None:
|
|
109
110
|
missing = []
|
|
110
|
-
if not self.workspace_id:
|
|
111
|
-
missing.append("MODELSTUDIO_WORKSPACE_ID")
|
|
112
111
|
if not self.access_key_id:
|
|
113
112
|
missing.append("ALIBABA_CLOUD_ACCESS_KEY_ID")
|
|
114
113
|
if not self.access_key_secret:
|
|
@@ -222,6 +221,180 @@ async def _oss_put_and_presign(
|
|
|
222
221
|
return pre.url
|
|
223
222
|
|
|
224
223
|
|
|
224
|
+
def _upload_to_oss_with_credentials(
|
|
225
|
+
api_response,
|
|
226
|
+
file_path,
|
|
227
|
+
) -> str:
|
|
228
|
+
response_data = (
|
|
229
|
+
json.loads(api_response)
|
|
230
|
+
if isinstance(api_response, str)
|
|
231
|
+
else api_response
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
body = response_data["body"]
|
|
236
|
+
data = body.get("Data")
|
|
237
|
+
if data is None:
|
|
238
|
+
messages = [
|
|
239
|
+
"\n❌ Configuration Error: "
|
|
240
|
+
"The current RAM user is not assigned to target workspace.",
|
|
241
|
+
"Bailian requires RAM users to be associated with "
|
|
242
|
+
"at least one workspace to use temporary storage.",
|
|
243
|
+
"\n🔧 How to resolve:",
|
|
244
|
+
"1. Ask the primary account to log in to the "
|
|
245
|
+
"Bailian Console: https://bailian.console.aliyun.com",
|
|
246
|
+
"2. Go to [Permission Management]",
|
|
247
|
+
"3. Go to [Add User]",
|
|
248
|
+
"4. Assign the user to a workspace",
|
|
249
|
+
"\n💡 Note: If you are not the primary account holder,"
|
|
250
|
+
" please contact your administrator to complete this step.",
|
|
251
|
+
"=" * 80,
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
for msg in messages:
|
|
255
|
+
logger.error(msg)
|
|
256
|
+
|
|
257
|
+
raise ValueError(
|
|
258
|
+
"RAM user is not assigned to any workspace in Bailian",
|
|
259
|
+
)
|
|
260
|
+
param = data["Param"]
|
|
261
|
+
signed_url = param["Url"]
|
|
262
|
+
headers = param["Headers"]
|
|
263
|
+
except KeyError as e:
|
|
264
|
+
raise ValueError(f"Missing expected field in API response: {e}") from e
|
|
265
|
+
try:
|
|
266
|
+
with open(file_path, "rb") as file:
|
|
267
|
+
response = requests.put(signed_url, data=file, headers=headers)
|
|
268
|
+
logger.info("OSS upload status code: %d", response.status_code)
|
|
269
|
+
response.raise_for_status() # Raises for 4xx/5xx
|
|
270
|
+
logger.info("File uploaded successfully using requests")
|
|
271
|
+
return data["TempStorageLeaseId"]
|
|
272
|
+
except Exception as e:
|
|
273
|
+
logger.error("Failed to upload file to OSS: %s", e)
|
|
274
|
+
raise
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def _get_presign_url_and_upload_to_oss(
|
|
278
|
+
cfg: ModelstudioConfig,
|
|
279
|
+
wheel_path: Path,
|
|
280
|
+
) -> str:
|
|
281
|
+
"""
|
|
282
|
+
Request a temporary storage lease, obtain a pre-signed OSS URL, and upload the file.
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
cfg: ModelStudio configuration with credentials and endpoint.
|
|
286
|
+
wheel_path: Path to the wheel file to upload.
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
The TempStorageLeaseId returned by the service.
|
|
290
|
+
|
|
291
|
+
Raises:
|
|
292
|
+
Exception: Any error from the SDK or upload process (not swallowed).
|
|
293
|
+
"""
|
|
294
|
+
try:
|
|
295
|
+
config = open_api_models.Config(
|
|
296
|
+
access_key_id=cfg.access_key_id,
|
|
297
|
+
access_key_secret=cfg.access_key_secret,
|
|
298
|
+
)
|
|
299
|
+
config.endpoint = cfg.endpoint
|
|
300
|
+
client_modelstudio = ModelstudioClient(config)
|
|
301
|
+
|
|
302
|
+
filename = wheel_path.name
|
|
303
|
+
size = wheel_path.stat().st_size
|
|
304
|
+
|
|
305
|
+
apply_temp_storage_lease_request = (
|
|
306
|
+
ModelstudioTypes.ApplyTempStorageLeaseRequest(
|
|
307
|
+
file_name=filename,
|
|
308
|
+
size_in_bytes=size,
|
|
309
|
+
)
|
|
310
|
+
)
|
|
311
|
+
runtime = util_models.RuntimeOptions()
|
|
312
|
+
headers = {}
|
|
313
|
+
workspace_id = getattr(cfg, "workspace_id", "default")
|
|
314
|
+
try:
|
|
315
|
+
response = (
|
|
316
|
+
client_modelstudio.apply_temp_storage_lease_with_options(
|
|
317
|
+
workspace_id,
|
|
318
|
+
apply_temp_storage_lease_request,
|
|
319
|
+
headers,
|
|
320
|
+
runtime,
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
except Exception as error:
|
|
324
|
+
logger.error(
|
|
325
|
+
"Error during temporary storage lease or upload: %s",
|
|
326
|
+
error,
|
|
327
|
+
)
|
|
328
|
+
error_code = None
|
|
329
|
+
recommend_url = None
|
|
330
|
+
if hasattr(error, "code"):
|
|
331
|
+
error_code = error.code
|
|
332
|
+
if hasattr(error, "data") and isinstance(error.data, dict):
|
|
333
|
+
recommend_url = error.data.get("Recommend")
|
|
334
|
+
|
|
335
|
+
if error_code == "NoPermission":
|
|
336
|
+
messages = [
|
|
337
|
+
"\n❌ Permission Denied (NoPermission)",
|
|
338
|
+
"The current account does not have permission to apply "
|
|
339
|
+
"for temporary storage (ApplyTempStorageLease).",
|
|
340
|
+
"\n🔧 How to resolve:",
|
|
341
|
+
"1. Ask the primary account holder (or an administrator)"
|
|
342
|
+
" to grant your RAM user the following permission:",
|
|
343
|
+
" - Action: `AliyunBailianDataFullAccess`",
|
|
344
|
+
"\n2. Steps to grant permission:",
|
|
345
|
+
" - Go to Alibaba Cloud RAM Console: https://ram.console.aliyun.com/users",
|
|
346
|
+
" - Locate your RAM user",
|
|
347
|
+
" - Click 'Add Permissions' and attach a policy that includes "
|
|
348
|
+
"`AliyunBailianDataFullAccess`",
|
|
349
|
+
"\n3. For further diagnostics:",
|
|
350
|
+
]
|
|
351
|
+
official_doc_link = "https://help.aliyun.com/zh/ram/"
|
|
352
|
+
if recommend_url:
|
|
353
|
+
messages.append(
|
|
354
|
+
f" - Official troubleshooting link: {recommend_url}",
|
|
355
|
+
)
|
|
356
|
+
else:
|
|
357
|
+
messages.append(
|
|
358
|
+
" - Visit the Alibaba Cloud API troubleshooting page",
|
|
359
|
+
)
|
|
360
|
+
messages.append(
|
|
361
|
+
f" - Official document link: {official_doc_link or 'N/A'}",
|
|
362
|
+
)
|
|
363
|
+
messages.append(
|
|
364
|
+
"\n💡 Note: If you are not an administrator, please "
|
|
365
|
+
"contact your cloud account administrator for assistance.",
|
|
366
|
+
)
|
|
367
|
+
messages.append("=" * 80)
|
|
368
|
+
|
|
369
|
+
# 一次性记录多行日志(每行单独一条日志,便于解析)
|
|
370
|
+
for msg in messages:
|
|
371
|
+
logger.error(msg)
|
|
372
|
+
|
|
373
|
+
logger.error("Original error details: %s", error)
|
|
374
|
+
raise
|
|
375
|
+
|
|
376
|
+
temp_storage_lease_id = _upload_to_oss_with_credentials(
|
|
377
|
+
response.to_map(),
|
|
378
|
+
wheel_path,
|
|
379
|
+
)
|
|
380
|
+
return temp_storage_lease_id
|
|
381
|
+
|
|
382
|
+
except Exception as error:
|
|
383
|
+
# Log detailed error information
|
|
384
|
+
logger.error(
|
|
385
|
+
"Error during temporary storage upload: %s",
|
|
386
|
+
error,
|
|
387
|
+
)
|
|
388
|
+
if hasattr(error, "message"):
|
|
389
|
+
logger.error("Error message: %s", error.message)
|
|
390
|
+
if hasattr(error, "data") and isinstance(error.data, dict):
|
|
391
|
+
recommend = error.data.get("Recommend")
|
|
392
|
+
if recommend:
|
|
393
|
+
logger.error("Diagnostic recommendation: %s", recommend)
|
|
394
|
+
# Re-raise the exception to avoid silent failures
|
|
395
|
+
raise
|
|
396
|
+
|
|
397
|
+
|
|
225
398
|
async def _modelstudio_deploy(
|
|
226
399
|
cfg: ModelstudioConfig,
|
|
227
400
|
file_url: str,
|
|
@@ -411,7 +584,7 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
411
584
|
build_dir.mkdir(parents=True, exist_ok=True)
|
|
412
585
|
|
|
413
586
|
logger.info("Generating wrapper project for %s", name)
|
|
414
|
-
wrapper_project_dir, _ =
|
|
587
|
+
wrapper_project_dir, _ = generate_wrapper_project(
|
|
415
588
|
build_root=build_dir,
|
|
416
589
|
user_project_dir=project_dir,
|
|
417
590
|
start_cmd=cmd,
|
|
@@ -420,7 +593,7 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
420
593
|
)
|
|
421
594
|
|
|
422
595
|
logger.info("Building wheel under %s", wrapper_project_dir)
|
|
423
|
-
wheel_path =
|
|
596
|
+
wheel_path = build_wheel(wrapper_project_dir)
|
|
424
597
|
return wheel_path, name
|
|
425
598
|
|
|
426
599
|
def _generate_env_file(
|
|
@@ -491,32 +664,19 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
491
664
|
agent_id: Optional[str] = None,
|
|
492
665
|
agent_desc: Optional[str] = None,
|
|
493
666
|
telemetry_enabled: bool = True,
|
|
494
|
-
) -> Tuple[str, str
|
|
495
|
-
logger.info("Uploading wheel to OSS
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
os.getenv("MODELSTUDIO_WORKSPACE_ID", str(uuid.uuid4()))
|
|
500
|
-
).lower()
|
|
501
|
-
bucket_name = (f"tmp-code-deploy-" f"{bucket_suffix}")[:63]
|
|
502
|
-
await _oss_create_bucket_if_not_exists(client, bucket_name)
|
|
503
|
-
filename = wheel_path.name
|
|
504
|
-
with wheel_path.open("rb") as f:
|
|
505
|
-
file_bytes = f.read()
|
|
506
|
-
artifact_url = await _oss_put_and_presign(
|
|
507
|
-
client,
|
|
508
|
-
bucket_name,
|
|
509
|
-
filename,
|
|
510
|
-
file_bytes,
|
|
667
|
+
) -> Tuple[str, str]:
|
|
668
|
+
logger.info("Uploading wheel to OSS")
|
|
669
|
+
temp_storage_lease_id = _get_presign_url_and_upload_to_oss(
|
|
670
|
+
self.modelstudio_config,
|
|
671
|
+
wheel_path,
|
|
511
672
|
)
|
|
512
|
-
|
|
513
673
|
logger.info("Triggering Modelstudio Full-Code deploy for %s", name)
|
|
514
674
|
deploy_identifier = await _modelstudio_deploy(
|
|
515
675
|
agent_desc=agent_desc,
|
|
516
676
|
agent_id=agent_id,
|
|
517
677
|
cfg=self.modelstudio_config,
|
|
518
|
-
file_url=
|
|
519
|
-
filename=
|
|
678
|
+
file_url=temp_storage_lease_id,
|
|
679
|
+
filename=wheel_path.name,
|
|
520
680
|
deploy_name=name,
|
|
521
681
|
telemetry_enabled=telemetry_enabled,
|
|
522
682
|
)
|
|
@@ -538,13 +698,13 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
538
698
|
if deploy_identifier
|
|
539
699
|
else ""
|
|
540
700
|
)
|
|
541
|
-
return
|
|
701
|
+
return console_url, deploy_identifier
|
|
542
702
|
|
|
543
703
|
async def deploy(
|
|
544
704
|
self,
|
|
545
|
-
|
|
705
|
+
app=None,
|
|
706
|
+
runner=None,
|
|
546
707
|
endpoint_path: str = "/process",
|
|
547
|
-
services_config: Optional[Union[ServicesConfig, dict]] = None,
|
|
548
708
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
549
709
|
requirements: Optional[Union[str, List[str]]] = None,
|
|
550
710
|
extra_packages: Optional[List[str]] = None,
|
|
@@ -567,7 +727,7 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
567
727
|
"""
|
|
568
728
|
Package the project, upload to OSS and trigger ModelStudio deploy.
|
|
569
729
|
|
|
570
|
-
Returns a dict containing deploy_id, wheel_path,
|
|
730
|
+
Returns a dict containing deploy_id, wheel_path, url (if uploaded),
|
|
571
731
|
resource_name (deploy_name), and workspace_id.
|
|
572
732
|
"""
|
|
573
733
|
if not agent_id:
|
|
@@ -577,30 +737,26 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
577
737
|
"or external_whl_path must be provided.",
|
|
578
738
|
)
|
|
579
739
|
|
|
580
|
-
# convert services_config to Model body
|
|
581
|
-
if services_config and isinstance(services_config, dict):
|
|
582
|
-
services_config = ServicesConfig(**services_config)
|
|
583
|
-
|
|
584
740
|
try:
|
|
585
741
|
if runner:
|
|
586
|
-
agent = runner._agent
|
|
587
742
|
if "agent" in kwargs:
|
|
588
743
|
kwargs.pop("agent")
|
|
589
744
|
|
|
590
745
|
# Create package project for detached deployment
|
|
591
746
|
project_dir = await LocalDeployManager.create_detached_project(
|
|
592
|
-
|
|
747
|
+
app=app,
|
|
593
748
|
endpoint_path=endpoint_path,
|
|
594
|
-
services_config=services_config, # type: ignore[arg-type]
|
|
595
749
|
protocol_adapters=protocol_adapters,
|
|
596
|
-
custom_endpoints=custom_endpoints,
|
|
750
|
+
custom_endpoints=custom_endpoints,
|
|
597
751
|
requirements=requirements,
|
|
598
752
|
extra_packages=extra_packages,
|
|
753
|
+
port=8080,
|
|
599
754
|
**kwargs,
|
|
600
755
|
)
|
|
601
756
|
if project_dir:
|
|
602
757
|
self._generate_env_file(project_dir, environment)
|
|
603
|
-
|
|
758
|
+
entry_script = get_bundle_entry_script(project_dir)
|
|
759
|
+
cmd = f"python {entry_script}"
|
|
604
760
|
deploy_name = deploy_name or default_deploy_name()
|
|
605
761
|
|
|
606
762
|
if agent_id:
|
|
@@ -618,10 +774,17 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
618
774
|
f"External wheel file not found: {wheel_path}",
|
|
619
775
|
)
|
|
620
776
|
name = deploy_name or default_deploy_name()
|
|
621
|
-
#
|
|
777
|
+
# Don't change name if agent was not updated and
|
|
778
|
+
# deploye_name was missing
|
|
622
779
|
if agent_id and (deploy_name is None):
|
|
623
780
|
name = None
|
|
781
|
+
logger.info(
|
|
782
|
+
"Using external wheel file: %s",
|
|
783
|
+
wheel_path,
|
|
784
|
+
)
|
|
785
|
+
|
|
624
786
|
else:
|
|
787
|
+
logger.info("Building wheel package from project")
|
|
625
788
|
(
|
|
626
789
|
wheel_path,
|
|
627
790
|
name,
|
|
@@ -632,16 +795,15 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
632
795
|
telemetry_enabled=telemetry_enabled,
|
|
633
796
|
)
|
|
634
797
|
|
|
635
|
-
artifact_url = ""
|
|
636
798
|
console_url = ""
|
|
637
799
|
deploy_identifier = ""
|
|
638
800
|
if not skip_upload:
|
|
639
|
-
# Only require cloud SDKs and credentials when performing
|
|
801
|
+
# Only require cloud SDKs and credentials when performing
|
|
802
|
+
# upload/deploy
|
|
640
803
|
_assert_cloud_sdks_available()
|
|
641
804
|
self.oss_config.ensure_valid()
|
|
642
805
|
self.modelstudio_config.ensure_valid()
|
|
643
806
|
(
|
|
644
|
-
artifact_url,
|
|
645
807
|
console_url,
|
|
646
808
|
deploy_identifier,
|
|
647
809
|
) = await self._upload_and_deploy(
|
|
@@ -654,11 +816,12 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
654
816
|
|
|
655
817
|
result: Dict[str, str] = {
|
|
656
818
|
"wheel_path": str(wheel_path),
|
|
657
|
-
"artifact_url": artifact_url,
|
|
658
819
|
"resource_name": name,
|
|
659
|
-
"workspace_id": self.modelstudio_config.workspace_id or "",
|
|
660
820
|
"url": console_url,
|
|
661
821
|
}
|
|
822
|
+
env_ws = os.environ.get("MODELSTUDIO_WORKSPACE_ID")
|
|
823
|
+
if env_ws and env_ws.strip():
|
|
824
|
+
result["workspace_id"] = env_ws.strip()
|
|
662
825
|
if deploy_identifier:
|
|
663
826
|
result["deploy_id"] = deploy_identifier
|
|
664
827
|
|
|
@@ -666,7 +829,10 @@ class ModelstudioDeployManager(DeployManager):
|
|
|
666
829
|
except Exception as e:
|
|
667
830
|
# Print richer error message to improve UX
|
|
668
831
|
err_text = str(e)
|
|
669
|
-
logger.error(
|
|
832
|
+
logger.error(
|
|
833
|
+
"Failed to deploy to modelstudio: %s",
|
|
834
|
+
err_text,
|
|
835
|
+
)
|
|
670
836
|
raise
|
|
671
837
|
|
|
672
838
|
async def stop(self) -> None: # pragma: no cover - not supported yet
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Helpers for working with AgentApp objects inside deployers."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any, Optional, TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
9
|
+
from ...runner import Runner
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def ensure_runner_from_app(app: Any) -> Optional["Runner"]:
|
|
13
|
+
"""Return a Runner extracted from an AgentApp instance.
|
|
14
|
+
|
|
15
|
+
Builds the runner lazily if the app hasn't initialized it yet.
|
|
16
|
+
"""
|
|
17
|
+
if app is None:
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
runner = getattr(app, "_runner", None)
|
|
21
|
+
if runner is not None:
|
|
22
|
+
return runner
|
|
23
|
+
|
|
24
|
+
build_runner = getattr(app, "_build_runner", None)
|
|
25
|
+
if callable(build_runner):
|
|
26
|
+
build_runner()
|
|
27
|
+
runner = getattr(app, "_runner", None)
|
|
28
|
+
|
|
29
|
+
return runner
|