Skip to content

Commit 80998be

Browse files
Merge pull request #161 from dashscope/dev/sdk-cli-1
fix(cli): Fix CLI compatibility issue with SDK response objects
2 parents 826fee9 + 4920f6d commit 80998be

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

dashscope/cli/deployments.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def create(
162162
if output is None:
163163
error("Deployment creation returned empty response")
164164

165-
deployed_model = output.get("deployed_model")
165+
deployed_model = (
166+
output.get("deployed_model")
167+
if isinstance(output, dict)
168+
else getattr(output, "deployed_model", None)
169+
)
166170
if not deployed_model:
167171
error(
168172
"Deployment creation succeeded but missing deployed_model "

dashscope/cli/files.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def upload(
7474
output = ensure_ok(rsp)
7575

7676
# Validate uploaded_files exists and is not empty
77-
uploaded_files = output.get("uploaded_files", [])
77+
uploaded_files = (
78+
output.get("uploaded_files", [])
79+
if isinstance(output, dict)
80+
else getattr(output, "uploaded_files", [])
81+
)
7882
if not uploaded_files:
7983
error("Upload succeeded but no file_id returned in response")
8084

dashscope/cli/fine_tunes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ def _stream_events(job_id: str):
115115
)
116116
return
117117

118-
status = rsp.output.get("status")
118+
status = (
119+
rsp.output.get("status")
120+
if isinstance(rsp.output, dict)
121+
else getattr(rsp.output, "status", None)
122+
)
119123
if status in (
120124
TaskStatus.FAILED,
121125
TaskStatus.CANCELED,
@@ -150,7 +154,11 @@ def _dump_logs(job_id: str):
150154
line=LOG_PAGE_SIZE,
151155
)
152156
output = ensure_ok(rsp)
153-
logs = output.get("logs", [])
157+
logs = (
158+
output.get("logs", [])
159+
if isinstance(output, dict)
160+
else getattr(output, "logs", [])
161+
)
154162
if not logs:
155163
break
156164
for line in logs:
@@ -244,7 +252,7 @@ def create(
244252
if output is None:
245253
error("Fine-tune creation returned empty response")
246254

247-
job_id = output.get("job_id")
255+
job_id = getattr(output, "job_id", None)
248256
if not job_id:
249257
error(
250258
"Fine-tune creation succeeded but missing job_id in response. "

tests/integration/test_large_utf8_payload.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ def _print_result(resp, elapsed): # pylint: disable=unused-argument
7070
return False
7171

7272

73-
def test_sync(test_messages):
73+
def test_sync(messages): # pylint: disable=redefined-outer-name
7474
print("\n" + "=" * 60)
7575
print("SYNC TEST")
7676
print("=" * 60)
7777
start = time.time()
7878
try:
7979
resp = Generation.call(
8080
model=MODEL,
81-
messages=test_messages,
81+
messages=messages,
8282
max_tokens=MAX_OUTPUT_TOKENS,
8383
result_format="message",
8484
)
@@ -94,15 +94,15 @@ def test_sync(test_messages):
9494
return _print_result(resp, elapsed)
9595

9696

97-
async def test_async(test_messages):
97+
async def test_async(messages): # pylint: disable=redefined-outer-name
9898
print("\n" + "=" * 60)
9999
print("ASYNC TEST")
100100
print("=" * 60)
101101
start = time.time()
102102
try:
103103
resp = await AioGeneration.call(
104104
model=MODEL,
105-
messages=test_messages,
105+
messages=messages,
106106
max_tokens=MAX_OUTPUT_TOKENS,
107107
result_format="message",
108108
)
@@ -118,7 +118,7 @@ async def test_async(test_messages):
118118
return _print_result(resp, elapsed)
119119

120120

121-
def test_stream(test_messages):
121+
def test_stream(messages): # pylint: disable=redefined-outer-name
122122
print("\n" + "=" * 60)
123123
print("STREAM TEST")
124124
print("=" * 60)
@@ -127,7 +127,7 @@ def test_stream(test_messages):
127127
try:
128128
responses = Generation.call(
129129
model=MODEL,
130-
messages=test_messages,
130+
messages=messages,
131131
max_tokens=MAX_OUTPUT_TOKENS,
132132
result_format="message",
133133
stream=True,
@@ -160,10 +160,10 @@ def test_stream(test_messages):
160160
return True
161161

162162

163-
def test_websocket(test_messages):
163+
def test_websocket(messages): # pylint: disable=redefined-outer-name
164164
# WebSocket has a smaller message size limit than HTTP;
165165
# use a subset that still contains non-ASCII content.
166-
ws_messages = test_messages[:5]
166+
ws_messages = messages[:5]
167167
print("\n" + "=" * 60)
168168
print(
169169
f"WEBSOCKET TEST ({len(ws_messages)}/{len(messages)} messages)",

0 commit comments

Comments
 (0)