compshare-cli 0.4.1__tar.gz → 0.4.2__tar.gz
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.
- {compshare_cli-0.4.1/src/compshare_cli.egg-info → compshare_cli-0.4.2}/PKG-INFO +1 -3
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/README.md +0 -2
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/__init__.py +1 -1
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/cli.py +0 -9
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/i18n.py +0 -11
- {compshare_cli-0.4.1 → compshare_cli-0.4.2/src/compshare_cli.egg-info}/PKG-INFO +1 -3
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli.egg-info/SOURCES.txt +0 -3
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_cli.py +1 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_feedback.py +0 -1
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_minimax.py +1 -3
- compshare_cli-0.4.1/src/compshare_cli/commands/ask.py +0 -31
- compshare_cli-0.4.1/src/compshare_cli/qa.py +0 -51
- compshare_cli-0.4.1/tests/test_qa.py +0 -126
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/LICENSE +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/pyproject.toml +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/setup.cfg +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/__main__.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/actions.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/api.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/__init__.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/bandwidth.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/common.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/doctor.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/feedback.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/image.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/instance.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/minimax.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/storage.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/commands/team.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/config.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/errors.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/insights.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/instance_templates.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/location.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/output.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/parsing.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/remote_jobs.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/runtime.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/sdk.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/ssh.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli/ssh_cache.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli.egg-info/dependency_links.txt +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli.egg-info/entry_points.txt +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli.egg-info/requires.txt +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/src/compshare_cli.egg-info/top_level.txt +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_actions.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_api.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_bandwidth.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_config.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_instance_templates.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_location.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_output.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_parsing.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_release_version.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_remote_jobs.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_sdk.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_ssh.py +0 -0
- {compshare_cli-0.4.1 → compshare_cli-0.4.2}/tests/test_ssh_cache.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compshare-cli
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Command-line client for CompShare GPU compute and MiniMax H3
|
|
5
5
|
Author: CompShare
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -34,7 +34,6 @@ Dynamic: license-file
|
|
|
34
34
|
- 支持独享带宽询价、购买、改配、退款预估及实例 EIP 切换
|
|
35
35
|
- 支持创建、查询和取消 MiniMax H3 视频任务,并查看积分套餐包与余额
|
|
36
36
|
- 默认中文帮助,可切换英文;所有命令支持 JSON 输出
|
|
37
|
-
- 可通过 `compshare ask` 查询产品使用和计费知识
|
|
38
37
|
- 可通过 `compshare feedback` 反馈 CLI 问题和建议
|
|
39
38
|
|
|
40
39
|
## 安装
|
|
@@ -98,7 +97,6 @@ compshare instance -h
|
|
|
98
97
|
compshare config API 凭证配置
|
|
99
98
|
compshare feedback 反馈 CLI 问题或建议
|
|
100
99
|
compshare doctor 配置、鉴权、网络与 SSH 环境诊断
|
|
101
|
-
compshare ask 产品使用和计费问答
|
|
102
100
|
compshare instance GPU 实例、规格、库存、价格和生命周期
|
|
103
101
|
compshare image 平台、自定义、社区及共享镜像
|
|
104
102
|
compshare storage 云盘和 US3 挂载
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
- 支持独享带宽询价、购买、改配、退款预估及实例 EIP 切换
|
|
10
10
|
- 支持创建、查询和取消 MiniMax H3 视频任务,并查看积分套餐包与余额
|
|
11
11
|
- 默认中文帮助,可切换英文;所有命令支持 JSON 输出
|
|
12
|
-
- 可通过 `compshare ask` 查询产品使用和计费知识
|
|
13
12
|
- 可通过 `compshare feedback` 反馈 CLI 问题和建议
|
|
14
13
|
|
|
15
14
|
## 安装
|
|
@@ -73,7 +72,6 @@ compshare instance -h
|
|
|
73
72
|
compshare config API 凭证配置
|
|
74
73
|
compshare feedback 反馈 CLI 问题或建议
|
|
75
74
|
compshare doctor 配置、鉴权、网络与 SSH 环境诊断
|
|
76
|
-
compshare ask 产品使用和计费问答
|
|
77
75
|
compshare instance GPU 实例、规格、库存、价格和生命周期
|
|
78
76
|
compshare image 平台、自定义、社区及共享镜像
|
|
79
77
|
compshare storage 云盘和 US3 挂载
|
|
@@ -10,7 +10,6 @@ from typer.completion import completion_init, install_callback
|
|
|
10
10
|
from typer.main import get_command
|
|
11
11
|
|
|
12
12
|
from compshare_cli import __version__
|
|
13
|
-
from compshare_cli.commands import ask as ask_command
|
|
14
13
|
from compshare_cli.commands import bandwidth, image, instance, minimax, storage, team
|
|
15
14
|
from compshare_cli.commands import doctor as doctor_command
|
|
16
15
|
from compshare_cli.commands import feedback as feedback_command
|
|
@@ -308,14 +307,6 @@ def doctor(ctx: typer.Context) -> None:
|
|
|
308
307
|
doctor_command.run(ctx.find_root().obj)
|
|
309
308
|
|
|
310
309
|
|
|
311
|
-
@app.command("ask", help="Ask a CompShare product question.")
|
|
312
|
-
def ask(
|
|
313
|
-
ctx: typer.Context,
|
|
314
|
-
question: str = typer.Argument(..., help="Question to answer."),
|
|
315
|
-
) -> None:
|
|
316
|
-
ask_command.run(ctx.find_root().obj, question)
|
|
317
|
-
|
|
318
|
-
|
|
319
310
|
@app.command("feedback")
|
|
320
311
|
def feedback(
|
|
321
312
|
ctx: typer.Context,
|
|
@@ -34,8 +34,6 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
34
34
|
"Save a CompShare API credential profile.": "保存优云智算 API 凭证配置。",
|
|
35
35
|
"Print the CLI version.": "显示 CLI 版本。",
|
|
36
36
|
"Print the CLI version and exit.": "显示 CLI 版本并退出。",
|
|
37
|
-
"Ask a CompShare product question.": "询问优云智算产品问题。",
|
|
38
|
-
"Question to answer.": "需要回答的问题。",
|
|
39
37
|
"Manage GPU instances.": "管理 GPU 实例。",
|
|
40
38
|
"Manage dedicated bandwidth.": "管理独享带宽。",
|
|
41
39
|
"List dedicated bandwidth resources.": "列出独享带宽资源。",
|
|
@@ -432,9 +430,6 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
432
430
|
),
|
|
433
431
|
"Operation submitted": "操作已提交",
|
|
434
432
|
"Operation completed": "操作已完成",
|
|
435
|
-
"Answer": "回答",
|
|
436
|
-
"ANSWER": "答案",
|
|
437
|
-
"SOURCES": "来源",
|
|
438
433
|
"No selectable options": "没有可选项",
|
|
439
434
|
"Automatically selected the only option.": "已自动选择唯一选项。",
|
|
440
435
|
"Please enter a number from 1 to {count}.": "请输入 1 到 {count} 之间的数字。",
|
|
@@ -840,12 +835,6 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
840
835
|
"Unable to reach the insights service.": "无法连接数据服务。",
|
|
841
836
|
"Insights service returned an invalid response.": "数据服务返回了无效响应。",
|
|
842
837
|
"Thank you for your feedback.": "感谢反馈。",
|
|
843
|
-
"Question cannot be empty.": "问题不能为空。",
|
|
844
|
-
"Question service rejected the request with HTTP {status}.": (
|
|
845
|
-
"问答服务拒绝了请求,HTTP 状态码为 {status}。"
|
|
846
|
-
),
|
|
847
|
-
"Unable to reach the question service.": "无法连接问答服务。",
|
|
848
|
-
"Question service returned an invalid response.": "问答服务返回了无效响应。",
|
|
849
838
|
"Team ID.": "团队 ID。",
|
|
850
839
|
"Team name.": "团队名称。",
|
|
851
840
|
"Team description.": "团队简介。",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compshare-cli
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Command-line client for CompShare GPU compute and MiniMax H3
|
|
5
5
|
Author: CompShare
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -34,7 +34,6 @@ Dynamic: license-file
|
|
|
34
34
|
- 支持独享带宽询价、购买、改配、退款预估及实例 EIP 切换
|
|
35
35
|
- 支持创建、查询和取消 MiniMax H3 视频任务,并查看积分套餐包与余额
|
|
36
36
|
- 默认中文帮助,可切换英文;所有命令支持 JSON 输出
|
|
37
|
-
- 可通过 `compshare ask` 查询产品使用和计费知识
|
|
38
37
|
- 可通过 `compshare feedback` 反馈 CLI 问题和建议
|
|
39
38
|
|
|
40
39
|
## 安装
|
|
@@ -98,7 +97,6 @@ compshare instance -h
|
|
|
98
97
|
compshare config API 凭证配置
|
|
99
98
|
compshare feedback 反馈 CLI 问题或建议
|
|
100
99
|
compshare doctor 配置、鉴权、网络与 SSH 环境诊断
|
|
101
|
-
compshare ask 产品使用和计费问答
|
|
102
100
|
compshare instance GPU 实例、规格、库存、价格和生命周期
|
|
103
101
|
compshare image 平台、自定义、社区及共享镜像
|
|
104
102
|
compshare storage 云盘和 US3 挂载
|
|
@@ -14,7 +14,6 @@ src/compshare_cli/instance_templates.py
|
|
|
14
14
|
src/compshare_cli/location.py
|
|
15
15
|
src/compshare_cli/output.py
|
|
16
16
|
src/compshare_cli/parsing.py
|
|
17
|
-
src/compshare_cli/qa.py
|
|
18
17
|
src/compshare_cli/remote_jobs.py
|
|
19
18
|
src/compshare_cli/runtime.py
|
|
20
19
|
src/compshare_cli/sdk.py
|
|
@@ -27,7 +26,6 @@ src/compshare_cli.egg-info/entry_points.txt
|
|
|
27
26
|
src/compshare_cli.egg-info/requires.txt
|
|
28
27
|
src/compshare_cli.egg-info/top_level.txt
|
|
29
28
|
src/compshare_cli/commands/__init__.py
|
|
30
|
-
src/compshare_cli/commands/ask.py
|
|
31
29
|
src/compshare_cli/commands/bandwidth.py
|
|
32
30
|
src/compshare_cli/commands/common.py
|
|
33
31
|
src/compshare_cli/commands/doctor.py
|
|
@@ -48,7 +46,6 @@ tests/test_location.py
|
|
|
48
46
|
tests/test_minimax.py
|
|
49
47
|
tests/test_output.py
|
|
50
48
|
tests/test_parsing.py
|
|
51
|
-
tests/test_qa.py
|
|
52
49
|
tests/test_release_version.py
|
|
53
50
|
tests/test_remote_jobs.py
|
|
54
51
|
tests/test_sdk.py
|
|
@@ -115,6 +115,7 @@ def test_root_help_lists_config_first(capsys) -> None:
|
|
|
115
115
|
assert "--version" in help_text
|
|
116
116
|
assert "--lang" in help_text
|
|
117
117
|
assert "│ lang " not in help_text
|
|
118
|
+
assert "│ ask " not in help_text
|
|
118
119
|
assert help_text.index("config") < help_text.index("feedback") < help_text.index("doctor")
|
|
119
120
|
|
|
120
121
|
|
|
@@ -172,7 +172,6 @@ def test_event_worker_posts_to_event_endpoint(monkeypatch) -> None:
|
|
|
172
172
|
"team.billing.export",
|
|
173
173
|
),
|
|
174
174
|
(["--json", "--show-sensitive", "instance", "show", "uhost-1"], "instance.show"),
|
|
175
|
-
(["ask", "云硬盘还收费吗?"], "ask"),
|
|
176
175
|
(["feedback", "suggest", "message"], "feedback"),
|
|
177
176
|
(["instance", "--help"], None),
|
|
178
177
|
([], None),
|
|
@@ -101,9 +101,7 @@ def test_create_posts_content_with_auth_and_idempotency(monkeypatch) -> None:
|
|
|
101
101
|
|
|
102
102
|
def test_prompt_length_boundary() -> None:
|
|
103
103
|
prompt = "a" * 7000
|
|
104
|
-
assert minimax._content(prompt, None, None, [], [], []) == [
|
|
105
|
-
{"type": "text", "text": prompt}
|
|
106
|
-
]
|
|
104
|
+
assert minimax._content(prompt, None, None, [], [], []) == [{"type": "text", "text": prompt}]
|
|
107
105
|
with pytest.raises(UsageError, match="7000"):
|
|
108
106
|
minimax._content(f"{prompt}a", None, None, [], [], [])
|
|
109
107
|
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Any, Dict, List
|
|
4
|
-
|
|
5
|
-
from compshare_cli.output import Renderer
|
|
6
|
-
from compshare_cli.qa import ask_question
|
|
7
|
-
from compshare_cli.runtime import Runtime
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def _source_lines(response: Dict[str, Any]) -> str:
|
|
11
|
-
lines: List[str] = []
|
|
12
|
-
for index, raw in enumerate(response.get("citations") or [], start=1):
|
|
13
|
-
if not isinstance(raw, dict):
|
|
14
|
-
continue
|
|
15
|
-
number = raw.get("number") or index
|
|
16
|
-
title = raw.get("title") or raw.get("document_id")
|
|
17
|
-
if title:
|
|
18
|
-
lines.append(f"[{number}] {title}")
|
|
19
|
-
return "\n".join(lines)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def run(state: Runtime, question: str) -> None:
|
|
23
|
-
response = ask_question(question)
|
|
24
|
-
Renderer(state.json_output, state.show_sensitive).details(
|
|
25
|
-
"Answer",
|
|
26
|
-
[
|
|
27
|
-
("ANSWER", response["answer"]),
|
|
28
|
-
("SOURCES", _source_lines(response) or None),
|
|
29
|
-
],
|
|
30
|
-
response=response,
|
|
31
|
-
)
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from typing import Any, Dict
|
|
5
|
-
from urllib import error as urlerror
|
|
6
|
-
from urllib import request
|
|
7
|
-
|
|
8
|
-
from compshare_cli import __version__
|
|
9
|
-
from compshare_cli.errors import CLIError
|
|
10
|
-
from compshare_cli.i18n import tr
|
|
11
|
-
|
|
12
|
-
ANSWER_URL = "http://117.50.180.139:55089/v1/answer"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def ask_question(question: str) -> Dict[str, Any]:
|
|
16
|
-
normalized = question.strip()
|
|
17
|
-
if not normalized:
|
|
18
|
-
raise CLIError(tr("Question cannot be empty."))
|
|
19
|
-
|
|
20
|
-
body = json.dumps(
|
|
21
|
-
{"question": normalized},
|
|
22
|
-
ensure_ascii=False,
|
|
23
|
-
separators=(",", ":"),
|
|
24
|
-
).encode("utf-8")
|
|
25
|
-
req = request.Request(
|
|
26
|
-
ANSWER_URL,
|
|
27
|
-
data=body,
|
|
28
|
-
headers={
|
|
29
|
-
"Accept": "application/json",
|
|
30
|
-
"Content-Type": "application/json",
|
|
31
|
-
"User-Agent": f"compshare-cli/{__version__}",
|
|
32
|
-
},
|
|
33
|
-
method="POST",
|
|
34
|
-
)
|
|
35
|
-
try:
|
|
36
|
-
with request.urlopen(req, timeout=60.0) as response:
|
|
37
|
-
content = response.read()
|
|
38
|
-
except urlerror.HTTPError as error:
|
|
39
|
-
raise CLIError(
|
|
40
|
-
tr("Question service rejected the request with HTTP {status}.", status=error.code)
|
|
41
|
-
) from error
|
|
42
|
-
except (urlerror.URLError, TimeoutError, OSError) as error:
|
|
43
|
-
raise CLIError(tr("Unable to reach the question service.")) from error
|
|
44
|
-
|
|
45
|
-
try:
|
|
46
|
-
result = json.loads(content.decode("utf-8"))
|
|
47
|
-
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
48
|
-
raise CLIError(tr("Question service returned an invalid response.")) from error
|
|
49
|
-
if not isinstance(result, dict) or not isinstance(result.get("answer"), str):
|
|
50
|
-
raise CLIError(tr("Question service returned an invalid response."))
|
|
51
|
-
return result
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from urllib import error as urlerror
|
|
3
|
-
|
|
4
|
-
import pytest
|
|
5
|
-
from typer.testing import CliRunner
|
|
6
|
-
|
|
7
|
-
from compshare_cli import __version__, cli, qa
|
|
8
|
-
from compshare_cli.errors import CLIError
|
|
9
|
-
|
|
10
|
-
runner = CliRunner()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class FakeResponse:
|
|
14
|
-
def __init__(self, payload):
|
|
15
|
-
self.payload = payload
|
|
16
|
-
|
|
17
|
-
def __enter__(self):
|
|
18
|
-
return self
|
|
19
|
-
|
|
20
|
-
def __exit__(self, exc_type, exc, traceback):
|
|
21
|
-
return False
|
|
22
|
-
|
|
23
|
-
def read(self):
|
|
24
|
-
return json.dumps(self.payload, ensure_ascii=False).encode("utf-8")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def _answer():
|
|
28
|
-
return {
|
|
29
|
-
"request_id": "request-1",
|
|
30
|
-
"answer": "关机后云硬盘仍会继续收费 [1]。",
|
|
31
|
-
"citations": [
|
|
32
|
-
{
|
|
33
|
-
"number": 1,
|
|
34
|
-
"document_id": "billing-faq",
|
|
35
|
-
"title": "实例计费相关 FAQ",
|
|
36
|
-
"snippet": "This long source excerpt is JSON-only.",
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"outcome": "answered",
|
|
40
|
-
"model": "deepseek-v4-flash",
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def test_ask_posts_only_the_question_and_preserves_json_response(monkeypatch) -> None:
|
|
45
|
-
captured = {}
|
|
46
|
-
|
|
47
|
-
def fake_urlopen(req, timeout):
|
|
48
|
-
captured["url"] = req.full_url
|
|
49
|
-
captured["method"] = req.get_method()
|
|
50
|
-
captured["headers"] = dict(req.header_items())
|
|
51
|
-
captured["payload"] = json.loads(req.data.decode("utf-8"))
|
|
52
|
-
captured["timeout"] = timeout
|
|
53
|
-
return FakeResponse(_answer())
|
|
54
|
-
|
|
55
|
-
monkeypatch.setattr(qa.request, "urlopen", fake_urlopen)
|
|
56
|
-
result = runner.invoke(
|
|
57
|
-
cli.app,
|
|
58
|
-
["--json", "ask", "按量实例关机以后,云硬盘还收费吗?"],
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
assert result.exit_code == 0, result.output
|
|
62
|
-
assert json.loads(result.stdout) == {
|
|
63
|
-
"ok": True,
|
|
64
|
-
"schema_version": "1",
|
|
65
|
-
"data": _answer(),
|
|
66
|
-
}
|
|
67
|
-
assert captured == {
|
|
68
|
-
"url": "http://117.50.180.139:55089/v1/answer",
|
|
69
|
-
"method": "POST",
|
|
70
|
-
"headers": {
|
|
71
|
-
"Accept": "application/json",
|
|
72
|
-
"Content-type": "application/json",
|
|
73
|
-
"User-agent": f"compshare-cli/{__version__}",
|
|
74
|
-
},
|
|
75
|
-
"payload": {"question": "按量实例关机以后,云硬盘还收费吗?"},
|
|
76
|
-
"timeout": 60.0,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def test_ask_human_output_shows_answer_and_source_titles(monkeypatch) -> None:
|
|
81
|
-
monkeypatch.setattr(qa.request, "urlopen", lambda *args, **kwargs: FakeResponse(_answer()))
|
|
82
|
-
|
|
83
|
-
result = runner.invoke(cli.app, ["ask", "云硬盘还收费吗?"])
|
|
84
|
-
|
|
85
|
-
assert result.exit_code == 0, result.output
|
|
86
|
-
assert "关机后云硬盘仍会继续收费" in result.stdout
|
|
87
|
-
assert "实例计费相关 FAQ" in result.stdout
|
|
88
|
-
assert "This long source excerpt is JSON-only." not in result.stdout
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def test_ask_rejects_an_empty_question() -> None:
|
|
92
|
-
with pytest.raises(CLIError, match="不能为空|cannot be empty"):
|
|
93
|
-
qa.ask_question(" ")
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def test_ask_empty_question_is_a_json_cli_error(monkeypatch, capsys) -> None:
|
|
97
|
-
monkeypatch.setattr(cli, "record_command", lambda command: None)
|
|
98
|
-
|
|
99
|
-
with pytest.raises(SystemExit) as raised:
|
|
100
|
-
cli.main(["--json", "ask", " "])
|
|
101
|
-
|
|
102
|
-
assert raised.value.code == 2
|
|
103
|
-
payload = json.loads(capsys.readouterr().out)
|
|
104
|
-
assert payload["ok"] is False
|
|
105
|
-
assert payload["error"]["code"] == "cli_error"
|
|
106
|
-
assert "问题不能为空" in payload["error"]["message"]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def test_ask_reports_http_and_invalid_response_errors(monkeypatch) -> None:
|
|
110
|
-
monkeypatch.setattr(
|
|
111
|
-
qa.request,
|
|
112
|
-
"urlopen",
|
|
113
|
-
lambda *args, **kwargs: (_ for _ in ()).throw(
|
|
114
|
-
urlerror.HTTPError(qa.ANSWER_URL, 503, "Unavailable", {}, None)
|
|
115
|
-
),
|
|
116
|
-
)
|
|
117
|
-
with pytest.raises(CLIError, match="503"):
|
|
118
|
-
qa.ask_question("问题")
|
|
119
|
-
|
|
120
|
-
class InvalidResponse(FakeResponse):
|
|
121
|
-
def read(self):
|
|
122
|
-
return b"not json"
|
|
123
|
-
|
|
124
|
-
monkeypatch.setattr(qa.request, "urlopen", lambda *args, **kwargs: InvalidResponse({}))
|
|
125
|
-
with pytest.raises(CLIError, match="无效响应|invalid response"):
|
|
126
|
-
qa.ask_question("问题")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|