itam-assistant 0.1.9__py3-none-any.whl → 0.1.11__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.
- it_assistant/__init__.py +0 -0
- it_assistant/ailyapp_client.py +129 -0
- it_assistant/config.py +51 -0
- it_assistant/do_ai.py +928 -0
- it_assistant/intent_detail.py +289 -0
- it_assistant/lark_client.py +159 -0
- it_assistant/logger.py +53 -0
- it_assistant/openapi.py +687 -0
- it_assistant/test.py +1 -0
- itam_assistant/do_ai.py +92 -3
- {itam_assistant-0.1.9.dist-info → itam_assistant-0.1.11.dist-info}/METADATA +2 -2
- itam_assistant-0.1.11.dist-info/RECORD +28 -0
- main/__init__.py +0 -0
- main/ailyapp_client.py +132 -0
- main/do_ai.py +177 -0
- main/intent_detail.py +326 -0
- main/lark_client.py +159 -0
- main/logger.py +53 -0
- itam_assistant-0.1.9.dist-info/RECORD +0 -13
- {itam_assistant-0.1.9.dist-info → itam_assistant-0.1.11.dist-info}/WHEEL +0 -0
- {itam_assistant-0.1.9.dist-info → itam_assistant-0.1.11.dist-info}/top_level.txt +0 -0
it_assistant/test.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["鼠标","显示器双C数据线","Type-C扩展坞","西部数据-WDBEPK0020BBK","鼠标和键盘","鼠标","鼠标","鼠标","笔记本充电器","笔记本充电器","鼠标","And crown-PTH-660/K0-F","mouse and keyboard","hdmi dongle","笔记本支架","蓝牙键盘","mac蓝牙鼠标","鼠标耳机键盘","显示器双C数据线","鼠标","鼠标","鼠标键盘","Adapter","外置硬盘","keyboard","笔记本充电器","鼠标和键盘","Type-C扩展坞","65W笔记本电源","安卓手机数据线","笔记本电源","keyboard","鼠标和键盘","SanDisk-SDSSDE81-4T00-Z25"]
|
itam_assistant/do_ai.py
CHANGED
|
@@ -89,19 +89,20 @@ def do_ai_auto(Testk_data, clientinfo):
|
|
|
89
89
|
startAt = int(time.time())
|
|
90
90
|
# 创建会话
|
|
91
91
|
seseion_id = AilyLarkClient(clientinfo).create_ailysession(tenant_access_token)
|
|
92
|
-
time.sleep(
|
|
92
|
+
time.sleep(3)
|
|
93
93
|
if not seseion_id:
|
|
94
94
|
raise ValueError("未能成功创建会话")
|
|
95
95
|
# 创建消息
|
|
96
96
|
message_id = AilyLarkClient(clientinfo).create_ailysessionaily_message(tenant_access_token, seseion_id,
|
|
97
97
|
aa)
|
|
98
|
-
time.sleep(
|
|
98
|
+
time.sleep(3)
|
|
99
99
|
if not message_id:
|
|
100
100
|
raise ValueError("未能成功创建消息")
|
|
101
101
|
# 创建运行实例
|
|
102
102
|
runs = AilyLarkClient(clientinfo).create_ailysession_run(tenant_access_token, seseion_id)
|
|
103
|
-
time.sleep(
|
|
103
|
+
time.sleep(4)
|
|
104
104
|
num = num + 1
|
|
105
|
+
time.sleep(4)
|
|
105
106
|
return startAt, num
|
|
106
107
|
except KeyError as ke:
|
|
107
108
|
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
@@ -970,3 +971,91 @@ def write_excletolist(data_name):
|
|
|
970
971
|
|
|
971
972
|
|
|
972
973
|
|
|
974
|
+
def do_waterlevelline_autotest_fix(collections, clientinfo, score_threshold):
|
|
975
|
+
"""
|
|
976
|
+
水位线评测- 返回 符合报告模式的结果
|
|
977
|
+
"""
|
|
978
|
+
keywprd= []
|
|
979
|
+
info_list = []
|
|
980
|
+
info = {
|
|
981
|
+
"input": {
|
|
982
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
983
|
+
},
|
|
984
|
+
"output": {
|
|
985
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
986
|
+
},
|
|
987
|
+
"rt": True,
|
|
988
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
989
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
990
|
+
}],
|
|
991
|
+
"artificial": []
|
|
992
|
+
}
|
|
993
|
+
a =0
|
|
994
|
+
for i in collections:
|
|
995
|
+
info['input']['用户输入/userInput'] = i['ext']['资产名称']
|
|
996
|
+
info['output']['用户输入/output'] = i['ext']['资产名称']
|
|
997
|
+
info['exp'] = []
|
|
998
|
+
for j in [i['ext']['匹配型号1'], i['ext'].get('匹配型号2'),i['ext'].get('匹配型号3'),i['ext'].get('匹配型号4'),i['ext'].get('匹配型号5'),i['ext'].get('匹配型号6'),i['ext'].get('匹配型号7'),i['ext'].get('匹配型号8'),i['ext'].get('匹配型号9'),i['ext'].get('匹配型号10')]:
|
|
999
|
+
if j:
|
|
1000
|
+
info['exp'].append({'label': j, 'score': score_threshold})
|
|
1001
|
+
#判断i['ext']['BPO标注-AP-资产型号']是否为空,为空就不用读取,不为空就读取
|
|
1002
|
+
if i['ext']['资产名称']:
|
|
1003
|
+
asset_name = i['ext']['资产名称']
|
|
1004
|
+
try:
|
|
1005
|
+
if isinstance(asset_name, str):
|
|
1006
|
+
asset_name = json.loads(asset_name)
|
|
1007
|
+
except json.JSONDecodeError:
|
|
1008
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
1009
|
+
pass
|
|
1010
|
+
info['artificial'] = info['exp']
|
|
1011
|
+
if i['ext']['资产名称']:
|
|
1012
|
+
asset_name = i['ext']['资产名称']
|
|
1013
|
+
try:
|
|
1014
|
+
if isinstance(asset_name, str):
|
|
1015
|
+
asset_name = json.loads(asset_name)
|
|
1016
|
+
except json.JSONDecodeError:
|
|
1017
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
1018
|
+
pass
|
|
1019
|
+
if "设备领用" in i['ext']['评测集标签']:
|
|
1020
|
+
keywprd = GetBestMatchItemandres_new(asset_name, i['ext']['资产类型'], clientinfo)
|
|
1021
|
+
|
|
1022
|
+
else:
|
|
1023
|
+
res = ""
|
|
1024
|
+
infoout = do_waterlevellineres_listv3(keywprd, info)
|
|
1025
|
+
info_list.append(copy.deepcopy(infoout))
|
|
1026
|
+
a = a+1
|
|
1027
|
+
print("这是"+str(a))
|
|
1028
|
+
bbb = a
|
|
1029
|
+
return info_list
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
def do_waterlevellineres_listv3(res, info):
|
|
1033
|
+
"""
|
|
1034
|
+
获取结果,并组装水位线info
|
|
1035
|
+
"""
|
|
1036
|
+
if res == '':
|
|
1037
|
+
info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
1038
|
+
info['rt'] = False
|
|
1039
|
+
return info
|
|
1040
|
+
reslist = res['res']
|
|
1041
|
+
info['output']['用户输入/output'] = 'log_id:' + res.get('log')
|
|
1042
|
+
if reslist:
|
|
1043
|
+
#取所有结果并追加到info['label']
|
|
1044
|
+
info['label'] = []
|
|
1045
|
+
if len(reslist) > 0:
|
|
1046
|
+
for j in range(len(reslist)):
|
|
1047
|
+
aaa = {'label': reslist[j]['Name'],
|
|
1048
|
+
'score': reslist[j]['Score']}
|
|
1049
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
1050
|
+
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
1051
|
+
for a in range(len(info['exp'])):
|
|
1052
|
+
if info['exp'][a]['label']== info['label'][a]['label']:
|
|
1053
|
+
info['rt'] = True
|
|
1054
|
+
else:
|
|
1055
|
+
info['rt'] = False
|
|
1056
|
+
break
|
|
1057
|
+
else:
|
|
1058
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
1059
|
+
info['rt'] = False
|
|
1060
|
+
|
|
1061
|
+
return info
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
it_assistant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
it_assistant/ailyapp_client.py,sha256=w-ihtcmRgOQCgWK0jB8eHGCikjo1tbre3xCiEKhLrUA,6357
|
|
3
|
+
it_assistant/config.py,sha256=L_5grm2ZWwg_S1JTOU6XLhQ5GPeYJaBFBLwzP2JA5Ys,5498
|
|
4
|
+
it_assistant/do_ai.py,sha256=Rs7SdXx_7DA9MQeEC9TQ-lHYZLFykETXf63-ppgrKek,41505
|
|
5
|
+
it_assistant/intent_detail.py,sha256=hmEj1KpcuKNvsoBZmn5PnbsBIIx6XGmQBJWdW_ICFmg,16831
|
|
6
|
+
it_assistant/lark_client.py,sha256=ZVDsdt7ucQvJN1-khC3TR-0IMeYaQXfdWF5DxRrkBH4,6665
|
|
7
|
+
it_assistant/logger.py,sha256=W3-tbQ4J-QKSrQSpaNBruzoyMuWYrUkrIY0uBZ1o-lw,1583
|
|
8
|
+
it_assistant/openapi.py,sha256=-YMx-Feu1dHkQ86EB1-QmQZJHS4dND3sNSnIpBF94w4,37730
|
|
9
|
+
it_assistant/test.py,sha256=qGSihMYmtZkz_vifwEOz579f_wPBJAx5_rz1sABUyo4,581
|
|
10
|
+
itam_assistant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
itam_assistant/ailyapp_client.py,sha256=w-ihtcmRgOQCgWK0jB8eHGCikjo1tbre3xCiEKhLrUA,6357
|
|
12
|
+
itam_assistant/config.py,sha256=L_5grm2ZWwg_S1JTOU6XLhQ5GPeYJaBFBLwzP2JA5Ys,5498
|
|
13
|
+
itam_assistant/do_ai.py,sha256=0ICPD3hXJty4cQX-LxBjl6os-2oXJyO0Iej0QuyMkJw,46769
|
|
14
|
+
itam_assistant/intent_detail.py,sha256=hmEj1KpcuKNvsoBZmn5PnbsBIIx6XGmQBJWdW_ICFmg,16831
|
|
15
|
+
itam_assistant/lark_client.py,sha256=ZVDsdt7ucQvJN1-khC3TR-0IMeYaQXfdWF5DxRrkBH4,6665
|
|
16
|
+
itam_assistant/logger.py,sha256=W3-tbQ4J-QKSrQSpaNBruzoyMuWYrUkrIY0uBZ1o-lw,1583
|
|
17
|
+
itam_assistant/openapi.py,sha256=-YMx-Feu1dHkQ86EB1-QmQZJHS4dND3sNSnIpBF94w4,37730
|
|
18
|
+
itam_assistant/test.py,sha256=qGSihMYmtZkz_vifwEOz579f_wPBJAx5_rz1sABUyo4,581
|
|
19
|
+
main/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
main/ailyapp_client.py,sha256=6CVlBkuiIvIzqG0lM38tdGFBNLhVi2_0jQIbHg7fpzw,6515
|
|
21
|
+
main/do_ai.py,sha256=rxsTRdd3oBs-gsIssHz3XV-6lIC5Bq4qoyNuyQzjidg,6879
|
|
22
|
+
main/intent_detail.py,sha256=Fo76c4BpGya-znCnKH7YAcr_2UJtbi3WPQN-PwtVsXc,18533
|
|
23
|
+
main/lark_client.py,sha256=ZVDsdt7ucQvJN1-khC3TR-0IMeYaQXfdWF5DxRrkBH4,6665
|
|
24
|
+
main/logger.py,sha256=W3-tbQ4J-QKSrQSpaNBruzoyMuWYrUkrIY0uBZ1o-lw,1583
|
|
25
|
+
itam_assistant-0.1.11.dist-info/METADATA,sha256=Jo4YBzkjITrauPn5eAA5CKwqtXBIUbIP2gvSU4vpPWE,775
|
|
26
|
+
itam_assistant-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
27
|
+
itam_assistant-0.1.11.dist-info/top_level.txt,sha256=KpZA4H04XBVAB3NLq0AAEOrAGEurwMnWw41AhJVqVFI,15
|
|
28
|
+
itam_assistant-0.1.11.dist-info/RECORD,,
|
main/__init__.py
ADDED
|
File without changes
|
main/ailyapp_client.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import lark_oapi as lark
|
|
4
|
+
from lark_oapi.api.auth.v3 import *
|
|
5
|
+
from lark_oapi.api.aily.v1 import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development
|
|
9
|
+
# 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用
|
|
10
|
+
# 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET.
|
|
11
|
+
|
|
12
|
+
class AilyLarkClient:
|
|
13
|
+
def __init__(self):
|
|
14
|
+
"""
|
|
15
|
+
初始化 Client 实例,tenant_access_token 会在 Client 初始化时自动获取
|
|
16
|
+
"""
|
|
17
|
+
self.aily_app_id = "spring_f17d05d924__c"
|
|
18
|
+
self.app_id = "cli_a6e3aea1a13c900c"
|
|
19
|
+
self.app_secret = "J0fAPt3BL6bv4KUJV0dJMdTUdr0pv3xx"
|
|
20
|
+
# 创建 Lark-tenant tenant客户端
|
|
21
|
+
self.tlark_client = lark.Client.builder().app_id(self.app_id).app_secret(self.app_secret).build()
|
|
22
|
+
|
|
23
|
+
# 创建 Lark-tenant user 客户端
|
|
24
|
+
self.ulark_client = lark.Client.builder().enable_set_token(True).log_level(lark.LogLevel.DEBUG).build()
|
|
25
|
+
|
|
26
|
+
def get_tenant_access_token(self):
|
|
27
|
+
# 构造请求对象
|
|
28
|
+
request: InternalTenantAccessTokenRequest = InternalTenantAccessTokenRequest.builder() \
|
|
29
|
+
.request_body(InternalTenantAccessTokenRequestBody.builder()
|
|
30
|
+
.app_id(self.app_id)
|
|
31
|
+
.app_secret(self.app_secret)
|
|
32
|
+
.build()) \
|
|
33
|
+
.build()
|
|
34
|
+
|
|
35
|
+
# 发起请求
|
|
36
|
+
response: InternalTenantAccessTokenResponse = self.tlark_client.auth.v3.tenant_access_token.internal(request)
|
|
37
|
+
|
|
38
|
+
# 处理失败返回
|
|
39
|
+
if not response.success():
|
|
40
|
+
lark.logger.error(
|
|
41
|
+
f"client.auth.v3.tenant_access_token.internal failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
42
|
+
return
|
|
43
|
+
# 处理业务结果
|
|
44
|
+
lark.logger.info(lark.JSON.marshal(response.raw, indent=4))
|
|
45
|
+
tenant_access_token = json.loads(response.raw.content).get("tenant_access_token")
|
|
46
|
+
if tenant_access_token:
|
|
47
|
+
return tenant_access_token
|
|
48
|
+
else:
|
|
49
|
+
lark.logger.error(
|
|
50
|
+
f"client.auth.v3.tenant_access_token.internal failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
def create_ailysession(self, access_token):
|
|
54
|
+
# 创建会话
|
|
55
|
+
# 构造请求对象
|
|
56
|
+
request: CreateAilySessionRequest = CreateAilySessionRequest.builder() \
|
|
57
|
+
.request_body(CreateAilySessionRequestBody.builder()
|
|
58
|
+
.channel_context("{}")
|
|
59
|
+
.metadata("{}")
|
|
60
|
+
.build()) \
|
|
61
|
+
.build()
|
|
62
|
+
|
|
63
|
+
# 发起请求
|
|
64
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
65
|
+
response: CreateAilySessionResponse = self.ulark_client.aily.v1.aily_session.create(request, option)
|
|
66
|
+
|
|
67
|
+
# 处理失败返回
|
|
68
|
+
if not response.success():
|
|
69
|
+
lark.logger.error(
|
|
70
|
+
f"client.aily.v1.aily_session.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
# 处理业务结果
|
|
74
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
75
|
+
return response.data.session.id
|
|
76
|
+
|
|
77
|
+
def create_ailysessionaily_message(self, access_token, session_id, content):
|
|
78
|
+
# 发送智能伙伴消息
|
|
79
|
+
# 构造请求对象
|
|
80
|
+
request: CreateAilySessionAilyMessageRequest = CreateAilySessionAilyMessageRequest.builder() \
|
|
81
|
+
.aily_session_id(session_id) \
|
|
82
|
+
.request_body(CreateAilySessionAilyMessageRequestBody.builder()
|
|
83
|
+
.content(content)
|
|
84
|
+
.content_type("MDX")
|
|
85
|
+
.idempotent_id("idempotent_id_1")
|
|
86
|
+
.build()) \
|
|
87
|
+
.build()
|
|
88
|
+
# 发起请求
|
|
89
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
90
|
+
response: CreateAilySessionAilyMessageResponse = self.ulark_client.aily.v1.aily_session_aily_message.create(
|
|
91
|
+
request,
|
|
92
|
+
option)
|
|
93
|
+
# 处理失败返回
|
|
94
|
+
if not response.success():
|
|
95
|
+
lark.logger.error(
|
|
96
|
+
f"client.aily.v1.aily_session_aily_message.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
97
|
+
return
|
|
98
|
+
# 处理业务结果
|
|
99
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
100
|
+
return response.data.message.id
|
|
101
|
+
|
|
102
|
+
def create_ailysession_run(self, access_token, aily_session_id):
|
|
103
|
+
# 创建运行
|
|
104
|
+
# 构造请求对象
|
|
105
|
+
request: CreateAilySessionRunRequest = CreateAilySessionRunRequest.builder() \
|
|
106
|
+
.aily_session_id(aily_session_id) \
|
|
107
|
+
.request_body(CreateAilySessionRunRequestBody.builder()
|
|
108
|
+
.app_id(self.aily_app_id)
|
|
109
|
+
.build()) \
|
|
110
|
+
.build()
|
|
111
|
+
# 发起请求
|
|
112
|
+
option = lark.RequestOption.builder().user_access_token(
|
|
113
|
+
access_token).build()
|
|
114
|
+
response: CreateAilySessionRunResponse = self.ulark_client.aily.v1.aily_session_run.create(request, option)
|
|
115
|
+
# 处理失败返回
|
|
116
|
+
if not response.success():
|
|
117
|
+
lark.logger.error(
|
|
118
|
+
f"client.aily.v1.aily_session_run.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
# 处理业务结果
|
|
122
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == '__main__':
|
|
127
|
+
tenant_access_token = AilyLarkClient().get_tenant_access_token()
|
|
128
|
+
seseion_id = AilyLarkClient().create_ailysession(tenant_access_token)
|
|
129
|
+
print(seseion_id)
|
|
130
|
+
message_id = AilyLarkClient().create_ailysessionaily_message(tenant_access_token, seseion_id, "你好")
|
|
131
|
+
runs = AilyLarkClient().create_ailysession_run(tenant_access_token, seseion_id)
|
|
132
|
+
|
main/do_ai.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from itam_assistant1.ailyapp_client import AilyLarkClient
|
|
4
|
+
from itam_assistant1.lark_client import LarkdocsClient
|
|
5
|
+
from itam_assistant1.intent_detail import *
|
|
6
|
+
import datetime
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Testsuitelink = "https://bytedance.larkoffice.com/sheets/ZVzfsw4rMhkMF6tjtxmc4BdSnMb"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def do_ai_auto(Testsuitelink):
|
|
14
|
+
"""
|
|
15
|
+
自动化执行AI测试用例
|
|
16
|
+
"""
|
|
17
|
+
startAt = 0
|
|
18
|
+
try:
|
|
19
|
+
# 获取租户访问令牌
|
|
20
|
+
tenant_access_token = AilyLarkClient().get_tenant_access_token()
|
|
21
|
+
if not tenant_access_token:
|
|
22
|
+
raise ValueError("未能获取到有效的租户访问令牌")
|
|
23
|
+
# 通过文档链接获取spreadsheet_token
|
|
24
|
+
spreadsheet_token = Testsuitelink.split("/")[-1]
|
|
25
|
+
if not spreadsheet_token:
|
|
26
|
+
raise ValueError("未能从文档链接中提取到有效的spreadsheet_token")
|
|
27
|
+
# 读取表格用户输入
|
|
28
|
+
spreadsheet = LarkdocsClient().get_the_worksheet(spreadsheet_token)
|
|
29
|
+
if not spreadsheet:
|
|
30
|
+
raise ValueError("未能获取到有效的工作表数据")
|
|
31
|
+
for i in spreadsheet.sheets:
|
|
32
|
+
column_count = i.grid_properties.column_count
|
|
33
|
+
row_count = i.grid_properties.row_count
|
|
34
|
+
sheet_id = i.sheet_id
|
|
35
|
+
title = i.title
|
|
36
|
+
if title == "测试集":
|
|
37
|
+
# 构建JSON字符串
|
|
38
|
+
json_str = {"ranges": [sheet_id + "!A1:A" + str(row_count)]}
|
|
39
|
+
# 获取纯文本内容
|
|
40
|
+
test = LarkdocsClient().get_plaintextcontent(json_str, spreadsheet_token, sheet_id)
|
|
41
|
+
test = json.loads(test)
|
|
42
|
+
userinput = test['data']['value_ranges'][0]['values']
|
|
43
|
+
print(f"表头为{userinput[0]}")
|
|
44
|
+
for i in range(1, row_count):
|
|
45
|
+
if userinput[i][0]:
|
|
46
|
+
if startAt == 0:
|
|
47
|
+
startAt = int(time.time())
|
|
48
|
+
# 创建会话
|
|
49
|
+
seseion_id = AilyLarkClient().create_ailysession(tenant_access_token)
|
|
50
|
+
if not seseion_id:
|
|
51
|
+
raise ValueError("未能成功创建会话")
|
|
52
|
+
# 创建消息
|
|
53
|
+
message_id = AilyLarkClient().create_ailysessionaily_message(tenant_access_token, seseion_id,
|
|
54
|
+
userinput[i][0])
|
|
55
|
+
if not message_id:
|
|
56
|
+
raise ValueError("未能成功创建消息")
|
|
57
|
+
# 创建运行实例
|
|
58
|
+
runs = AilyLarkClient().create_ailysession_run(tenant_access_token, seseion_id)
|
|
59
|
+
#可不需等待运行实例创建完成
|
|
60
|
+
#if not runs:
|
|
61
|
+
# raise ValueError("未能成功创建运行实例")
|
|
62
|
+
time.sleep(1)
|
|
63
|
+
else:
|
|
64
|
+
return startAt, i
|
|
65
|
+
break
|
|
66
|
+
return startAt, row_count
|
|
67
|
+
break
|
|
68
|
+
except KeyError as ke:
|
|
69
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
70
|
+
return None, None
|
|
71
|
+
except json.JSONDecodeError as jde:
|
|
72
|
+
print(f"JSON 解析错误: {jde}")
|
|
73
|
+
return None, None
|
|
74
|
+
except ValueError as ve:
|
|
75
|
+
print(f"值错误: {ve}")
|
|
76
|
+
return None, None
|
|
77
|
+
except Exception as e:
|
|
78
|
+
print(f"发生未知错误: {e}")
|
|
79
|
+
return None, None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def get_conversationlogs1(startAt):
|
|
83
|
+
"""
|
|
84
|
+
对话ID 技能分发 用户输入
|
|
85
|
+
res_data = {
|
|
86
|
+
'intentID': 7485259579248705537,
|
|
87
|
+
'skillLabels': ["GUI 设备/配件申请"],
|
|
88
|
+
'userInput': "我要申请一个鼠标",
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
"""
|
|
92
|
+
data = webapiClient().get_intent_detail_list(startAt)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_conversationlogs(startAt, pageSize=10):
|
|
96
|
+
"""
|
|
97
|
+
对话ID 技能分发 用户输入
|
|
98
|
+
res_data = {
|
|
99
|
+
'intentID': 7485259579248705537,
|
|
100
|
+
'skillLabels': ["GUI 设备/配件申请"],
|
|
101
|
+
'userInput': "我要申请一个鼠标",
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
"""
|
|
105
|
+
try:
|
|
106
|
+
# 之前提到形参 'pageSize' 未填,这里假设默认值为 10,你可按需修改
|
|
107
|
+
data = webapiClient().get_intent_detail_list(startAt, pageSize=10)
|
|
108
|
+
return data
|
|
109
|
+
except KeyError as ke:
|
|
110
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
111
|
+
return None
|
|
112
|
+
except IndexError as ie:
|
|
113
|
+
print(f"IndexError 发生: 索引超出范围,错误详情: {ie}")
|
|
114
|
+
return None
|
|
115
|
+
except Exception as e:
|
|
116
|
+
print(f"发生未知错误: {e}")
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def write_reslut(data, Testsuitelink, title):
|
|
121
|
+
"""
|
|
122
|
+
写入表格
|
|
123
|
+
"""
|
|
124
|
+
try:
|
|
125
|
+
# 解析 spreadsheet_token
|
|
126
|
+
spreadsheet_token = Testsuitelink.split("/")[-1]
|
|
127
|
+
|
|
128
|
+
# 生成新工作表名称
|
|
129
|
+
new_sheet_title = f"{title}{datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')}"
|
|
130
|
+
sheetinfo = {"index": 0, "title": new_sheet_title}
|
|
131
|
+
|
|
132
|
+
# 创建新工作表
|
|
133
|
+
spreadsheet0 = LarkdocsClient().createsheets(spreadsheet_token, sheetinfo)
|
|
134
|
+
sheet_id = spreadsheet0['sheet_id']
|
|
135
|
+
|
|
136
|
+
# 准备表头数据
|
|
137
|
+
headers = list(data[0].keys())
|
|
138
|
+
header_data = [
|
|
139
|
+
{
|
|
140
|
+
"range": f"{sheet_id}!{chr(ord('A') + col)}1:{chr(ord('A') + col)}1",
|
|
141
|
+
"values": [[[{"text": {"text": header}, "type": "text"}]]]
|
|
142
|
+
}
|
|
143
|
+
for col, header in enumerate(headers)
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
# 写入表头
|
|
147
|
+
LarkdocsClient().writesheets(spreadsheet_token, sheet_id, {"value_ranges": header_data})
|
|
148
|
+
|
|
149
|
+
# 写入数据
|
|
150
|
+
for row, row_data in enumerate(data, start=1):
|
|
151
|
+
row_values = [
|
|
152
|
+
{
|
|
153
|
+
"range": f"{sheet_id}!{chr(ord('A') + col)}{row + 1}:{chr(ord('A') + col)}{row + 1}",
|
|
154
|
+
"values": [[[{"text": {"text": str(row_data[header])}, "type": "text"}]]]
|
|
155
|
+
}
|
|
156
|
+
for col, header in enumerate(headers)
|
|
157
|
+
]
|
|
158
|
+
LarkdocsClient().writesheets(spreadsheet_token, sheet_id, {"value_ranges": row_values})
|
|
159
|
+
|
|
160
|
+
return True
|
|
161
|
+
except KeyError as ke:
|
|
162
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
163
|
+
return False
|
|
164
|
+
except IndexError as ie:
|
|
165
|
+
print(f"IndexError 发生: 索引超出范围,错误详情: {ie}")
|
|
166
|
+
return False
|
|
167
|
+
except Exception as e:
|
|
168
|
+
print(f"发生未知错误: {e}")
|
|
169
|
+
return False
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
if __name__ == '__main__':
|
|
173
|
+
Testsuitelink = "https://bytedance.larkoffice.com/sheets/ZVzfsw4rMhkMF6tjtxmc4BdSnMb"
|
|
174
|
+
startAt, num = do_ai_auto(Testsuitelink)
|
|
175
|
+
data = webapiClient().get_intent_detail_list(startAt, num)
|
|
176
|
+
data_qqq = webapiClient().get_intent_detail_llm(data)
|
|
177
|
+
aaaa = write_reslut(data_qqq, Testsuitelink, "测试")
|