smartcheck-cli 0.1.1__tar.gz → 0.1.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.
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/PKG-INFO +1 -1
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/pyproject.toml +1 -1
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/commands.py +18 -1
- smartcheck_cli-0.1.2/smartcheck_cli/inspection.py +104 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/labs.py +1 -16
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/main.py +16 -6
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/PKG-INFO +1 -1
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/SOURCES.txt +2 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/tests/test_cli.py +3 -2
- smartcheck_cli-0.1.2/tests/test_inspection.py +89 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/setup.cfg +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/__init__.py +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/auth.py +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/http.py +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/insights.py +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli/quality.py +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/dependency_links.txt +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/entry_points.txt +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/requires.txt +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/smartcheck_cli.egg-info/top_level.txt +0 -0
- {smartcheck_cli-0.1.1 → smartcheck_cli-0.1.2}/tests/test_labs.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "smartcheck-cli"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "SmartCheck 账号授权、通话管理、洞察与质检配置命令行"
|
|
9
9
|
requires-python = ">=3.11"
|
|
10
10
|
dependencies = ["requests>=2.32,<3", "filelock>=3.13,<4", "keyring>=25,<26"]
|
|
@@ -5,11 +5,26 @@ from pathlib import Path
|
|
|
5
5
|
import secrets
|
|
6
6
|
import string
|
|
7
7
|
import sys
|
|
8
|
+
from typing import NamedTuple
|
|
8
9
|
|
|
9
10
|
from .auth import current
|
|
10
11
|
from .http import Error, note, segment
|
|
11
12
|
|
|
12
13
|
|
|
14
|
+
class Command(NamedTuple):
|
|
15
|
+
method: str
|
|
16
|
+
path: str
|
|
17
|
+
purpose: str
|
|
18
|
+
example: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def positive_id(value):
|
|
22
|
+
number = int(value)
|
|
23
|
+
if not 1 <= number <= 2147483647:
|
|
24
|
+
raise Error("编号须为 1 至 2147483647 的整数")
|
|
25
|
+
return number
|
|
26
|
+
|
|
27
|
+
|
|
13
28
|
def read_object(path):
|
|
14
29
|
try:
|
|
15
30
|
body = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
@@ -72,7 +87,7 @@ def run_business(client, vault, args):
|
|
|
72
87
|
path = "/" + group
|
|
73
88
|
if hasattr(args, "identifier"):
|
|
74
89
|
path += "/" + segment(args.identifier)
|
|
75
|
-
methods = {"list": "GET", "get": "GET", "download-recording": "GET", "create": "POST",
|
|
90
|
+
methods = {"list": "GET", "get": "GET", "quality-results": "GET", "download-recording": "GET", "create": "POST",
|
|
76
91
|
"update": "PUT", "set": "PUT", "enable": "PATCH", "disable": "PATCH",
|
|
77
92
|
"reorder": "PUT", "delete": "DELETE"}
|
|
78
93
|
method = methods[action]
|
|
@@ -109,6 +124,8 @@ def run_business(client, vault, args):
|
|
|
109
124
|
if any(len(tag) > 50 for tag in tags):
|
|
110
125
|
raise Error("标签最多 50 个字符")
|
|
111
126
|
params.update(tag_field=args.tag_field, tag=tags)
|
|
127
|
+
elif action == "quality-results":
|
|
128
|
+
path += "/quality-results"
|
|
112
129
|
elif action == "download-recording":
|
|
113
130
|
path += "/recording/" + segment(args.source) + "/audio"
|
|
114
131
|
output = args.output
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Tenant-scoped inspection tasks and frozen call results."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .auth import current
|
|
7
|
+
from .commands import Command, confirm_operation, positive_id, read_object
|
|
8
|
+
from .http import Error, segment
|
|
9
|
+
|
|
10
|
+
BASE = "/inspection/tasks"
|
|
11
|
+
TASK = BASE + "/{task_id}"
|
|
12
|
+
CALL = TASK + "/calls/{call_id}"
|
|
13
|
+
|
|
14
|
+
COMMANDS = {
|
|
15
|
+
"list": Command("GET", BASE, "查询自动任务或临时批次", "--tab temp --mode dry_run"),
|
|
16
|
+
"options": Command("GET", BASE + "/options", "列出已发布评分卡版本及可用筛选字段", ""),
|
|
17
|
+
"get": Command("GET", TASK, "读取配置、状态和执行统计", "12"),
|
|
18
|
+
"preview": Command("POST", BASE + "/preview", "预览临时任务命中数及已有正式结果数", "--json-file filters.json"),
|
|
19
|
+
"create": Command("POST", BASE, "创建并启用自动任务,或立即启动临时批次", "--tab temp --json-file task.json"),
|
|
20
|
+
"update": Command("PUT", TASK, "保存自动任务的完整配置", "12 --json-file task.json"),
|
|
21
|
+
"enable": Command("POST", TASK + "/enable", "启用自动任务", "12"),
|
|
22
|
+
"disable": Command("POST", TASK + "/disable", "停用自动任务", "12"),
|
|
23
|
+
"cancel": Command("POST", TASK + "/cancel", "取消临时任务中尚未开始的通话", "12 --yes"),
|
|
24
|
+
"retry": Command("POST", TASK + "/retry", "重试临时批次中的异常通话", "12 --no-include-fallback --yes"),
|
|
25
|
+
"retry-call": Command("POST", CALL + "/retry", "重跑自动任务中的一通异常通话", "12 CALL001 --yes"),
|
|
26
|
+
"runs": Command("GET", TASK + "/calls", "分页查询通话执行记录", "12 --risk redline"),
|
|
27
|
+
"run-detail": Command("GET", CALL, "查看单通质检快照、得分及证据", "12 CALL001"),
|
|
28
|
+
"debug": Command("POST", CALL + "/models/{pin}/debug", "用临时提示词测试锁定版本的模型",
|
|
29
|
+
"12 CALL001 --pin service_score:1 --json-file debug.json"),
|
|
30
|
+
"download-recording": Command("GET", CALL + "/recording/{source}/audio", "下载单通质检快照录音",
|
|
31
|
+
"12 CALL001 --source SOURCE --output call.mp3"),
|
|
32
|
+
"delete": Command("DELETE", TASK, "删除质检任务", "12 --yes"),
|
|
33
|
+
}
|
|
34
|
+
GROUPS = {"inspection-tasks": ("质检任务", [(key, cmd.purpose, cmd.example) for key, cmd in COMMANDS.items()])}
|
|
35
|
+
MEMBER_ACTIONS = {"list", "options", "get", "runs", "run-detail", "download-recording"}
|
|
36
|
+
CONFIRM_ACTIONS = {"cancel", "retry", "retry-call", "delete"}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def arguments(parser, action):
|
|
40
|
+
add = parser.add_argument
|
|
41
|
+
path = COMMANDS[action].path
|
|
42
|
+
if "{task_id}" in path:
|
|
43
|
+
add("task_id", metavar="task_id", type=positive_id, help="质检任务 ID")
|
|
44
|
+
if "{call_id}" in path:
|
|
45
|
+
add("call_id", metavar="call_id", type=segment, help="执行记录中的平台通话 ID")
|
|
46
|
+
if action in ("list", "create"):
|
|
47
|
+
add("--tab", choices=("auto", "temp"), required=action == "create", default="auto",
|
|
48
|
+
help="auto 为自动任务,temp 为临时批次;查询默认 auto,创建时必填")
|
|
49
|
+
if action in ("list", "runs"):
|
|
50
|
+
add("--page", type=positive_id, default=1, help="页码,默认 1")
|
|
51
|
+
add("--per-page", type=int, choices=(20, 50, 100), default=20, help="每页条数,默认 20")
|
|
52
|
+
if action == "list":
|
|
53
|
+
add("--keyword", help="搜索任务名称或评分卡名称")
|
|
54
|
+
add("--exact", action="store_true", help="精确匹配任务名称")
|
|
55
|
+
add("--mode", choices=("all", "formal", "dry_run"), help="运行模式")
|
|
56
|
+
add("--enabled", choices=("all", "enabled", "disabled"), help="自动任务启用状态")
|
|
57
|
+
add("--status", choices=("all", "queued", "running", "completed", "failed", "cancelled"), help="临时批次状态")
|
|
58
|
+
if action in ("runs", "run-detail"):
|
|
59
|
+
add("--keyword", help="按通话 ID 搜索;单通详情沿用此筛选定位相邻记录")
|
|
60
|
+
add("--risk", choices=("all", "fatal", "redline", "prohibited"), help="触发的风险类型")
|
|
61
|
+
add("--status", choices=("all", "waiting", "pending", "running", "succeeded", "failed", "fallback", "cancelled"),
|
|
62
|
+
help="通话执行状态")
|
|
63
|
+
if action in ("create", "update", "preview", "debug"):
|
|
64
|
+
add("--json-file", required=True, help="UTF-8 JSON 请求体,示例见 guide")
|
|
65
|
+
if action == "debug":
|
|
66
|
+
add("--pin", required=True, type=segment, help="run-detail 返回的模型标识与版本,例如 service_score:1")
|
|
67
|
+
if action == "retry":
|
|
68
|
+
add("--include-fallback", action=argparse.BooleanOptionalAction, default=True, help="默认包含兜底项,--no-include-fallback 仅重试失败或未执行的通话")
|
|
69
|
+
if action == "download-recording":
|
|
70
|
+
add("--source", required=True, type=segment, help="快照中的 recording.source_id")
|
|
71
|
+
add("--output", required=True, help="本地录音路径")
|
|
72
|
+
add("--force", action="store_true", help="覆盖已有文件")
|
|
73
|
+
if action in CONFIRM_ACTIONS:
|
|
74
|
+
add("--yes", action="store_true", help="确认执行,非交互环境必填")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def run(client, vault, args):
|
|
78
|
+
action = args.action
|
|
79
|
+
command = COMMANDS[action]
|
|
80
|
+
path = command.path.format(**vars(args))
|
|
81
|
+
body = read_object(args.json_file) if hasattr(args, "json_file") else None
|
|
82
|
+
if action == "retry":
|
|
83
|
+
body = {"include_fallback": args.include_fallback}
|
|
84
|
+
fields = {"tab": "tab", "keyword": "q", "exact": "exact", "page": "page", "per_page": "pageSize",
|
|
85
|
+
"mode": "mode", "enabled": "enabled", "status": "status", "risk": "risk"}
|
|
86
|
+
params = {key: getattr(args, name) for name, key in fields.items() if getattr(args, name, None) is not None}
|
|
87
|
+
pair = current(client, vault)
|
|
88
|
+
if action not in MEMBER_ACTIONS and pair["profile"]["role"] != "admin":
|
|
89
|
+
raise Error("仅租户管理员可执行此质检任务操作", 3, code="FORBIDDEN", status=403)
|
|
90
|
+
if action in CONFIRM_ACTIONS and not args.yes:
|
|
91
|
+
confirm_operation(client, pair, f"确定{command.purpose}?目标 {path}")
|
|
92
|
+
if action == "download-recording":
|
|
93
|
+
if Path(args.output).exists() and not args.force:
|
|
94
|
+
raise Error("文件已存在,添加 --force 覆盖")
|
|
95
|
+
return client.request("GET", path, token=pair["access_token"], output=args.output, force=args.force)
|
|
96
|
+
return client.request(command.method, path, token=pair["access_token"], body=body, params=params,
|
|
97
|
+
read_only=action == "preview")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def examples():
|
|
101
|
+
filters = {"direction": "outbound", "conditions": []}
|
|
102
|
+
draft = {"name": "外呼试跑", "scorecard_key": "service_card", "version": 1, "mode": "dry_run", "filters": filters}
|
|
103
|
+
return {"inspection-tasks create": draft, "inspection-tasks update": draft, "inspection-tasks preview": filters,
|
|
104
|
+
"inspection-tasks debug": {"prompt": "请根据当前通话转写评价服务质量。"}}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
"""Quality-point experiments and the dataset operations needed to run them."""
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import NamedTuple
|
|
5
4
|
|
|
6
5
|
from .auth import current
|
|
7
|
-
from .commands import confirm_operation, read_object
|
|
6
|
+
from .commands import Command, confirm_operation, positive_id, read_object
|
|
8
7
|
from .http import Error, segment
|
|
9
8
|
|
|
10
9
|
|
|
11
|
-
class Command(NamedTuple):
|
|
12
|
-
method: str
|
|
13
|
-
path: str
|
|
14
|
-
purpose: str
|
|
15
|
-
example: str
|
|
16
|
-
|
|
17
|
-
|
|
18
10
|
LAB = "/model-lab/quality-points"
|
|
19
11
|
EXPERIMENT = LAB + "/{lab_id}"
|
|
20
12
|
RUN = EXPERIMENT + "/runs/{run}"
|
|
@@ -55,13 +47,6 @@ MEMBER_ACTIONS = {"list", "get", "sample", "download-recording"}
|
|
|
55
47
|
CONFIRM_ACTIONS = {"delete", "cancel", "retry", "confirm-rest", "clear-truth"}
|
|
56
48
|
|
|
57
49
|
|
|
58
|
-
def positive_id(value):
|
|
59
|
-
number = int(value)
|
|
60
|
-
if not 1 <= number <= 2147483647:
|
|
61
|
-
raise Error("编号须为 1 至 2147483647 的整数")
|
|
62
|
-
return number
|
|
63
|
-
|
|
64
|
-
|
|
65
50
|
def arguments(parser, group, action):
|
|
66
51
|
add = parser.add_argument
|
|
67
52
|
path = COMMANDS[group][action].path
|
|
@@ -3,7 +3,7 @@ import json
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
|
|
6
|
-
from . import __version__, auth, insights, labs, quality
|
|
6
|
+
from . import __version__, auth, insights, inspection, labs, quality
|
|
7
7
|
from .commands import reidentify_calls, run_business
|
|
8
8
|
from .http import Client, Error, PRODUCTION, note, segment
|
|
9
9
|
|
|
@@ -34,6 +34,7 @@ GROUPS = {
|
|
|
34
34
|
"auth": ("账号授权", [("login", "浏览器登录", ""), ("status", "在线校验登录状态", ""),
|
|
35
35
|
("logout", "退出并撤销授权", "")]),
|
|
36
36
|
"calls": ("本企业通话", [("list", "分页查询通话", "--page 1"), ("get", "读取通话详情", "CALL001"),
|
|
37
|
+
("quality-results", "查看本通话的正式质检历史", "CALL001"),
|
|
37
38
|
("download-recording", "下载一个录音来源", "CALL001 --source SOURCE --output call.wav"),
|
|
38
39
|
("reidentify-speakers", "按当前配置重新识别话轮角色", "CALL001 CALL002 --yes")]),
|
|
39
40
|
"accounts": ("成员账号", [("list", "分页查询成员", "--page 1"), ("get", "查看成员资料", "zhangsan"),
|
|
@@ -49,13 +50,16 @@ GROUPS = {
|
|
|
49
50
|
**insights.GROUPS,
|
|
50
51
|
**quality.GROUPS,
|
|
51
52
|
**labs.GROUPS,
|
|
53
|
+
**inspection.GROUPS,
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
GUARDED_ACTIONS = {"delete", "set", "reidentify-speakers", "workbook-commit", "cancel", "retry"} | labs.CONFIRM_ACTIONS
|
|
57
|
+
GUARDED_ACTIONS = {"delete", "set", "reidentify-speakers", "workbook-commit", "cancel", "retry"} | labs.CONFIRM_ACTIONS | inspection.CONFIRM_ACTIONS
|
|
56
58
|
|
|
57
59
|
|
|
58
60
|
def arguments(parser, group, action):
|
|
61
|
+
if group in inspection.GROUPS:
|
|
62
|
+
return inspection.arguments(parser, action)
|
|
59
63
|
if group in labs.GROUPS:
|
|
60
64
|
return labs.arguments(parser, group, action)
|
|
61
65
|
if group in quality.GROUPS:
|
|
@@ -77,7 +81,7 @@ def arguments(parser, group, action):
|
|
|
77
81
|
add("--direction", choices=("inbound", "outbound", "unknown"), help="通话方向")
|
|
78
82
|
add("--tag-field", help="标签字段的字段键,须与 --tag 同时使用")
|
|
79
83
|
add("--tag", action="append", help="标签,完整匹配、区分大小写;可重复,最多 10 个,命中任一")
|
|
80
|
-
if action in ("delete", "enable", "disable", "download-recording", "update") or (action == "get" and group in ("calls", "accounts", "call-fields")):
|
|
84
|
+
if action in ("delete", "enable", "disable", "download-recording", "quality-results", "update") or (action == "get" and group in ("calls", "accounts", "call-fields")):
|
|
81
85
|
label = {"calls": "call_id", "accounts": "username", "call-fields": "field_key"}[group]
|
|
82
86
|
add("identifier", metavar=label, help="目标标识")
|
|
83
87
|
if action == "reidentify-speakers":
|
|
@@ -126,6 +130,8 @@ def parser_tree():
|
|
|
126
130
|
arguments(child, name, action)
|
|
127
131
|
if name in insights.GROUPS:
|
|
128
132
|
role = insights.role(name, action)
|
|
133
|
+
elif name in inspection.GROUPS:
|
|
134
|
+
role = "管理员或成员" if action in inspection.MEMBER_ACTIONS else "管理员"
|
|
129
135
|
elif name in quality.GROUPS:
|
|
130
136
|
role = "管理员或成员" if action in quality.READ_ACTIONS else "管理员"
|
|
131
137
|
elif name in labs.GROUPS:
|
|
@@ -146,13 +152,13 @@ def guide_content(entries):
|
|
|
146
152
|
field = dict(label="门店", description="来电门店", config={}, options=[])
|
|
147
153
|
return {
|
|
148
154
|
"product": "企业是数据隔离范围。通话可以包含录音来源、按时间排序的转写话轮和企业定义的业务字段。",
|
|
149
|
-
"permissions": "管理员可管理账号、字段、话者识别和 ASR
|
|
155
|
+
"permissions": "管理员可管理账号、字段、话者识别和 ASR 设置。成员可查看本企业通话及录音。洞察配置按账号现有查看或编辑权限开放,打标任务预览和维护、打标代码维护仅对管理员开放。管理员和成员均可读取质检模型、评分卡及选项,查重、维护与模型试跑需要管理员权限。成员可查看测试数据集列表和质检点实验结果,管理员还可采集样本、运行实验和标注。成员可复核质检任务并下载快照录音,任务维护、预览与调试需要管理员权限。",
|
|
150
156
|
"install": "python -m pip install --upgrade smartcheck-cli 或 pipx install smartcheck-cli",
|
|
151
157
|
"global_options": ["--host > SMARTCHECK_HOST > " + PRODUCTION, "--pretty 缩进 JSON",
|
|
152
158
|
"--timeout 请求超时秒数(默认 30,质检试跑默认 70,最大 300)", "--version 版本", "--help 帮助"],
|
|
153
159
|
"guide": "smartcheck guide [--format terminal|markdown|json],默认 terminal,无需登录",
|
|
154
160
|
"commands": entries,
|
|
155
|
-
"examples": {**insights.examples(), **quality.examples(), **labs.examples(),
|
|
161
|
+
"examples": {**insights.examples(), **quality.examples(), **labs.examples(), **inspection.examples(),
|
|
156
162
|
"call-fields create": dict(field_key="store", field_type="text", **field),
|
|
157
163
|
"call-fields create(标签)": dict(field_key="customer_tags", field_type="tags", label="客户标签",
|
|
158
164
|
description="上游推送的通话标记", config={}, options=[]),
|
|
@@ -177,6 +183,8 @@ def guide_content(entries):
|
|
|
177
183
|
"smartcheck quality-models trial --call-id CALL001 --json-file model.json",
|
|
178
184
|
"评分卡:用 smartcheck scorecards options 选择已发布的 model_key 和 version,"
|
|
179
185
|
"在评分项中填入 model_key 和 model_version 后运行 smartcheck scorecards create --json-file card.json",
|
|
186
|
+
"质检任务:用 inspection-tasks options 选择评分卡版本,preview 预览临时批次范围,create 创建任务。"
|
|
187
|
+
"用 runs 查询执行记录,用 run-detail 复核单通,用 calls quality-results 查询正式历史。",
|
|
180
188
|
"实验室:通过 test-datasets create、add-calls 准备数据集,通过 quality-labs create 启动实验。"
|
|
181
189
|
"用 get 查看进度,sample 复核样本,set-truth 保存答案,preview 和 rerun 发起复测,再用 get 比较各轮指标。"],
|
|
182
190
|
}
|
|
@@ -209,7 +217,7 @@ def main():
|
|
|
209
217
|
try:
|
|
210
218
|
parser, entries = parser_tree()
|
|
211
219
|
args = parser.parse_args()
|
|
212
|
-
trial = (args.group, getattr(args, "action", None)) in {("quality-models", "trial"), ("quality-labs", "debug")}
|
|
220
|
+
trial = (args.group, getattr(args, "action", None)) in {("quality-models", "trial"), ("quality-labs", "debug"), ("inspection-tasks", "debug")}
|
|
213
221
|
client = Client(getattr(args, "host", os.getenv("SMARTCHECK_HOST", PRODUCTION)),
|
|
214
222
|
getattr(args, "timeout", 70 if trial else 30))
|
|
215
223
|
if args.group == "guide":
|
|
@@ -236,6 +244,8 @@ def main():
|
|
|
236
244
|
result = insights.run(client, vault, args)
|
|
237
245
|
elif args.group in quality.GROUPS:
|
|
238
246
|
result = quality.run(client, vault, args)
|
|
247
|
+
elif args.group in inspection.GROUPS:
|
|
248
|
+
result = inspection.run(client, vault, args)
|
|
239
249
|
elif args.group in labs.GROUPS:
|
|
240
250
|
result = labs.run(client, vault, args)
|
|
241
251
|
elif args.group != "auth":
|
|
@@ -4,6 +4,7 @@ smartcheck_cli/auth.py
|
|
|
4
4
|
smartcheck_cli/commands.py
|
|
5
5
|
smartcheck_cli/http.py
|
|
6
6
|
smartcheck_cli/insights.py
|
|
7
|
+
smartcheck_cli/inspection.py
|
|
7
8
|
smartcheck_cli/labs.py
|
|
8
9
|
smartcheck_cli/main.py
|
|
9
10
|
smartcheck_cli/quality.py
|
|
@@ -14,4 +15,5 @@ smartcheck_cli.egg-info/entry_points.txt
|
|
|
14
15
|
smartcheck_cli.egg-info/requires.txt
|
|
15
16
|
smartcheck_cli.egg-info/top_level.txt
|
|
16
17
|
tests/test_cli.py
|
|
18
|
+
tests/test_inspection.py
|
|
17
19
|
tests/test_labs.py
|
|
@@ -16,7 +16,7 @@ from unittest.mock import Mock, patch
|
|
|
16
16
|
|
|
17
17
|
import requests
|
|
18
18
|
|
|
19
|
-
from smartcheck_cli import auth, insights, labs, quality
|
|
19
|
+
from smartcheck_cli import auth, insights, inspection, labs, quality
|
|
20
20
|
from smartcheck_cli.commands import run_business
|
|
21
21
|
from smartcheck_cli.http import Client, Error, LOCAL, save_recording
|
|
22
22
|
from smartcheck_cli.main import guide_content, main, parser_tree
|
|
@@ -460,6 +460,7 @@ class CliTests(unittest.TestCase):
|
|
|
460
460
|
(["tagging-tasks", "cancel", "12"], 1), (["tagging-tasks", "retry", "12"], 1),
|
|
461
461
|
(["tagging-tasks", "delete", "12"], 1),
|
|
462
462
|
(["quality-models", "delete", "service_score"], 1), (["scorecards", "delete", "service_card"], 1),
|
|
463
|
+
(["inspection-tasks", "retry-call", "12", "CALL001"], 1),
|
|
463
464
|
(["quality-labs", "confirm-rest", "1", "--run", "1"], 1),
|
|
464
465
|
(["quality-labs", "clear-truth", "1", "--run", "1", "--sample", "2"], 1),
|
|
465
466
|
(["insight-datasets", "workbook-commit", "--file", "a.xlsx", "--json-file", "p.json", "--token", "t"], 1),
|
|
@@ -472,7 +473,7 @@ class CliTests(unittest.TestCase):
|
|
|
472
473
|
else:
|
|
473
474
|
self.assertIn("commands", json.loads(result.stdout))
|
|
474
475
|
root, entries = parser_tree()
|
|
475
|
-
self.assertEqual(sum(e["command"].split()[1] not in (insights.GROUPS | quality.GROUPS | labs.GROUPS) for e in entries),
|
|
476
|
+
self.assertEqual(sum(e["command"].split()[1] not in (insights.GROUPS | quality.GROUPS | labs.GROUPS | inspection.GROUPS) for e in entries), 25)
|
|
476
477
|
self.assertEqual({e["command"].split()[1] for e in entries} & insights.GROUPS.keys(),
|
|
477
478
|
{"tag-catalog", "product-models", "insight-datasets", "tagging-code", "tagging-tasks", "insight-fields"})
|
|
478
479
|
for entry in entries:
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import tempfile
|
|
3
|
+
import unittest
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from unittest.mock import Mock, patch
|
|
6
|
+
|
|
7
|
+
from smartcheck_cli import commands, inspection
|
|
8
|
+
from smartcheck_cli.http import Error
|
|
9
|
+
from smartcheck_cli.main import parser_tree
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InspectionCommands(unittest.TestCase):
|
|
13
|
+
@classmethod
|
|
14
|
+
def setUpClass(cls):
|
|
15
|
+
cls.parser, _ = parser_tree()
|
|
16
|
+
|
|
17
|
+
def test_requests_and_roles(self):
|
|
18
|
+
task = "/inspection/tasks"
|
|
19
|
+
call = task + "/7/calls/C%231"
|
|
20
|
+
draft = inspection.examples()["inspection-tasks create"]
|
|
21
|
+
query = {"q": "C", "status": "fallback", "risk": "redline"}
|
|
22
|
+
cases = (
|
|
23
|
+
("list --tab temp --keyword A --exact --mode dry_run --enabled all --status completed --page 2 --per-page 50",
|
|
24
|
+
"GET", task, dict(tab="temp", q="A", exact=True, mode="dry_run", enabled="all", status="completed",
|
|
25
|
+
page=2, pageSize=50), None),
|
|
26
|
+
("options", "GET", task + "/options", {}, None),
|
|
27
|
+
("get 7", "GET", task + "/7", {}, None),
|
|
28
|
+
("create --tab temp", "POST", task, {"tab": "temp"}, draft),
|
|
29
|
+
("update 7", "PUT", task + "/7", {}, draft),
|
|
30
|
+
("preview", "POST", task + "/preview", {}, draft["filters"]),
|
|
31
|
+
("enable 7", "POST", task + "/7/enable", {}, None),
|
|
32
|
+
("disable 7", "POST", task + "/7/disable", {}, None),
|
|
33
|
+
("cancel 7 --yes", "POST", task + "/7/cancel", {}, None),
|
|
34
|
+
("delete 7 --yes", "DELETE", task + "/7", {}, None),
|
|
35
|
+
("retry 7 --yes", "POST", task + "/7/retry", {}, {"include_fallback": True}),
|
|
36
|
+
("retry 7 --no-include-fallback --yes", "POST", task + "/7/retry", {}, {"include_fallback": False}),
|
|
37
|
+
("retry-call 7 C#1 --yes", "POST", call + "/retry", {}, None),
|
|
38
|
+
("runs 7 --keyword C --status fallback --risk redline", "GET", task + "/7/calls",
|
|
39
|
+
{**query, "page": 1, "pageSize": 20}, None),
|
|
40
|
+
("run-detail 7 C#1 --keyword C --status fallback --risk redline", "GET", call, query, None),
|
|
41
|
+
("debug 7 C#1 --pin sample:1", "POST", call + "/models/sample%3A1/debug", {}, {"prompt": "测试"}),
|
|
42
|
+
)
|
|
43
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
44
|
+
for command, method, path, params, body in cases:
|
|
45
|
+
argv = command.split()
|
|
46
|
+
if argv[0] in ("create", "update", "preview", "debug"):
|
|
47
|
+
file = Path(directory) / "input.json"
|
|
48
|
+
file.write_text(json.dumps(body), encoding="utf-8")
|
|
49
|
+
argv += ["--json-file", str(file)]
|
|
50
|
+
args = self.parser.parse_args(["inspection-tasks", *argv])
|
|
51
|
+
client = Mock()
|
|
52
|
+
profile = {"role": "member"}
|
|
53
|
+
with self.subTest(command=command), patch.object(
|
|
54
|
+
inspection, "current", return_value={"access_token": "token", "profile": profile}
|
|
55
|
+
):
|
|
56
|
+
if method != "GET":
|
|
57
|
+
with self.assertRaises(Error) as exc:
|
|
58
|
+
inspection.run(client, None, args)
|
|
59
|
+
self.assertEqual(exc.exception.status, 403)
|
|
60
|
+
client.request.assert_not_called()
|
|
61
|
+
profile["role"] = "admin"
|
|
62
|
+
inspection.run(client, None, args)
|
|
63
|
+
client.request.assert_called_once_with(method, path, token="token", body=body, params=params,
|
|
64
|
+
read_only=argv[0] == "preview")
|
|
65
|
+
|
|
66
|
+
def test_member_recording_and_formal_history(self):
|
|
67
|
+
client = Mock()
|
|
68
|
+
pair = {"access_token": "token", "profile": {"role": "member"}}
|
|
69
|
+
with tempfile.TemporaryDirectory() as directory, patch.object(inspection, "current", return_value=pair):
|
|
70
|
+
path = str(Path(directory) / "audio.mp3")
|
|
71
|
+
args = self.parser.parse_args(["inspection-tasks", "download-recording", "7", "C#1", "--source", "SRC",
|
|
72
|
+
"--output", path])
|
|
73
|
+
inspection.run(client, None, args)
|
|
74
|
+
client.request.assert_called_once_with("GET", "/inspection/tasks/7/calls/C%231/recording/SRC/audio",
|
|
75
|
+
token="token", output=path, force=False)
|
|
76
|
+
Path(path).touch()
|
|
77
|
+
with self.assertRaises(Error):
|
|
78
|
+
inspection.run(client, None, args)
|
|
79
|
+
self.assertEqual(client.request.call_count, 1)
|
|
80
|
+
args = self.parser.parse_args(["calls", "quality-results", "C#1"])
|
|
81
|
+
with patch.object(commands, "current", return_value=pair):
|
|
82
|
+
commands.run_business(client, None, args)
|
|
83
|
+
self.assertEqual(client.request.call_args.args, ("GET", "/calls/C%231/quality-results"))
|
|
84
|
+
|
|
85
|
+
def test_invalid_targets_and_missing_tab(self):
|
|
86
|
+
for argv in (["get", "0"], ["create", "--json-file", "task.json"], ["runs", "1", "--per-page", "10"],
|
|
87
|
+
["run-detail", "1", "../x"], ["debug", "1", "C", "--pin", "..", "--json-file", "p.json"]):
|
|
88
|
+
with self.subTest(argv=argv), self.assertRaises(Error):
|
|
89
|
+
self.parser.parse_args(["inspection-tasks", *argv])
|
|
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
|