Skip to content

Commit 6979c6a

Browse files
author
zhansheng.lzs
committed
apt: remove incompatible syntax,etc.
1 parent d1c0347 commit 6979c6a

19 files changed

Lines changed: 66 additions & 73 deletions

dashscope/finetune/agentic_rl.py

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# Copyright (c) Alibaba, Inc. and its affiliates.
55

6-
import yaml
7-
from pathlib import Path
86
from typing import Union, List, Optional, ClassVar, Dict, Any
97
from typing_extensions import Self
108

@@ -29,8 +27,6 @@
2927
from dashscope.finetune.reinforcement import (
3028
FunctionType,
3129
DatasetsType,
32-
TrainingType,
33-
DataSourceType,
3430
)
3531
from dashscope.finetune.reinforcement import (
3632
RewardInput,
@@ -47,7 +43,6 @@
4743
from dashscope.finetune.reinforcement.common.errors import (
4844
RegistrationError,
4945
ValidationError,
50-
IOErrorWithCode,
5146
RuntimeErrorWithCode,
5247
ValueErrorWithCode,
5348
DatasetsError,
@@ -65,7 +60,8 @@ def __init__(self, api_key: str = None):
6560
except Exception as e:
6661
logger.error("API key initialization failed", exc_info=True)
6762
raise ValueErrorWithCode(
68-
"Invalid API key configuration", error_code=3000
63+
"Invalid API key configuration",
64+
error_code=3000,
6965
) from e
7066

7167
def init(self, config_path: Optional[str] = None, **kwargs) -> Self:
@@ -86,7 +82,14 @@ async def register_functions(
8682
]
8783
] = None,
8884
lazy_load: Optional[bool] = True,
89-
) -> tuple[List[str], List[str], List[str], List[str], List[str], List[str]]:
85+
) -> tuple[
86+
List[str],
87+
List[str],
88+
List[str],
89+
List[str],
90+
List[str],
91+
List[str],
92+
]:
9093
"""Register function components and return entity/instance IDs."""
9194
if functions:
9295
self.tuning.functions = functions
@@ -105,10 +108,12 @@ async def register_functions(
105108
logger.info("Function components registered")
106109
except Exception as e:
107110
logger.error(
108-
"Function component registration failed", exc_info=True
111+
"Function component registration failed",
112+
exc_info=True,
109113
)
110114
raise RegistrationError(
111-
"Function registration error", error_code=3200
115+
"Function registration error",
116+
error_code=3200,
112117
) from e
113118

114119
return (
@@ -130,17 +135,19 @@ async def upload_datasets(
130135
self.tuning.datasets = datasets
131136

132137
try:
133-
uploaded_training_ids, uploaded_validation_ids = (
134-
await self.tuning.upload_datasets(
135-
training_files=training_files,
136-
validation_files=validation_files,
137-
)
138+
(
139+
uploaded_training_ids,
140+
uploaded_validation_ids,
141+
) = await self.tuning.upload_datasets(
142+
training_files=training_files,
143+
validation_files=validation_files,
138144
)
139145
logger.info("Datasets uploaded")
140146
except Exception as e:
141147
logger.error("Datasets upload failed", exc_info=True)
142148
raise DatasetsError(
143-
"Datasets upload error", error_code=3300
149+
"Datasets upload error",
150+
error_code=3300,
144151
) from e
145152

146153
return uploaded_training_ids, uploaded_validation_ids
@@ -187,16 +194,16 @@ def submit_job(
187194
self.tuning.functions = functions
188195
try:
189196
rollouts = self.tuning.combine_ids_runtimes(
190-
functype=FunctionType.ROLLOUT
197+
functype=FunctionType.ROLLOUT,
191198
)
192199
rewards = self.tuning.combine_ids_runtimes(
193-
functype=FunctionType.REWARD
200+
functype=FunctionType.REWARD,
194201
)
195202
rewards.extend(
196203
self.tuning.combine_ids_runtimes(
197204
functype=FunctionType.GROUP_REWARD,
198205
id_str=get_func_type_id(FunctionType.REWARD),
199-
)
206+
),
200207
)
201208
except Exception as e:
202209
logger.error(
@@ -207,7 +214,8 @@ def submit_job(
207214
# names of functions
208215
if not self.tuning.check_function_names():
209216
raise ValueErrorWithCode(
210-
"Duplicate function names detected. All function names must be unique.",
217+
"Duplicate function names detected. All function names must "
218+
"be unique.",
211219
error_code=3401,
212220
)
213221

@@ -259,7 +267,8 @@ def submit_job(
259267
except Exception as e:
260268
logger.error("Job submission failed", exc_info=True)
261269
raise RuntimeErrorWithCode(
262-
"Job submission error", error_code=3400
270+
"Job submission error",
271+
error_code=3400,
263272
) from e
264273

265274
return FineTune(**resp)
@@ -296,15 +305,16 @@ async def run(
296305
"""
297306
try:
298307
logger.info(
299-
"🟦 Path-Driven mode: Registering functions & uploading datasets..."
308+
"🟦 Path-Driven mode: Registering functions & uploading "
309+
"datasets...",
300310
)
301311
await self.register_functions(
302312
functions=functions,
303313
lazy_load=True,
304314
)
305315

306316
datasets = list(training_datasets or []) + list(
307-
validation_datasets or []
317+
validation_datasets or [],
308318
)
309319
await self.upload_datasets(
310320
datasets=datasets,
@@ -321,7 +331,8 @@ async def run(
321331
except Exception as e:
322332
logger.error("RL tuning workflow failed", exc_info=True)
323333
raise RuntimeErrorWithCode(
324-
f"RL tuning workflow failed: {str(e)}", error_code=3500
334+
f"RL tuning workflow failed: {str(e)}",
335+
error_code=3500,
325336
) from e
326337

327338
@classmethod
@@ -439,7 +450,8 @@ async def test_functions(
439450
value = GroupRewardInput.model_validate(input_data)
440451
else:
441452
raise ValueErrorWithCode(
442-
f"Unsupported function type: {functype}", error_code=3600
453+
f"Unsupported function type: {functype}",
454+
error_code=3600,
443455
)
444456

445457
logger.info(
@@ -451,13 +463,16 @@ async def test_functions(
451463
)
452464

453465
return await AgenticRLFunctionComponent.verify_function(
454-
value, instance_id
466+
value,
467+
instance_id,
455468
)
456469

457470
except Exception as e:
458471
logger.error(
459-
f"Failure during {str(functype)} test: {str(e)}", exc_info=True
472+
f"Failure during {str(functype)} test: {str(e)}",
473+
exc_info=True,
460474
)
461475
raise ValidationError(
462-
f"Function test failed: {str(e)}", error_code=3601
476+
f"Function test failed: {str(e)}",
477+
error_code=3601,
463478
) from e

dashscope/finetune/reinforcement/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@
122122
from dashscope.finetune.reinforcement.component.processor.abstract_group_reward_processor import (
123123
AbstractGroupRewardProcessor,
124124
)
125-
from dashscope.finetune.reinforcement.component.observability import (
126-
observe_processor,
127-
)
128125

129126

130127
def __getattr__(name):
@@ -229,7 +226,6 @@ def __getattr__(name):
229226
"AbstractRolloutProcessor",
230227
"AbstractRewardProcessor",
231228
"AbstractGroupRewardProcessor",
232-
"observe_processor",
233229
# Core Models
234230
"FunctionComponentModel",
235231
"TuningModel",
@@ -247,6 +243,4 @@ def __getattr__(name):
247243
"Observability",
248244
"AgenticRLTuning",
249245
"Models",
250-
# CLI
251-
"app",
252246
]

dashscope/finetune/reinforcement/common/model.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import shutil
77
import tempfile
8-
import time
98
import asyncio
109

1110
# Third-party Libraries
@@ -91,12 +90,9 @@ class Dataset(BaseModel):
9190
type: DatasetsType = DatasetsType.TRAINING
9291

9392
data_source_type: Optional[DataSourceType] = DataSourceType.FILE_ID
94-
# type: file_id
9593
file_name: Optional[str] = None
9694
file_id: Optional[str] = None
97-
# type: download_url
9895
download_url: Optional[str] = None
99-
# type: oss_mount
10096
mount_storage: Optional[MountStorage] = None
10197

10298
async def upload_dataset(self) -> str:

dashscope/finetune/reinforcement/component/data/group_reward_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from pydantic import Field
9-
from typing import Any, Dict, List, Optional
9+
from typing import Any, List, Optional
1010

1111
from dashscope.finetune.reinforcement.common.model_types import (
1212
FunctionType as FuncType,

dashscope/finetune/reinforcement/component/data/group_reward_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from pydantic import BaseModel, Field
8-
from typing import Any, Dict, List, Optional
8+
from typing import List, Optional
99

1010
from dashscope.finetune.reinforcement.component.data.base_data_model import (
1111
TaskStatus,

dashscope/finetune/reinforcement/component/data/reward_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from pydantic import Field
9-
from typing import Any, Dict, Optional
9+
from typing import Any, Optional
1010

1111
from dashscope.finetune.reinforcement.common.model_types import (
1212
FunctionType as FuncType,

dashscope/finetune/reinforcement/component/data/reward_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from pydantic import BaseModel, Field
8-
from typing import Any, Dict, Optional
8+
from typing import Dict, Optional
99

1010
from dashscope.finetune.reinforcement.component.data.base_data_model import (
1111
TaskStatus,

dashscope/finetune/reinforcement/component/observability/genai/_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
except ImportError: # pragma: no cover
5757
get_extended_telemetry_handler = None # type: ignore[assignment]
5858
ExecuteToolInvocation = None # type: ignore[assignment]
59-
InputMessage = OutputMessage = Text = ToolCall = None # type: ignore[assignment]
59+
# type: ignore[assignment]
60+
InputMessage = OutputMessage = Text = ToolCall = None
6061
GENAI_AVAILABLE = False
6162

6263
_logger = logging.getLogger(__name__)

dashscope/finetune/reinforcement/component/observability/genai/tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ async def _run_tool_with_span_async(
881881
_emit_trace_tool_debug_line("wrap_ainvoke", tool_name, config)
882882

883883
if not is_tracing_enabled() or not GENAI_AVAILABLE:
884-
return await orig_fn(input, config=config, **kwargs) # type: ignore[misc]
884+
# type: ignore[misc]
885+
return await orig_fn(input, config=config, **kwargs)
885886

886887
trace_key = _trace_hex_or_none()
887888
ctx_token: Optional[contextvars.Token[int]] = None
@@ -907,7 +908,8 @@ async def _run_tool_with_span_async(
907908
"trace_tool_async:after_use_span", invocation
908909
)
909910
log_trace_id(f"execute_tool:{tool_name}")
910-
result = await orig_fn(input, config=config, **kwargs) # type: ignore[misc]
911+
# type: ignore[misc]
912+
result = await orig_fn(input, config=config, **kwargs)
911913
invocation.tool_call_result = _json_serializable(result)
912914
if hasattr(invocation, "span") and invocation.span is not None:
913915
invocation.span.set_status(Status(StatusCode.OK))

dashscope/finetune/reinforcement/component/observability/processor_span.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ async def auto_wrapper(
272272
else:
273273

274274
@wraps(fn)
275-
def auto_wrapper(self: Any, input_data: Any, *args: Any, **kwargs: Any) -> Any: # type: ignore[misc]
275+
# type: ignore[misc]
276+
def auto_wrapper(self: Any, input_data: Any, *args: Any, **kwargs: Any) -> Any:
276277
has_func_type = (
277278
getattr(input_data, "func_type", None) is not None
278279
)

0 commit comments

Comments
 (0)