itam-assistant 0.1.4__py3-none-any.whl → 0.1.5__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/do_ai.py +5 -5
- itam_assistant/__init__.py +0 -0
- itam_assistant/ailyapp_client.py +129 -0
- itam_assistant/config.py +51 -0
- itam_assistant/do_ai.py +928 -0
- itam_assistant/intent_detail.py +289 -0
- itam_assistant/lark_client.py +159 -0
- itam_assistant/logger.py +53 -0
- itam_assistant/openapi.py +687 -0
- itam_assistant/test.py +1 -0
- {itam_assistant-0.1.4.dist-info → itam_assistant-0.1.5.dist-info}/METADATA +1 -1
- itam_assistant-0.1.5.dist-info/RECORD +28 -0
- itam_assistant-0.1.5.dist-info/top_level.txt +1 -0
- main/do_ai.py +3 -3
- itam_assistant-0.1.4.dist-info/RECORD +0 -19
- itam_assistant-0.1.4.dist-info/top_level.txt +0 -1
- {itam_assistant-0.1.4.dist-info → itam_assistant-0.1.5.dist-info}/WHEEL +0 -0
itam_assistant/do_ai.py
ADDED
|
@@ -0,0 +1,928 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import time
|
|
3
|
+
from itam_assistant.ailyapp_client import AilyLarkClient
|
|
4
|
+
from itam_assistant.lark_client import LarkdocsClient
|
|
5
|
+
from itam_assistant.intent_detail import *
|
|
6
|
+
from itam_assistant.openapi import *
|
|
7
|
+
import datetime
|
|
8
|
+
import copy
|
|
9
|
+
import os
|
|
10
|
+
import csv
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# 定义一个全局变量Client
|
|
14
|
+
# Testsuitelink = "https://bytedance.larkoffice.com/sheets/ZVzfsw4rMhkMF6tjtxmc4BdSnMb"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def do_ai_auto(Testk_data, clientinfo):
|
|
18
|
+
"""
|
|
19
|
+
自动化执行AI测试用例
|
|
20
|
+
"""
|
|
21
|
+
startAt = 0
|
|
22
|
+
try:
|
|
23
|
+
# 获取租户访问令牌
|
|
24
|
+
tenant_access_token = AilyLarkClient(clientinfo).get_tenant_access_token()
|
|
25
|
+
if not tenant_access_token:
|
|
26
|
+
raise ValueError("未能获取到有效的租户访问令牌")
|
|
27
|
+
# 判断Testsuitelink中是否包含https://
|
|
28
|
+
if "https://" in Testk_data:
|
|
29
|
+
|
|
30
|
+
# 通过文档链接获取spreadsheet_token
|
|
31
|
+
spreadsheet_token = Testk_data.split("/")[-1]
|
|
32
|
+
if not spreadsheet_token:
|
|
33
|
+
raise ValueError("未能从文档链接中提取到有效的spreadsheet_token")
|
|
34
|
+
# 读取表格用户输入
|
|
35
|
+
spreadsheet = LarkdocsClient().get_the_worksheet(spreadsheet_token)
|
|
36
|
+
if not spreadsheet:
|
|
37
|
+
raise ValueError("未能获取到有效的工作表数据")
|
|
38
|
+
for i in spreadsheet.sheets:
|
|
39
|
+
column_count = i.grid_properties.column_count
|
|
40
|
+
row_count = i.grid_properties.row_count
|
|
41
|
+
sheet_id = i.sheet_id
|
|
42
|
+
title = i.title
|
|
43
|
+
if title == "测试集":
|
|
44
|
+
# 构建JSON字符串
|
|
45
|
+
json_str = {"ranges": [sheet_id + "!A1:A" + str(row_count)]}
|
|
46
|
+
# 获取纯文本内容
|
|
47
|
+
test = LarkdocsClient().get_plaintextcontent(json_str, spreadsheet_token, sheet_id)
|
|
48
|
+
test = json.loads(test)
|
|
49
|
+
userinput = test['data']['value_ranges'][0]['values']
|
|
50
|
+
print(f"表头为{userinput[0]}")
|
|
51
|
+
for i in range(1, row_count):
|
|
52
|
+
if userinput[i][0]:
|
|
53
|
+
if startAt == 0:
|
|
54
|
+
startAt = int(time.time())
|
|
55
|
+
# 创建会话
|
|
56
|
+
seseion_id = AilyLarkClient(clientinfo).create_ailysession(tenant_access_token)
|
|
57
|
+
if not seseion_id:
|
|
58
|
+
raise ValueError("未能成功创建会话")
|
|
59
|
+
# 创建消息
|
|
60
|
+
message_id = AilyLarkClient(clientinfo).create_ailysessionaily_message(tenant_access_token,
|
|
61
|
+
seseion_id,
|
|
62
|
+
userinput[i][0])
|
|
63
|
+
if not message_id:
|
|
64
|
+
raise ValueError("未能成功创建消息")
|
|
65
|
+
# 创建运行实例
|
|
66
|
+
runs = AilyLarkClient(clientinfo).create_ailysession_run(tenant_access_token, seseion_id)
|
|
67
|
+
# 可不需等待运行实例创建完成
|
|
68
|
+
# if not runs:
|
|
69
|
+
# raise ValueError("未能成功创建运行实例")
|
|
70
|
+
time.sleep(5)
|
|
71
|
+
else:
|
|
72
|
+
return startAt, i
|
|
73
|
+
break
|
|
74
|
+
return startAt, row_count
|
|
75
|
+
break
|
|
76
|
+
elif Testk_data[0].get('ext'):
|
|
77
|
+
num = 0
|
|
78
|
+
for i in Testk_data:
|
|
79
|
+
aa = i['ext']['input']
|
|
80
|
+
if startAt == 0:
|
|
81
|
+
startAt = int(time.time())
|
|
82
|
+
# 创建会话
|
|
83
|
+
seseion_id = AilyLarkClient(clientinfo).create_ailysession(tenant_access_token)
|
|
84
|
+
time.sleep(10)
|
|
85
|
+
if not seseion_id:
|
|
86
|
+
raise ValueError("未能成功创建会话")
|
|
87
|
+
# 创建消息
|
|
88
|
+
message_id = AilyLarkClient(clientinfo).create_ailysessionaily_message(tenant_access_token, seseion_id,
|
|
89
|
+
aa)
|
|
90
|
+
time.sleep(5)
|
|
91
|
+
if not message_id:
|
|
92
|
+
raise ValueError("未能成功创建消息")
|
|
93
|
+
# 创建运行实例
|
|
94
|
+
runs = AilyLarkClient(clientinfo).create_ailysession_run(tenant_access_token, seseion_id)
|
|
95
|
+
time.sleep(5)
|
|
96
|
+
num = num + 1
|
|
97
|
+
return startAt, num
|
|
98
|
+
except KeyError as ke:
|
|
99
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
100
|
+
return None, None
|
|
101
|
+
except json.JSONDecodeError as jde:
|
|
102
|
+
print(f"JSON 解析错误: {jde}")
|
|
103
|
+
return None, None
|
|
104
|
+
except ValueError as ve:
|
|
105
|
+
print(f"值错误: {ve}")
|
|
106
|
+
return None, None
|
|
107
|
+
except Exception as e:
|
|
108
|
+
print(f"发生未知错误: {e}")
|
|
109
|
+
return None, None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def get_results(num,res):
|
|
113
|
+
"""
|
|
114
|
+
获取结果
|
|
115
|
+
"""
|
|
116
|
+
labels = []
|
|
117
|
+
a = len(res["body"]["Results"])
|
|
118
|
+
#判断res["body"]["Results"]的个数,如果大于num,则取num个值,小于num,则取res["body"]["Results"]的个数
|
|
119
|
+
if a > num:
|
|
120
|
+
num = num
|
|
121
|
+
else:
|
|
122
|
+
num = a
|
|
123
|
+
#提取res["body"]["Results"]的前num个值
|
|
124
|
+
res["body"]["Results"] = res["body"]["Results"][:num]
|
|
125
|
+
#遍历res["body"]["Results"]提取 name_zh、brand_zh、model_zh、specification_zh 并拼接
|
|
126
|
+
for i in range(0, num):
|
|
127
|
+
res["body"]["Results"][i]['Item']['sku_zh'] = res["body"]["Results"][i]['Item']['name_zh'] + " " + res["body"]["Results"][i]['Item']['brand_zh'] + " " + res["body"]["Results"][i]['Item']['model_zh'] + " " + res["body"]["Results"][i]['Item']['specification_zh']
|
|
128
|
+
label = {"label" :res["body"]["Results"][i]['Item']['sku_zh'], "score" : res["body"]["Results"][i]['Score']}
|
|
129
|
+
labels.append(copy.deepcopy(label))
|
|
130
|
+
return labels
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def do_waterlevellineres_list(res, info):
|
|
135
|
+
"""
|
|
136
|
+
获取结果,并组装水位线info
|
|
137
|
+
"""
|
|
138
|
+
if res == '':
|
|
139
|
+
info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
140
|
+
info['rt'] = False
|
|
141
|
+
return info
|
|
142
|
+
|
|
143
|
+
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
144
|
+
if res["body"]["Results"]:
|
|
145
|
+
info['output']['用户输入/output']='log_id:'+res['log_id']
|
|
146
|
+
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
147
|
+
if len(res["body"]["Results"]) > 0:
|
|
148
|
+
for j in range(len(res["body"]["Results"])):
|
|
149
|
+
aaa = {'label': res["body"]["Results"][j]['Item']['name_zh']+"&"+res["body"]["Results"][j]['Item']['brand_zh']+"&"+res["body"]["Results"][j]['Item']['model_zh']+"&"+res["body"]["Results"][j]['Item']['specification_zh'],
|
|
150
|
+
'score': res["body"]["Results"][j]['Score']}
|
|
151
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
152
|
+
# 判断label0和label1是否为空,为空则:label默认2级
|
|
153
|
+
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
154
|
+
if info['exp'][0]['label'] == info['label'][0]['label'] and info['exp'][1]['label'] == info['label'][1][
|
|
155
|
+
'label'] and info['exp'][0]['score'] <= info['label'][0]['score'] and info['exp'][1]['score'] <= \
|
|
156
|
+
info['label'][1]['score']:
|
|
157
|
+
info['rt'] = True
|
|
158
|
+
else:
|
|
159
|
+
info['rt'] = False
|
|
160
|
+
|
|
161
|
+
else:
|
|
162
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
163
|
+
info['rt'] = False
|
|
164
|
+
|
|
165
|
+
return info
|
|
166
|
+
|
|
167
|
+
def do_waterlevellineres_listv2(res, info):
|
|
168
|
+
"""
|
|
169
|
+
获取结果,并组装水位线info
|
|
170
|
+
"""
|
|
171
|
+
if res == '':
|
|
172
|
+
info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
173
|
+
info['rt'] = False
|
|
174
|
+
return info
|
|
175
|
+
reslist = res["body"]["Results"]
|
|
176
|
+
info['output']['用户输入/output'] = 'log_id:' + res.get('log_id') or res.get('requestId')
|
|
177
|
+
if reslist:
|
|
178
|
+
#取所有结果并追加到info['label']
|
|
179
|
+
info['label'] = []
|
|
180
|
+
if len(reslist) > 0:
|
|
181
|
+
for j in range(len(reslist)):
|
|
182
|
+
aaa = {'label': reslist[j]['Item']['name_zh'],
|
|
183
|
+
'score': reslist[j]['Score'],
|
|
184
|
+
'info':reslist[j]['Item']['name_zh']+"&"+reslist[j]['Item']['brand_zh']+"&"+reslist[j]['Item']['model_zh']+"&"+reslist[j]['Item']['specification_zh'],}
|
|
185
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
186
|
+
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
187
|
+
for a in range(len(info['exp'])):
|
|
188
|
+
if info['exp'][a]['label']== info['label'][a]['label']:
|
|
189
|
+
info['rt'] = True
|
|
190
|
+
else:
|
|
191
|
+
info['rt'] = False
|
|
192
|
+
break
|
|
193
|
+
else:
|
|
194
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
195
|
+
info['rt'] = False
|
|
196
|
+
|
|
197
|
+
return info
|
|
198
|
+
|
|
199
|
+
def do_waterlevellineres_listassetspu(res, info,hardtype):
|
|
200
|
+
"""
|
|
201
|
+
获取结果,并组装水位线info
|
|
202
|
+
"""
|
|
203
|
+
if res == '':
|
|
204
|
+
info['label'] = [{'label': '', 'score': 0}]
|
|
205
|
+
info['rt'] = False
|
|
206
|
+
return info
|
|
207
|
+
if res["data"].get("AiBorrowAndUseResponseList") == None:
|
|
208
|
+
info['label'] = [{'label': '', 'score': 0},{'label': '', 'score': 0.8}]
|
|
209
|
+
info['rt'] = False
|
|
210
|
+
if info['exp']==[]:
|
|
211
|
+
info['rt'] = True
|
|
212
|
+
return info
|
|
213
|
+
reslist=res["data"]["AiBorrowAndUseResponseList"]
|
|
214
|
+
info['output']['用户输入/output']='requestId:'+res['requestId']
|
|
215
|
+
aaa ={}
|
|
216
|
+
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
217
|
+
if reslist:
|
|
218
|
+
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
219
|
+
if len(reslist) > 0:
|
|
220
|
+
for j in range(len(reslist)):
|
|
221
|
+
if hardtype==2:
|
|
222
|
+
aaa = {'label': reslist[j]['AccessoryModelScope']['AccessoryModelInfo']['Name']['ValueZh'],
|
|
223
|
+
'score': reslist[j]['Score']}
|
|
224
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
225
|
+
if hardtype == 1:
|
|
226
|
+
aaa = {'label': reslist[j]['AssetModelScope']['SpuNameZh'] or reslist[j]['AssetModelScope']['NameZh']+reslist[j]['AssetModelScope']['ModelZh']+reslist[j]['AssetModelScope']['SpecificationZh'],
|
|
227
|
+
'score': reslist[j]['Score']}
|
|
228
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
229
|
+
# 判断label0和label1是否为空,为空则:label默认2级
|
|
230
|
+
for a in range(len(info['exp'])):
|
|
231
|
+
if info['exp'][a]['label'] == info['label'][a]['label']:
|
|
232
|
+
info['rt'] = True
|
|
233
|
+
else:
|
|
234
|
+
info['rt'] = False
|
|
235
|
+
break
|
|
236
|
+
else:
|
|
237
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
238
|
+
info['rt'] = False
|
|
239
|
+
return info
|
|
240
|
+
|
|
241
|
+
def do_waterlevellineres_listassetspu_pre(res, info,hardtype):
|
|
242
|
+
"""
|
|
243
|
+
获取结果,并组装水位线info
|
|
244
|
+
"""
|
|
245
|
+
if res == '':
|
|
246
|
+
info['label'] = [{'label': '', 'score': 0}]
|
|
247
|
+
info['rt'] = False
|
|
248
|
+
return info
|
|
249
|
+
if res.get("body") == None:
|
|
250
|
+
info['label'] = [{'label': '', 'score': 0},{'label': '', 'score': 0.8}]
|
|
251
|
+
info['rt'] = False
|
|
252
|
+
if info['exp'][0]['label']=='':
|
|
253
|
+
info['rt'] = True
|
|
254
|
+
return info
|
|
255
|
+
reslist=res["body"]
|
|
256
|
+
aaa ={}
|
|
257
|
+
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
258
|
+
if reslist:
|
|
259
|
+
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
260
|
+
if len(reslist) > 0:
|
|
261
|
+
for j in range(len(reslist)):
|
|
262
|
+
if hardtype==2:
|
|
263
|
+
aaa = {'label': reslist[j]['AccessoryModelScope']['AccessoryModelInfo']['Name']['ValueZh'],
|
|
264
|
+
'score': reslist[j]['Score']}
|
|
265
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
266
|
+
if hardtype == 1:
|
|
267
|
+
aaa = {'label': reslist[j]['Item']['name_zh']+reslist[j]['Item']['brand_zh']+reslist[j]['Item']['model_zh']+reslist[j]['Item']['specification_zh'],
|
|
268
|
+
'score': reslist[j]['Score']}
|
|
269
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
270
|
+
# 判断label0和label1是否为空,为空则:label默认2级
|
|
271
|
+
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
272
|
+
if info['exp'][0]['label'] == info['label'][0]['label'] and info['exp'][1]['label'] == info['label'][1][
|
|
273
|
+
'label'] and info['exp'][0]['score'] <= info['label'][0]['score'] and info['exp'][1]['score'] <= \
|
|
274
|
+
info['label'][1]['score']:
|
|
275
|
+
info['rt'] = True
|
|
276
|
+
else:
|
|
277
|
+
info['rt'] = False
|
|
278
|
+
else:
|
|
279
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
280
|
+
info['rt'] = False
|
|
281
|
+
return info
|
|
282
|
+
|
|
283
|
+
def do_waterlevellineres_sr(res, info,hardtype):
|
|
284
|
+
"""
|
|
285
|
+
获取结果,并组装水位线info
|
|
286
|
+
"""
|
|
287
|
+
if res == '':
|
|
288
|
+
info['label'] = [{'label': '', 'score': 0}]
|
|
289
|
+
info['rt'] = False
|
|
290
|
+
return info
|
|
291
|
+
if res["data"].get("AiBorrowAndUseResponseList") == None:
|
|
292
|
+
info['label'] = [{'label': '', 'score': 0},{'label': '', 'score': 0.8}]
|
|
293
|
+
info['rt'] = False
|
|
294
|
+
if info['exp'][0]['label']=='':
|
|
295
|
+
info['rt'] = True
|
|
296
|
+
return info
|
|
297
|
+
reslist=res["data"]["AssetModels"]
|
|
298
|
+
aaa ={}
|
|
299
|
+
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
300
|
+
if reslist:
|
|
301
|
+
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
302
|
+
if len(reslist) > 0:
|
|
303
|
+
for j in range(len(reslist)):
|
|
304
|
+
if hardtype==2:
|
|
305
|
+
aaa = {'label': reslist[j]['AccessoryModelScope']['AccessoryModelInfo']['Name']['ValueZh'],
|
|
306
|
+
'score': reslist[j]['Score']}
|
|
307
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
308
|
+
if hardtype == 1:
|
|
309
|
+
aaa = {'label': reslist[j]['SpuNameZh'] or reslist[j]['NameZh']+reslist[j]['ModelZh']+reslist[j]['SpecificationZh'],
|
|
310
|
+
'score': 0.5}
|
|
311
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
312
|
+
# 判断label0和label1是否为空,为空则:label默认2级
|
|
313
|
+
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
314
|
+
if info['exp'][0]['label'] == info['label'][0]['label'] and info['exp'][1]['label'] == info['label'][1][
|
|
315
|
+
'label'] and info['exp'][0]['score'] <= info['label'][0]['score'] and info['exp'][1]['score'] <= \
|
|
316
|
+
info['label'][1]['score']:
|
|
317
|
+
info['rt'] = True
|
|
318
|
+
else:
|
|
319
|
+
info['rt'] = False
|
|
320
|
+
else:
|
|
321
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
322
|
+
info['rt'] = False
|
|
323
|
+
return info
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def do_metricsevaluation_list(collections,data,score_threshold):
|
|
327
|
+
"""
|
|
328
|
+
指标 评测
|
|
329
|
+
"""
|
|
330
|
+
info = {
|
|
331
|
+
"input": {
|
|
332
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
333
|
+
},
|
|
334
|
+
"output": {
|
|
335
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
336
|
+
},
|
|
337
|
+
"rt": True,
|
|
338
|
+
"label": [{"label": "测试"}, {"label": "测试"}],
|
|
339
|
+
"exp": [{"label": "测试"}, {"label": "测试" }],
|
|
340
|
+
"artificial": []
|
|
341
|
+
}
|
|
342
|
+
info_list = []
|
|
343
|
+
businessscenario = []
|
|
344
|
+
for i in collections:
|
|
345
|
+
for j in data:
|
|
346
|
+
if i['content'] == j['用户输入/userInput']:
|
|
347
|
+
info = {
|
|
348
|
+
"input": {},
|
|
349
|
+
"output": {},
|
|
350
|
+
"rt": False,
|
|
351
|
+
"label": [{"label": "测试"}, {"label": "测试"}],
|
|
352
|
+
"exp": [{"label": "测试",}, {"label": "测试"}],
|
|
353
|
+
"artificial": []
|
|
354
|
+
}
|
|
355
|
+
info['input']['用户输入/userInput'] = i['ext']['output']
|
|
356
|
+
info['output']['用户输入/output'] = "对话id:"+j['对话日志/intentID']+" 对话内容:"+j['用户输入/userInput']
|
|
357
|
+
if i['ext']['BPO标注-AP-分发技能'] != '' and i['ext']['BPO标注-AP-分发技能'] in j['分发技能/skill'][0]:
|
|
358
|
+
info['rt'] = True
|
|
359
|
+
info['label'] = [{'label': j['分发技能/skill'][0]}]
|
|
360
|
+
info['exp'] = [{'label': j['分发技能/skill'][0]}]
|
|
361
|
+
info['artificial'] = info['exp']
|
|
362
|
+
else:
|
|
363
|
+
info['rt'] = False
|
|
364
|
+
info['label'] = [{'label': j['分发技能/skill'][0]}]
|
|
365
|
+
info['exp'] = [{'label': i['ext']['BPO标注-AP-分发技能']}]
|
|
366
|
+
info['artificial'] = info['exp']
|
|
367
|
+
if i['ext']['BPO标注-AP-分发技能'] not in businessscenario:
|
|
368
|
+
businessscenario.append(i['ext']['BPO标注-AP-分发技能'])
|
|
369
|
+
#将data中的j删除
|
|
370
|
+
data.remove(j)
|
|
371
|
+
break
|
|
372
|
+
info_list.append(copy.deepcopy(info))
|
|
373
|
+
return info_list,businessscenario
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def do_scenereview_list(collections,data,score_threshold):
|
|
377
|
+
"""
|
|
378
|
+
场景 评测 提取关键词
|
|
379
|
+
"""
|
|
380
|
+
score_threshold=0.8
|
|
381
|
+
info = {
|
|
382
|
+
"input": {
|
|
383
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
384
|
+
},
|
|
385
|
+
"output": {
|
|
386
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
387
|
+
},
|
|
388
|
+
"rt": True,
|
|
389
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
390
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8 }],
|
|
391
|
+
"artificial": []
|
|
392
|
+
}
|
|
393
|
+
info_list = []
|
|
394
|
+
for i in collections:
|
|
395
|
+
for j in data:
|
|
396
|
+
if i['content'] == j['用户输入/userInput']:
|
|
397
|
+
info['input']['用户输入/userInput'] = i['ext']['output']
|
|
398
|
+
info['output']['用户输入/output'] = j['用户输入/userInput']
|
|
399
|
+
if i['ext']['BPO标注-AP-资产名称'] == j['llm关键词']:
|
|
400
|
+
info['rt'] = True
|
|
401
|
+
info['label'] = [{'label': str(j['llm关键词']), 'score': score_threshold}]
|
|
402
|
+
else:
|
|
403
|
+
info['rt'] = False
|
|
404
|
+
info['label'] = [{'label': str(i['ext']['BPO标注-AP-资产名称']), 'score': score_threshold}]
|
|
405
|
+
info['exp'] = [{'label': str(i['ext']['BPO标注-AP-资产名称']), 'score': score_threshold}]
|
|
406
|
+
info['artificial'] = info['exp']
|
|
407
|
+
info_list.append(copy.deepcopy(info))
|
|
408
|
+
return info_list
|
|
409
|
+
|
|
410
|
+
def do_waterlevelline_autotest(collections, clientinfo, score_threshold):
|
|
411
|
+
"""
|
|
412
|
+
水位线评测- 返回 符合报告模式的结果
|
|
413
|
+
"""
|
|
414
|
+
keywprd= []
|
|
415
|
+
info_list = []
|
|
416
|
+
info = {
|
|
417
|
+
"input": {
|
|
418
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
419
|
+
},
|
|
420
|
+
"output": {
|
|
421
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
422
|
+
},
|
|
423
|
+
"rt": True,
|
|
424
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
425
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
426
|
+
}],
|
|
427
|
+
"artificial": []
|
|
428
|
+
}
|
|
429
|
+
a =0
|
|
430
|
+
for i in collections:
|
|
431
|
+
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
432
|
+
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
433
|
+
info['exp'] = []
|
|
434
|
+
for j in [i['ext']['BPO标注-AP-资产型号'], i['ext'].get('BPO标注-AP-资产型号1'),i['ext'].get('BPO标注-AP-资产型号2'),i['ext'].get('BPO标注-AP-资产型号3'),i['ext'].get('BPO标注-AP-资产型号4'),i['ext'].get('BPO标注-AP-资产型号5'),i['ext'].get('BPO标注-AP-资产型号6'),i['ext'].get('BPO标注-AP-资产型号7'),i['ext'].get('BPO标注-AP-资产型号8'),i['ext'].get('BPO标注-AP-资产型号9'),i['ext'].get('BPO标注-AP-资产型号10')]:
|
|
435
|
+
if j:
|
|
436
|
+
info['exp'].append({'label': j, 'score': score_threshold})
|
|
437
|
+
#判断i['ext']['BPO标注-AP-资产型号']是否为空,为空就不用读取,不为空就读取
|
|
438
|
+
if i['ext']['BPO标注-AP-资产型号']:
|
|
439
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
440
|
+
try:
|
|
441
|
+
if isinstance(asset_name, str):
|
|
442
|
+
asset_name = json.loads(asset_name)
|
|
443
|
+
except json.JSONDecodeError:
|
|
444
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
445
|
+
pass
|
|
446
|
+
info['artificial'] = info['exp']
|
|
447
|
+
if i['ext']['BPO标注-AP-资产名称']:
|
|
448
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
449
|
+
try:
|
|
450
|
+
if isinstance(asset_name, str):
|
|
451
|
+
asset_name = json.loads(asset_name)
|
|
452
|
+
except json.JSONDecodeError:
|
|
453
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
454
|
+
pass
|
|
455
|
+
if "软件申请" in i['ext']['BPO标注-AP-分发技能']:
|
|
456
|
+
keywprd = software_asset_sku_structure(asset_name)
|
|
457
|
+
res = json.loads(get_query_vector(keywprd, clientinfo))
|
|
458
|
+
if "设备/配件申请" in i['ext']['BPO标注-AP-分发技能']:
|
|
459
|
+
#keywprd = equipmentrequest_structure(asset_name, i['ext']['asset_type'])
|
|
460
|
+
keywprd = {
|
|
461
|
+
"From": 0,
|
|
462
|
+
"Size": 10,
|
|
463
|
+
"MinScore": 0.7,
|
|
464
|
+
"AssetModelFieldsWithAnd": [
|
|
465
|
+
{
|
|
466
|
+
"FieldName": "vec_search",
|
|
467
|
+
"FieldType": "knn",
|
|
468
|
+
"QueryValue": [
|
|
469
|
+
asset_name
|
|
470
|
+
]
|
|
471
|
+
}
|
|
472
|
+
],
|
|
473
|
+
"SPUIDs": None,
|
|
474
|
+
"AssetModelBizTypes": [
|
|
475
|
+
"asset_sku"
|
|
476
|
+
]
|
|
477
|
+
}
|
|
478
|
+
res = json.loads(get_query_vector(keywprd, clientinfo))
|
|
479
|
+
#res = get_by_AssetModelBizTypes(keywprd,res0)
|
|
480
|
+
if "设备/配件退还" in i['ext']['BPO标注-AP-分发技能']:
|
|
481
|
+
keywprd = equipmentreturn_structure0(asset_name, i['ext']['asset_type'])
|
|
482
|
+
res0 = json.loads(get_query_vector(keywprd, clientinfo))
|
|
483
|
+
res = get_by_AssetModelBizTypes(keywprd, res0)
|
|
484
|
+
else:
|
|
485
|
+
res = ""
|
|
486
|
+
infoout = do_waterlevellineres_listv2(res, info)
|
|
487
|
+
info_list.append(copy.deepcopy(infoout))
|
|
488
|
+
a = a+1
|
|
489
|
+
print("这是"+str(a))
|
|
490
|
+
bbb = a
|
|
491
|
+
return info_list
|
|
492
|
+
|
|
493
|
+
def do_waterlevelline_autotest_aseetspu(collections, clientinfo, score_threshold):
|
|
494
|
+
"""
|
|
495
|
+
水位线评测- 返回 符合报告模式的结果
|
|
496
|
+
"""
|
|
497
|
+
keywprd= []
|
|
498
|
+
info_list = []
|
|
499
|
+
info = {
|
|
500
|
+
"input": {
|
|
501
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
502
|
+
},
|
|
503
|
+
"output": {
|
|
504
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
505
|
+
},
|
|
506
|
+
"rt": True,
|
|
507
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
508
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
509
|
+
}],
|
|
510
|
+
"artificial": []
|
|
511
|
+
}
|
|
512
|
+
a =0
|
|
513
|
+
for i in collections:
|
|
514
|
+
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
515
|
+
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
516
|
+
info['exp'] = []
|
|
517
|
+
for j in [i['ext']['BPO标注-AP-资产型号'], i['ext'].get('BPO标注-AP-资产型号1'),
|
|
518
|
+
i['ext'].get('BPO标注-AP-资产型号2'), i['ext'].get('BPO标注-AP-资产型号3'),
|
|
519
|
+
i['ext'].get('BPO标注-AP-资产型号4'), i['ext'].get('BPO标注-AP-资产型号5'),
|
|
520
|
+
i['ext'].get('BPO标注-AP-资产型号6'), i['ext'].get('BPO标注-AP-资产型号7'),
|
|
521
|
+
i['ext'].get('BPO标注-AP-资产型号8'), i['ext'].get('BPO标注-AP-资产型号9'),
|
|
522
|
+
i['ext'].get('BPO标注-AP-资产型号10')]:
|
|
523
|
+
if j:
|
|
524
|
+
info['exp'].append({'label': j, 'score': score_threshold})
|
|
525
|
+
info['artificial'] = info['exp']
|
|
526
|
+
info['label']=[]
|
|
527
|
+
if i['ext']['BPO标注-AP-资产名称']:
|
|
528
|
+
if "设备" in i['ext']['BPO标注-AP-分发技能'] or "配件" in i['ext']['BPO标注-AP-分发技能']:
|
|
529
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
530
|
+
try:
|
|
531
|
+
# 尝试将其解析为 JSON 对象
|
|
532
|
+
if isinstance(asset_name, str):
|
|
533
|
+
asset_name0 = json.loads(asset_name)
|
|
534
|
+
asset_name = asset_name0['asset_name']
|
|
535
|
+
except json.JSONDecodeError:
|
|
536
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
537
|
+
pass
|
|
538
|
+
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
539
|
+
if i['ext']['BPO标注-AP-资产类型'] == "设备":
|
|
540
|
+
hardtype = 1
|
|
541
|
+
elif i['ext']['BPO标注-AP-资产类型'] == "配件" or i['ext']['BPO标注-AP-资产类型'] == '2.0' :
|
|
542
|
+
hardtype = 2
|
|
543
|
+
res = GetBestMatchItemonline(key,hardtype,clientinfo)
|
|
544
|
+
else:
|
|
545
|
+
res = ""
|
|
546
|
+
infoout = do_waterlevellineres_listassetspu(res, info,hardtype)
|
|
547
|
+
info_list.append(copy.deepcopy(infoout))
|
|
548
|
+
a = a+1
|
|
549
|
+
print("这是"+str(a))
|
|
550
|
+
bbb = a
|
|
551
|
+
return info_list
|
|
552
|
+
|
|
553
|
+
def do_waterlevelline_autotest_aseetspu_old(collections, clientinfo, score_threshold):
|
|
554
|
+
"""
|
|
555
|
+
水位线评测- 返回 符合报告模式的结果
|
|
556
|
+
"""
|
|
557
|
+
keywprd= []
|
|
558
|
+
info_list = []
|
|
559
|
+
info = {
|
|
560
|
+
"input": {
|
|
561
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
562
|
+
},
|
|
563
|
+
"output": {
|
|
564
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
565
|
+
},
|
|
566
|
+
"rt": True,
|
|
567
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
568
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
569
|
+
}],
|
|
570
|
+
"artificial": []
|
|
571
|
+
}
|
|
572
|
+
a =0
|
|
573
|
+
for i in collections:
|
|
574
|
+
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
575
|
+
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
576
|
+
info['exp'] = [
|
|
577
|
+
{'label': i['ext']['BPO标注-AP-资产型号'], 'score': score_threshold},
|
|
578
|
+
{'label': i['ext'].get('BPO标注-AP-资产型号1', ''), 'score': score_threshold}]
|
|
579
|
+
info['artificial'] = info['exp']
|
|
580
|
+
info['label']=[]
|
|
581
|
+
if i['ext']['BPO标注-AP-资产名称']:
|
|
582
|
+
if "设备" in i['ext']['BPO标注-AP-分发技能'] or "配件" in i['ext']['BPO标注-AP-分发技能']:
|
|
583
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
584
|
+
asset_name = i['ext']['BPO标注-AP-资产类型']
|
|
585
|
+
try:
|
|
586
|
+
# 尝试将其解析为 JSON 对象
|
|
587
|
+
if isinstance(asset_name, str):
|
|
588
|
+
asset_name = json.loads(asset_name)
|
|
589
|
+
except json.JSONDecodeError:
|
|
590
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
591
|
+
pass
|
|
592
|
+
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
593
|
+
if i['ext']['BPO标注-AP-资产型号'] == "设备":
|
|
594
|
+
hardtype = 1
|
|
595
|
+
elif i['ext']['BPO标注-AP-资产型号'] == "配件" :
|
|
596
|
+
hardtype = 2
|
|
597
|
+
res = GetBestMatchItemonline_old(key,hardtype,clientinfo)
|
|
598
|
+
else:
|
|
599
|
+
res = ""
|
|
600
|
+
infoout = do_waterlevellineres_listassetspu(res, info,hardtype)
|
|
601
|
+
info_list.append(copy.deepcopy(infoout))
|
|
602
|
+
a = a+1
|
|
603
|
+
print("这是"+str(a))
|
|
604
|
+
bbb = a
|
|
605
|
+
return info_list
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def do_waterlevelline_autotest_aseetspu_pre(collections, clientinfo, score_threshold):
|
|
609
|
+
"""
|
|
610
|
+
水位线评测- 返回 符合报告模式的结果
|
|
611
|
+
"""
|
|
612
|
+
keywprd= []
|
|
613
|
+
info_list = []
|
|
614
|
+
info = {
|
|
615
|
+
"input": {
|
|
616
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
617
|
+
},
|
|
618
|
+
"output": {
|
|
619
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
620
|
+
},
|
|
621
|
+
"rt": True,
|
|
622
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
623
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
624
|
+
}],
|
|
625
|
+
"artificial": []
|
|
626
|
+
}
|
|
627
|
+
a =0
|
|
628
|
+
for i in collections:
|
|
629
|
+
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
630
|
+
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
631
|
+
info['exp'] = [
|
|
632
|
+
{'label': i['ext']['BPO标注-AP-资产型号'], 'score': score_threshold},
|
|
633
|
+
{'label': i['ext'].get('BPO标注-AP-资产型号1', ''), 'score': score_threshold}]
|
|
634
|
+
info['artificial'] = info['exp']
|
|
635
|
+
info['label']=[]
|
|
636
|
+
if i['ext']['BPO标注-AP-资产名称']:
|
|
637
|
+
if "设备" in i['ext']['BPO标注-AP-分发技能'] or "配件" in i['ext']['BPO标注-AP-分发技能']:
|
|
638
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
639
|
+
asset_name = i['ext']['BPO标注-AP-资产类型']
|
|
640
|
+
try:
|
|
641
|
+
# 尝试将其解析为 JSON 对象
|
|
642
|
+
if isinstance(asset_name, str):
|
|
643
|
+
asset_name = json.loads(asset_name)
|
|
644
|
+
except json.JSONDecodeError:
|
|
645
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
646
|
+
pass
|
|
647
|
+
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
648
|
+
if i['ext']['BPO标注-AP-资产型号'] == "设备":
|
|
649
|
+
hardtype = 1
|
|
650
|
+
elif i['ext']['BPO标注-AP-资产型号'] == "配件" :
|
|
651
|
+
hardtype = 2
|
|
652
|
+
res = test_hardware_match(key,hardtype,clientinfo)
|
|
653
|
+
else:
|
|
654
|
+
res = ""
|
|
655
|
+
infoout = do_waterlevellineres_listassetspu_pre(res, info,hardtype)
|
|
656
|
+
info_list.append(copy.deepcopy(infoout))
|
|
657
|
+
a = a+1
|
|
658
|
+
print("这是"+str(a))
|
|
659
|
+
bbb = a
|
|
660
|
+
return info_list
|
|
661
|
+
|
|
662
|
+
def do_waterlevelline_autotest_search(collections, clientinfo, score_threshold):
|
|
663
|
+
"""
|
|
664
|
+
水位线评测- 返回 符合报告模式的结果
|
|
665
|
+
"""
|
|
666
|
+
keywprd= []
|
|
667
|
+
info_list = []
|
|
668
|
+
info = {
|
|
669
|
+
"input": {
|
|
670
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
671
|
+
},
|
|
672
|
+
"output": {
|
|
673
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
674
|
+
},
|
|
675
|
+
"rt": True,
|
|
676
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
677
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
678
|
+
}],
|
|
679
|
+
"artificial": []
|
|
680
|
+
}
|
|
681
|
+
a =0
|
|
682
|
+
for i in collections:
|
|
683
|
+
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
684
|
+
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
685
|
+
info['exp'] = [
|
|
686
|
+
{'label': i['ext']['BPO标注-AP-资产型号'], 'score': score_threshold},
|
|
687
|
+
{'label': i['ext'].get('BPO标注-AP-资产型号1', ''), 'score': score_threshold}]
|
|
688
|
+
info['artificial'] = info['exp']
|
|
689
|
+
info['label']=[]
|
|
690
|
+
if i['ext']['BPO标注-AP-资产名称']:
|
|
691
|
+
if "设备" in i['ext']['BPO标注-AP-分发技能'] or "配件" in i['ext']['BPO标注-AP-分发技能']:
|
|
692
|
+
asset_name = i['ext']['BPO标注-AP-资产名称']
|
|
693
|
+
asset_name = i['ext']['BPO标注-AP-资产类型']
|
|
694
|
+
try:
|
|
695
|
+
# 尝试将其解析为 JSON 对象
|
|
696
|
+
if isinstance(asset_name, str):
|
|
697
|
+
asset_name = json.loads(asset_name)
|
|
698
|
+
except json.JSONDecodeError:
|
|
699
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
700
|
+
pass
|
|
701
|
+
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
702
|
+
if i['ext']['BPO标注-AP-资产型号'] == "设备":
|
|
703
|
+
hardtype = 1
|
|
704
|
+
elif i['ext']['BPO标注-AP-资产型号'] == "配件" :
|
|
705
|
+
hardtype = 2
|
|
706
|
+
res = searchListAssetModelScope(key,hardtype,clientinfo)
|
|
707
|
+
else:
|
|
708
|
+
res = ""
|
|
709
|
+
infoout = do_waterlevellineres_sr(res, info,hardtype)
|
|
710
|
+
info_list.append(copy.deepcopy(infoout))
|
|
711
|
+
a = a+1
|
|
712
|
+
print("这是"+str(a))
|
|
713
|
+
bbb = a
|
|
714
|
+
return info_list
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def do_waterlevelline_autotest_SoftwareApplyRecommendList(collections, clientinfo, score_threshold):
|
|
718
|
+
"""
|
|
719
|
+
水位线评测- 返回 符合报告模式的结果
|
|
720
|
+
"""
|
|
721
|
+
keywprd= []
|
|
722
|
+
info_list = []
|
|
723
|
+
info = {
|
|
724
|
+
"input": {
|
|
725
|
+
"用户输入/userInput": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
726
|
+
},
|
|
727
|
+
"output": {
|
|
728
|
+
"用户输入/output": "我要申请软件,名字叫:ai_xzh_all_restricted_software完全受限软件"
|
|
729
|
+
},
|
|
730
|
+
"rt": True,
|
|
731
|
+
"label": [{"label": "GUI 软件申请", "score": 0.6}, {"label": "软件申请", "score": 0.5}],
|
|
732
|
+
"exp": [{"label": "GUI 软件申请", " score": 0.9}, {"label": "软件申请", "score": 0.8
|
|
733
|
+
}],
|
|
734
|
+
"artificial": []
|
|
735
|
+
}
|
|
736
|
+
a =0
|
|
737
|
+
for i in collections:
|
|
738
|
+
info['input']['用户输入/userInput'] = i['ext'].get('BP标注-AP-资产名称') or i['ext'].get('BPO标注-AP-资产名称')
|
|
739
|
+
info['output']['用户输入/output'] = i['ext']['BP标注-AP-资产名称']
|
|
740
|
+
info['exp'] = [
|
|
741
|
+
{'label': i['ext']['BP标注-AP-资产名称'], 'score': score_threshold},
|
|
742
|
+
{'label': i['ext'].get('BP标注-AP-资产型号1', ''), 'score': score_threshold}]
|
|
743
|
+
info['artificial'] = info['exp']
|
|
744
|
+
info['label']=[]
|
|
745
|
+
if i['ext']['BP标注-AP-资产名称']:
|
|
746
|
+
if "软件" in i['ext']['BP标注-AP-分发技能']:
|
|
747
|
+
asset_name = i['ext']['BP标注-AP-资产名称']
|
|
748
|
+
try:
|
|
749
|
+
# 尝试将其解析为 JSON 对象
|
|
750
|
+
if isinstance(asset_name, str):
|
|
751
|
+
asset_name = json.loads(asset_name)
|
|
752
|
+
except json.JSONDecodeError:
|
|
753
|
+
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
754
|
+
pass
|
|
755
|
+
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
756
|
+
res = SoftwareApplyGetBestMatchItem(key,clientinfo)
|
|
757
|
+
else:
|
|
758
|
+
res = ""
|
|
759
|
+
infoout = do_waterlevellineres_software(res, info)
|
|
760
|
+
info_list.append(copy.deepcopy(infoout))
|
|
761
|
+
a = a+1
|
|
762
|
+
print("这是"+str(a))
|
|
763
|
+
bbb = a
|
|
764
|
+
return info_list
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
def do_waterlevellineres_software(res, info):
|
|
768
|
+
"""
|
|
769
|
+
获取结果,并组装水位线info
|
|
770
|
+
"""
|
|
771
|
+
if res == '':
|
|
772
|
+
info['label'] = [{'label': '', 'score': 0}]
|
|
773
|
+
info['rt'] = False
|
|
774
|
+
return info
|
|
775
|
+
if res["data"].get("SoftwareApplyRecommendList") == None:
|
|
776
|
+
info['label'] = [{'label': '', 'score': 0},{'label': '', 'score': 0.8}]
|
|
777
|
+
info['rt'] = False
|
|
778
|
+
if info['exp'][0]['label']=='':
|
|
779
|
+
info['rt'] = True
|
|
780
|
+
return info
|
|
781
|
+
reslist=res["data"]["SoftwareApplyRecommendList"]
|
|
782
|
+
aaa ={}
|
|
783
|
+
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
784
|
+
if reslist:
|
|
785
|
+
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
786
|
+
if len(reslist) > 0:
|
|
787
|
+
for j in range(len(reslist)):
|
|
788
|
+
aaa = {'label': reslist[j]['Data']['Name']['ValueZh'],
|
|
789
|
+
'score': reslist[j]['Score']}
|
|
790
|
+
info['label'].append(copy.deepcopy(aaa))
|
|
791
|
+
if info['exp'][0]['label'] == info['label'][0]['label'] and info['exp'][0]['score'] <= info['label'][0]['score']:
|
|
792
|
+
info['rt'] = True
|
|
793
|
+
else:
|
|
794
|
+
info['rt'] = False
|
|
795
|
+
else:
|
|
796
|
+
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
797
|
+
info['rt'] = False
|
|
798
|
+
return info
|
|
799
|
+
|
|
800
|
+
def get_conversationlogs1(startAt):
|
|
801
|
+
"""
|
|
802
|
+
对话ID 技能分发 用户输入
|
|
803
|
+
res_data = {
|
|
804
|
+
'intentID': 7485259579248705537,
|
|
805
|
+
'skillLabels': ["GUI 设备/配件申请"],
|
|
806
|
+
'userInput': "我要申请一个鼠标",
|
|
807
|
+
|
|
808
|
+
}
|
|
809
|
+
"""
|
|
810
|
+
data = webapiClient().get_intent_detail_list(startAt)
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def get_conversationlogs(startAt, pageSize=10):
|
|
814
|
+
"""
|
|
815
|
+
对话ID 技能分发 用户输入
|
|
816
|
+
res_data = {
|
|
817
|
+
'intentID': 7485259579248705537,
|
|
818
|
+
'skillLabels': ["GUI 设备/配件申请"],
|
|
819
|
+
'userInput': "我要申请一个鼠标",
|
|
820
|
+
|
|
821
|
+
}
|
|
822
|
+
"""
|
|
823
|
+
try:
|
|
824
|
+
# 之前提到形参 'pageSize' 未填,这里假设默认值为 10,你可按需修改
|
|
825
|
+
data = webapiClient().get_intent_detail_list(startAt, pageSize=10)
|
|
826
|
+
return data
|
|
827
|
+
except KeyError as ke:
|
|
828
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
829
|
+
return None
|
|
830
|
+
except IndexError as ie:
|
|
831
|
+
print(f"IndexError 发生: 索引超出范围,错误详情: {ie}")
|
|
832
|
+
return None
|
|
833
|
+
except Exception as e:
|
|
834
|
+
print(f"发生未知错误: {e}")
|
|
835
|
+
return None
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
def write_reslut(data, Testsuitelink, title):
|
|
839
|
+
"""
|
|
840
|
+
写入表格
|
|
841
|
+
"""
|
|
842
|
+
try:
|
|
843
|
+
# 解析 spreadsheet_token
|
|
844
|
+
spreadsheet_token = Testsuitelink.split("/")[-1]
|
|
845
|
+
|
|
846
|
+
# 生成新工作表名称
|
|
847
|
+
new_sheet_title = f"{title}{datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')}"
|
|
848
|
+
sheetinfo = {"index": 0, "title": new_sheet_title}
|
|
849
|
+
|
|
850
|
+
# 创建新工作表
|
|
851
|
+
spreadsheet0 = LarkdocsClient().createsheets(spreadsheet_token, sheetinfo)
|
|
852
|
+
sheet_id = spreadsheet0['sheet_id']
|
|
853
|
+
|
|
854
|
+
# 准备表头数据
|
|
855
|
+
headers = list(data[0].keys())
|
|
856
|
+
header_data = [
|
|
857
|
+
{
|
|
858
|
+
"range": f"{sheet_id}!{chr(ord('A') + col)}1:{chr(ord('A') + col)}1",
|
|
859
|
+
"values": [[[{"text": {"text": header}, "type": "text"}]]]
|
|
860
|
+
}
|
|
861
|
+
for col, header in enumerate(headers)
|
|
862
|
+
]
|
|
863
|
+
|
|
864
|
+
# 写入表头
|
|
865
|
+
LarkdocsClient().writesheets(spreadsheet_token, sheet_id, {"value_ranges": header_data})
|
|
866
|
+
|
|
867
|
+
# 写入数据
|
|
868
|
+
for row, row_data in enumerate(data, start=1):
|
|
869
|
+
row_values = [
|
|
870
|
+
{
|
|
871
|
+
"range": f"{sheet_id}!{chr(ord('A') + col)}{row + 1}:{chr(ord('A') + col)}{row + 1}",
|
|
872
|
+
"values": [[[{"text": {"text": str(row_data[header])}, "type": "text"}]]]
|
|
873
|
+
}
|
|
874
|
+
for col, header in enumerate(headers)
|
|
875
|
+
]
|
|
876
|
+
LarkdocsClient().writesheets(spreadsheet_token, sheet_id, {"value_ranges": row_values})
|
|
877
|
+
|
|
878
|
+
return True
|
|
879
|
+
except KeyError as ke:
|
|
880
|
+
print(f"KeyError 发生: 数据中缺少必要的键,错误详情: {ke}")
|
|
881
|
+
return False
|
|
882
|
+
except IndexError as ie:
|
|
883
|
+
print(f"IndexError 发生: 索引超出范围,错误详情: {ie}")
|
|
884
|
+
return False
|
|
885
|
+
except Exception as e:
|
|
886
|
+
print(f"发生未知错误: {e}")
|
|
887
|
+
return False
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def write_excletolist(data_name):
|
|
891
|
+
"""
|
|
892
|
+
1. 读取本地表格
|
|
893
|
+
2. 将表格内容拼接为text
|
|
894
|
+
"""
|
|
895
|
+
try:
|
|
896
|
+
# 查看当前工作目录
|
|
897
|
+
print(f"当前工作目录: {os.getcwd()}")
|
|
898
|
+
# /Users/bytedance/itam_assistant/itam_assistant/accessory.csv
|
|
899
|
+
# 构建文件路径
|
|
900
|
+
file_path = f'data/{data_name}.csv'
|
|
901
|
+
Candidates = []
|
|
902
|
+
Candidate = {
|
|
903
|
+
"Score": 0,
|
|
904
|
+
"Text": "IOS手机",
|
|
905
|
+
"Attrs": {"id": "", "type": ""}}
|
|
906
|
+
text = ""
|
|
907
|
+
with open(file_path, 'r', encoding='utf-8', newline='') as file:
|
|
908
|
+
reader = csv.reader(file)
|
|
909
|
+
headers = next(reader) # 读取表头
|
|
910
|
+
for header in headers:
|
|
911
|
+
text += f"{header}: "
|
|
912
|
+
text = text.rstrip(': ') + '\n'
|
|
913
|
+
|
|
914
|
+
for row in reader:
|
|
915
|
+
textout = ""
|
|
916
|
+
textout += ', '.join(row)
|
|
917
|
+
Candidate['Text'] = textout
|
|
918
|
+
Candidates.append(copy.deepcopy(Candidate))
|
|
919
|
+
return Candidates
|
|
920
|
+
except FileNotFoundError:
|
|
921
|
+
print(f"未找到文件: {file_path}")
|
|
922
|
+
return None
|
|
923
|
+
except Exception as e:
|
|
924
|
+
print(f"发生未知错误: {e}")
|
|
925
|
+
return None
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|