itam-assistant 0.1.1__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 +127 -0
- it_assistant/config.py +51 -0
- it_assistant/do_ai.py +490 -0
- it_assistant/intent_detail.py +290 -0
- it_assistant/lark_client.py +159 -0
- it_assistant/logger.py +53 -0
- it_assistant/openapi.py +459 -0
- it_assistant/test.py +1 -0
- itam_assistant-0.1.1.dist-info/METADATA +25 -0
- itam_assistant-0.1.1.dist-info/RECORD +13 -0
- itam_assistant-0.1.1.dist-info/WHEEL +5 -0
- itam_assistant-0.1.1.dist-info/top_level.txt +1 -0
it_assistant/openapi.py
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import copy
|
|
5
|
+
import csv
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
import json
|
|
10
|
+
from typing import List, Dict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_SegSearchCandidates(Query: str, Candidates: List[Dict]) -> str or None:
|
|
14
|
+
"""
|
|
15
|
+
获取分段搜索候选结果。
|
|
16
|
+
|
|
17
|
+
:param Query: 搜索查询字符串
|
|
18
|
+
:param Candidates: 候选结果列表,每个元素是一个字典,包含 "Score", "Text", "Attrs" 等键
|
|
19
|
+
:return: 按分数排序后的前 5 个候选结果的 JSON 字符串,如果请求失败则返回 None
|
|
20
|
+
"""
|
|
21
|
+
api_url = "https://genie.bytedance.com/pre/entsol/genie/skills/it-service/common/SegSearchCandidates"
|
|
22
|
+
payload = {
|
|
23
|
+
"Query": Query,
|
|
24
|
+
"TopN": 0,
|
|
25
|
+
"Candidates": Candidates
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
headers = {
|
|
29
|
+
'Authorization': 'Basic bWFzLTZrMGJxLWgwMmhxbDM4MjQtMzJrcXQ6YTljNDIwMWJlOTc4OTg4MDRhZmZiNTQyMzA2ZTMxMzU=',
|
|
30
|
+
'Content-Type': 'application/json'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
# 发起 POST 请求
|
|
35
|
+
response = requests.post(api_url, headers=headers, json=payload)
|
|
36
|
+
# 检查响应状态码
|
|
37
|
+
response.raise_for_status()
|
|
38
|
+
result = response.json()
|
|
39
|
+
if result and 'Candidates' in result:
|
|
40
|
+
top_5_scores = sorted(result['Candidates'], key=lambda x: x.get('Score', 0), reverse=True)[:5]
|
|
41
|
+
return json.dumps(top_5_scores, ensure_ascii=False)
|
|
42
|
+
except requests.RequestException as e:
|
|
43
|
+
print(f"请求发生错误: {e}")
|
|
44
|
+
except (KeyError, ValueError) as e:
|
|
45
|
+
print(f"处理响应数据时发生错误: {e}")
|
|
46
|
+
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_query_vector(para, clientinfo):
|
|
51
|
+
url = "https://open-itam-mig-pre.bytedance.net/v1/query_vector"
|
|
52
|
+
payload = json.dumps(para)
|
|
53
|
+
headers = {
|
|
54
|
+
'Authorization': clientinfo.get(
|
|
55
|
+
"authorization") or "Basic cm40cmFpdTRwenY1cGlsYTo2bWhvOXV3ZXFrOHZpbDllcXRxMHZ1YmVnc2xjeXBucg==",
|
|
56
|
+
'x-use-ppe': '1',
|
|
57
|
+
'x-tt-env': clientinfo.get("x_tt_env") or "ppe_cn_env_self_test_feat_cr_a",
|
|
58
|
+
'Content-Type': 'application/json'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
response = requests.request("POST", url, headers=headers, data=payload)
|
|
62
|
+
return response.text
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_by_AssetModelBizTypes(param,res):
|
|
66
|
+
"""
|
|
67
|
+
根据AssetModelBizTypes对分数进行预处理
|
|
68
|
+
"""
|
|
69
|
+
num = len(param.get("AssetModelFieldsWithOr"))
|
|
70
|
+
res0 =res["body"]["Results"]
|
|
71
|
+
for i in res0:
|
|
72
|
+
i['Score']=i['Score']/num
|
|
73
|
+
res["body"]["Results"]=res0
|
|
74
|
+
return res
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def software_asset_sku_structure(QueryValue):
|
|
80
|
+
"""
|
|
81
|
+
{ "asset_name": "figma", "version": null, "usage": "画画", "other_software": null, "link": "https://www.figma.com" }
|
|
82
|
+
"""
|
|
83
|
+
AssetModelFieldsWithAnd = []
|
|
84
|
+
if QueryValue.get('asset_name'):
|
|
85
|
+
AssetModelFieldsWithAnd.append(
|
|
86
|
+
{"FieldName": "vec_neme", "FieldType": "knn", "QueryValue": QueryValue.get("asset_name")})
|
|
87
|
+
if QueryValue.get('version'):
|
|
88
|
+
AssetModelFieldsWithAnd.append(
|
|
89
|
+
{"FieldName": "vec_version", "FieldType": "knn", "QueryValue": QueryValue.get("version")})
|
|
90
|
+
if QueryValue.get('usage'):
|
|
91
|
+
AssetModelFieldsWithAnd.append(
|
|
92
|
+
{"FieldName": "vec_description", "FieldType": "knn", "QueryValue": QueryValue.get("usage")})
|
|
93
|
+
|
|
94
|
+
parm = {
|
|
95
|
+
"From": 0,
|
|
96
|
+
"Size": 10,
|
|
97
|
+
"MinScore": 0.6,
|
|
98
|
+
"AssetModelFieldsWithAnd": AssetModelFieldsWithAnd,
|
|
99
|
+
"AssetModelBizTypes": "software_asset_sku"
|
|
100
|
+
}
|
|
101
|
+
return parm
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def asset_sku_structure(QueryValue):
|
|
105
|
+
"""
|
|
106
|
+
//除4
|
|
107
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
108
|
+
"""
|
|
109
|
+
keyword_parts = [QueryValue.get(key, "") for key in ["asset_name", "brand", "model", "specification"] if
|
|
110
|
+
QueryValue.get(key)]
|
|
111
|
+
keyword = ''.join(keyword_parts)
|
|
112
|
+
keyword = QueryValue['asset_name']
|
|
113
|
+
parm = {
|
|
114
|
+
"From": 0,
|
|
115
|
+
"Size": 10,
|
|
116
|
+
"MinScore": 0.1,
|
|
117
|
+
"AssetModelFieldsWithOr": [
|
|
118
|
+
{
|
|
119
|
+
"FieldName": "vec_name",
|
|
120
|
+
"FieldType": "knn",
|
|
121
|
+
"QueryValue": [keyword]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"FieldName": "vec_brand",
|
|
125
|
+
"FieldType": "knn",
|
|
126
|
+
"QueryValue": [keyword]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"FieldName": "vec_specification",
|
|
130
|
+
"FieldType": "knn",
|
|
131
|
+
"QueryValue": [keyword]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"FieldName": "vec_model_name",
|
|
135
|
+
"FieldType": "knn",
|
|
136
|
+
"QueryValue": [keyword]
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"AssetModelBizTypes": ["asset_sku"]
|
|
140
|
+
}
|
|
141
|
+
return parm
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def asset_spu_structure(QueryValue):
|
|
145
|
+
"""
|
|
146
|
+
//
|
|
147
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
148
|
+
"""
|
|
149
|
+
keyword = QueryValue['asset_name']
|
|
150
|
+
parm = {
|
|
151
|
+
"From": 0,
|
|
152
|
+
"Size": 10,
|
|
153
|
+
"MinScore": 0.1,
|
|
154
|
+
"AssetModelFieldsWithOr": [
|
|
155
|
+
{
|
|
156
|
+
"FieldName": "vec_name",
|
|
157
|
+
"FieldType": "knn",
|
|
158
|
+
"QueryValue": [keyword]
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
"AssetModelBizTypes": [
|
|
162
|
+
"asset_spu"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
return parm
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def accessory_sku_structure(QueryValue):
|
|
169
|
+
"""
|
|
170
|
+
//除2
|
|
171
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
172
|
+
"""
|
|
173
|
+
keyword = QueryValue['asset_name']
|
|
174
|
+
parm = {
|
|
175
|
+
"From": 0,
|
|
176
|
+
"Size": 10,
|
|
177
|
+
"MinScore": 0.1,
|
|
178
|
+
"AssetModelFieldsWithOr": [
|
|
179
|
+
{
|
|
180
|
+
"FieldName": "vec_brand",
|
|
181
|
+
"FieldType": "knn",
|
|
182
|
+
"QueryValue": [keyword]
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"FieldName": "vec_name",
|
|
186
|
+
"FieldType": "knn",
|
|
187
|
+
"QueryValue": [keyword]
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"AssetModelBizTypes": ["accessory_sku"]
|
|
191
|
+
}
|
|
192
|
+
return parm
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def asset_sku_structure0(QueryValue):
|
|
196
|
+
"""
|
|
197
|
+
//除4
|
|
198
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
199
|
+
"""
|
|
200
|
+
keyword_parts = [QueryValue.get(key, "") for key in ["asset_name", "brand", "model", "specification"] if
|
|
201
|
+
QueryValue.get(key)]
|
|
202
|
+
keyword = ''.join(keyword_parts)
|
|
203
|
+
keyword = QueryValue['asset_name']
|
|
204
|
+
spuid =["7188375763950259259","7188376358115380256","7188376497748560929","7189141923718220857","7189147675056704572","7195007119644134460","7195007119644150844","7195086198350842891","7195086198350859275","7195090795660069921","7195090795660086305","7195090795660102689","7195090795660119073","7195090795660135457","7195090795660151841","7195090795660168225","7195090795660184609","7195090795660200993","7195090795660217377","7195090795660233761","7195090795660250145","7195090795660266529","7195090795660282913","7195090795660299297","7195090795660315681","7195090795660332065","7195090795660348449","7195090795660364833","7195090795660381217","7195090795660397601","7195090795660413985","7195090795660430369","7195090795660446753","7195090795660463137","7195090795660479521","7195090795660495905","7195090795660512289","7195090795660528673","7195090795660545057","7195090795660561441","7195090795660577825","7195090795660594209","7195090795660610593","7195090795660626977","7195090795660643361","7195090795660659745","7195090795660676129","7195090795660692513","7195090795660708897","7195090795660725281","7195090795660741665","7195090795660758049","7195090795660774433","7195090795660790817","7195090795660807201","7195090795660823585","7195090795660839969","7195090795660856353","7195090795660872737","7195090795660889121","7195090795660905505","7195090795660921889","7195090795660938273","7195090795660954657","7195090795660971041","7195090795660987425","7195090795661003809","7195090795661020193","7195090795661036577","7195090795661052961","7195090795661069345","7195090795661085729","7195090795661102113","7195090795661118497","7195090795661134881","7195090795661151265","7195090795661167649","7195090795661184033","7195090795661200417","7195090795661216801","7195090795661233185","7195090795661249569","7195090795661265953","7195090795661282337","7195090795661298721","7195090795661315105","7195090795661331489","7195090795661347873","7195090795661364257","7195090795661380641","7195090795661397025","7195090795661413409","7195090795661429793","7195090795661446177","7195090795661462561","7195090795661478945","7195090795661495329","7195090795661511713","7195090795661528097","7195090795661544481","7195090795661560865","7195090795661577249","7195090795661593633","7195090795661610017","7195090795661626401","7195090795661642785","7195090795661659169","7195090795661675553","7195092625618111499","7195092625618127883","7195092625618144267","7195092625618160651","7195092625618177035","7195092625618193419","7195092625618209803","7195092625618226187","7195092625618242571","7195092625618258955","7195092625618275339","7195092625618291723","7195092625618308107","7195092625618324491","7195092625618340875","7195092625618357259","7195092625618373643","7195092625618390027","7195092625618406411","7195092625618422795","7195092625618439179","7195092625618455563","7195092625618471947","7195092625618488331","7195092625618504715","7195092625618521099","7195092625618537483","7195092625618553867","7195092625618570251","7195092625618586635","7195092625618603019","7195092625618619403","7195092625618635787","7195092625618652171","7195092625618668555","7195092625618684939","7195092625618701323","7195092625618717707","7195092625618734091","7195092625618750475","7195092625618766859","7195092625618783243","7195092625618799627","7195092625618816011","7195092625618832395","7195092625618848779","7195092625618865163","7195092625618881547","7195092625618897931","7195092625618914315","7195092625618930699","7195092625618947083","7195092625618963467","7195092625618979851","7195092625618996235","7195092625619012619","7195092625619029003","7195092625619045387","7195092625619061771","7195092625619078155","7195092625619094539","7195092625619110923","7195092625619127307","7195092625619143691","7195092625619160075","7195092625619176459","7195092625619192843","7195092625619209227","7195092625619225611","7195092625619241995","7195092625619258379","7195092625619274763","7195092625619291147","7195092625619307531","7195092625619323915","7195092625619340299","7195092625619356683","7195092625619373067","7195092625619389451","7195092625619405835","7195092625619422219","7195092625619438603","7195092625619454987","7195092625619471371","7195092625619487755","7195092625619504139","7195092625619520523","7195092625619536907","7195092625619553291","7195092625619569675","7195092625619586059","7195092625619602443","7195092625619618827","7195092625619635211","7195092625619651595","7195092625619667979","7195092625619684363","7195092625619700747","7195092625619717131","7195092625619733515","7195096094198467588","7195096094198483972","7195096094198500356","7195096094198516740","7195096094198533124","7195096094198549508","7195096094198565892","7195096094198582276","7195096094198598660","7195096094198615044","7195096094198631428","7195096094198647812","7195096094198664196","7195096094198680580","7195096094198696964","7195096094198713348","7195096094198729732","7195096094198746116","7195096094198762500","7195096094198778884","7195096094198795268","7195096094198811652","7195096094198828036","7195096094198844420","7195096094198860804","7195096094198877188","7195096094198893572","7195096094198909956","7195096094198926340","7195096094198942724","7195096094198959108","7195096094198975492","7195096094198991876","7195096094199008260","7195096094199024644","7195096094199041028","7195096094199057412","7195096094199073796","7195096094199090180","7195096094199106564"]
|
|
205
|
+
parm = {
|
|
206
|
+
"From": 0,
|
|
207
|
+
"Size": 10,
|
|
208
|
+
"MinScore": 0.1,
|
|
209
|
+
"AssetModelFieldsWithOr": [
|
|
210
|
+
{
|
|
211
|
+
"FieldName": "vec_name",
|
|
212
|
+
"FieldType": "knn",
|
|
213
|
+
"QueryValue": [keyword]
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"FieldName": "vec_brand",
|
|
217
|
+
"FieldType": "knn",
|
|
218
|
+
"QueryValue": [keyword]
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"FieldName": "vec_specification",
|
|
222
|
+
"FieldType": "knn",
|
|
223
|
+
"QueryValue": [keyword]
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"FieldName": "vec_model_name",
|
|
227
|
+
"FieldType": "knn",
|
|
228
|
+
"QueryValue": [keyword]
|
|
229
|
+
}
|
|
230
|
+
],
|
|
231
|
+
"SPUIDs":spuid,
|
|
232
|
+
"AssetModelBizTypes": ["asset_sku"]
|
|
233
|
+
}
|
|
234
|
+
return parm
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def asset_spu_structure0(QueryValue):
|
|
238
|
+
"""
|
|
239
|
+
//
|
|
240
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
241
|
+
"""
|
|
242
|
+
keyword = QueryValue['asset_name']
|
|
243
|
+
spuid = ["7188375763950250000","7188376358115380000","7188376497748560000","7189141923718220000","7189147675056700000","7195007119644130000","7195007119644150000","7195086198350840000","7195086198350850000","7195090795660060000","7195090795660080000","7195090795660100000","7195090795660110000","7195090795660130000","7195090795660150000","7195090795660160000","7195090795660180000","7195090795660200000","7195090795660210000","7195090795660230000","7195090795660250000","7195090795660260000","7195090795660280000","7195090795660290000","7195090795660310000","7195090795660330000","7195090795660340000","7195090795660360000","7195090795660380000","7195090795660390000","7195090795660410000","7195090795660430000","7195090795660440000","7195090795660460000","7195090795660470000","7195090795660490000","7195090795660510000","7195090795660520000","7195090795660540000","7195090795660560000","7195090795660570000","7195090795660590000","7195090795660610000","7195090795660620000","7195090795660640000","7195090795660650000","7195090795660670000","7195090795660690000","7195090795660700000","7195090795660720000","7195090795660740000","7195090795660750000","7195090795660770000","7195090795660790000","7195090795660800000","7195090795660820000","7195090795660830000","7195090795660850000","7195090795660870000","7195090795660880000","7195090795660900000","7195090795660920000","7195090795660930000","7195090795660950000","7195090795660970000","7195090795660980000","7195090795661000000","7195090795661020000","7195090795661030000","7195090795661050000","7195090795661060000","7195090795661080000","7195090795661100000","7195090795661110000","7195090795661130000","7195090795661150000","7195090795661160000","7195090795661180000","7195090795661200000","7195090795661210000","7195090795661230000","7195090795661240000","7195090795661260000","7195090795661280000","7195090795661290000","7195090795661310000","7195090795661330000","7195090795661340000","7195090795661360000","7195090795661380000","7195090795661390000","7195090795661410000","7195090795661420000","7195090795661440000","7195090795661460000","7195090795661470000","7195090795661490000","7195090795661510000","7195090795661520000","7195090795661540000","7195090795661560000","7195090795661570000","7195090795661590000","7195090795661610000","7195090795661620000","7195090795661640000","7195090795661650000","7195090795661670000","7195092625618110000","7195092625618120000","7195092625618140000","7195092625618160000","7195092625618170000","7195092625618190000","7195092625618200000","7195092625618220000","7195092625618240000","7195092625618250000","7195092625618270000","7195092625618290000","7195092625618300000","7195092625618320000","7195092625618340000","7195092625618350000","7195092625618370000","7195092625618390000","7195092625618400000","7195092625618420000","7195092625618430000","7195092625618450000","7195092625618470000","7195092625618480000","7195092625618500000","7195092625618520000","7195092625618530000","7195092625618550000","7195092625618570000","7195092625618580000","7195092625618600000","7195092625618610000","7195092625618630000","7195092625618650000","7195092625618660000","7195092625618680000","7195092625618700000","7195092625618710000","7195092625618730000","7195092625618750000","7195092625618760000","7195092625618780000","7195092625618790000","7195092625618810000","7195092625618830000","7195092625618840000","7195092625618860000","7195092625618880000","7195092625618890000","7195092625618910000","7195092625618930000","7195092625618940000","7195092625618960000","7195092625618970000","7195092625618990000","7195092625619010000","7195092625619020000","7195092625619040000","7195092625619060000","7195092625619070000","7195092625619090000","7195092625619110000","7195092625619120000","7195092625619140000","7195092625619160000","7195092625619170000","7195092625619190000","7195092625619200000","7195092625619220000","7195092625619240000","7195092625619250000","7195092625619270000","7195092625619290000","7195092625619300000","7195092625619320000","7195092625619340000","7195092625619350000","7195092625619370000","7195092625619380000","7195092625619400000","7195092625619420000","7195092625619430000","7195092625619450000","7195092625619470000","7195092625619480000","7195092625619500000","7195092625619520000","7195092625619530000","7195092625619550000","7195092625619560000","7195092625619580000","7195092625619600000","7195092625619610000","7195092625619630000","7195092625619650000","7195092625619660000","7195092625619680000","7195092625619700000","7195092625619710000","7195092625619730000","7195096094198460000","7195096094198480000","7195096094198500000","7195096094198510000","7195096094198530000","7195096094198540000","7195096094198560000","7195096094198580000","7195096094198590000","7195096094198610000","7195096094198630000","7195096094198640000","7195096094198660000","7195096094198680000","7195096094198690000","7195096094198710000","7195096094198720000","7195096094198740000","7195096094198760000","7195096094198770000","7195096094198790000","7195096094198810000","7195096094198820000","7195096094198840000","7195096094198860000","7195096094198870000","7195096094198890000","7195096094198900000","7195096094198920000","7195096094198940000","7195096094198950000","7195096094198970000","7195096094198990000","7195096094199000000","7195096094199020000","7195096094199040000","7195096094199050000","7195096094199070000","7195096094199090000","7195096094199100000"]
|
|
244
|
+
|
|
245
|
+
parm = {
|
|
246
|
+
"From": 0,
|
|
247
|
+
"Size": 10,
|
|
248
|
+
"MinScore": 0.1,
|
|
249
|
+
"AssetModelFieldsWithOr": [
|
|
250
|
+
{
|
|
251
|
+
"FieldName": "vec_name",
|
|
252
|
+
"FieldType": "knn",
|
|
253
|
+
"QueryValue": [keyword]
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
"SPUIDs": spuid,
|
|
257
|
+
"AssetModelBizTypes": [
|
|
258
|
+
"asset_spu"
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
return parm
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def accessory_sku_structure0(QueryValue):
|
|
265
|
+
"""
|
|
266
|
+
//除2
|
|
267
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
268
|
+
"""
|
|
269
|
+
keyword = QueryValue['asset_name']
|
|
270
|
+
aid =["7255990503152471077","7256617984164285452","7256686318809091129","7256686749950004281","7256687225969986618","7256690778088442899","7262681101586811916","7263392934995921977","7268230229804747813","7268232128557550653","7268234687477910586","7268241171808357415","7268255937588087864","7268270717870197771","7269732837775182887","7269763472186002495","7270845670796332092","7272702161690856502","7272752025073929228","7273438590867098636","7273440306249845814","7280477482813344825","7280479475325815868","7280483298299366456","7280498894235667511","7280764067903065124","7290837439865310264","7290842766874889276","7291270703461551115","7291277340449049663","7291277661333244982","7291354258590501900","7291354258590649356","7291358098207444009","7296056359766166567","7296382679158967332","7296382761811069988","7296382987112680467","7296388329770503222","7296388836878879782","7296390800186264587","7296391160079567911","7299038962449910823","7299051655970245695","7299061913801985035","7299080091194625065","7304504856743185462","7304574626516126730","7304864148406897701","7305960363957799948","7316741301058866239","7316852547615149110","7340991996498660389","7340992199092259890","7379095110077697087","7399862706805558281","7399862706805574665","7399862706805591049","7399862706805607433","7399862706805623817","7399862706805640201","7399862706805656585","7399862706805672969","7399862706805689353","7399862706805705737","7399862706805722121","7399862706805738505","7399862706805754889","7399862706806000649","7399862706806017033","7399862706806033417","7399862706806049801","7399906761391852556","7399906761392245772","7399906761392262156","7399906761392278540","7399906761392294924","7399906761392311308","7399906761392327692","7399906761392344076","7399906761392360460","7399906890068904979","7399906890069429267","7399906890069445651","7399906890069462035","7399906890069478419","7399906890069494803","7399906890069511187","7399952345222433843","7399952345222450227","7399952345222515763","7399952345222663219","7399952345222679603","7399952345222695987","7399952345222712371","7399952345222728755","7399952345222745139","7399952345222761523","7399952345222777907","7399952345222794291","7399952345222810675","7399952345222827059","7399952345222843443","7399952345222859827","7400306254902873115","7401103218090822683","7401103559464389641","7401158275641658404","7401170324039224356","7401176177328753705","7401191208268139561","7401193223491685388","7402187910122474505","7402561710756334603","7402563646222437395","7402564170141666367","7402564170141682751","7402564472043113483","7402565735024102463","7402565735024200767","7408913120209751090","7425532006169906227","7425532006170266675","7425536204962565130","7425537037367479322","7425537037367495706","7425537037367594010","7425537518110805042","7425537637102652425","7425538636952685594","7425538636953013274","7425540136253770789","7425543080369507355","7425545975999089701","7425552650253470770","7427045751215541298"]
|
|
271
|
+
parm = {
|
|
272
|
+
"From": 0,
|
|
273
|
+
"Size": 10,
|
|
274
|
+
"MinScore": 0.1,
|
|
275
|
+
"AssetModelFieldsWithOr": [
|
|
276
|
+
{
|
|
277
|
+
"FieldName": "vec_brand",
|
|
278
|
+
"FieldType": "knn",
|
|
279
|
+
"QueryValue": [keyword]
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"FieldName": "vec_name",
|
|
283
|
+
"FieldType": "knn",
|
|
284
|
+
"QueryValue": [keyword]
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
"SPUIDs": aid,
|
|
288
|
+
"AssetModelBizTypes": ["accessory_sku"]
|
|
289
|
+
}
|
|
290
|
+
return parm
|
|
291
|
+
|
|
292
|
+
def equipmentrequest_structure(QueryValue,asset_type):
|
|
293
|
+
"""
|
|
294
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
if "asset_sku" in asset_type:
|
|
298
|
+
return asset_sku_structure(QueryValue)
|
|
299
|
+
if "asset_spu" in asset_type:
|
|
300
|
+
return asset_spu_structure(QueryValue)
|
|
301
|
+
if "accessory_sku" in asset_type:
|
|
302
|
+
return accessory_sku_structure(QueryValue)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def equipmentreturn_structure0(QueryValue,asset_type):
|
|
306
|
+
"""
|
|
307
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
308
|
+
"""
|
|
309
|
+
|
|
310
|
+
if "asset_sku" in asset_type:
|
|
311
|
+
return asset_sku_structure0(QueryValue)
|
|
312
|
+
if "asset_spu" in asset_type:
|
|
313
|
+
return asset_spu_structure0(QueryValue)
|
|
314
|
+
if "accessory_sku" in asset_type:
|
|
315
|
+
return accessory_sku_structure0(QueryValue)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def equipmentrequest_structure0(QueryValue):
|
|
319
|
+
"""
|
|
320
|
+
{"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
|
|
321
|
+
"""
|
|
322
|
+
|
|
323
|
+
if QueryValue.get("device_type") and QueryValue.get("device_type")=="asset":
|
|
324
|
+
if QueryValue.get("brand") or QueryValue.get("model") or QueryValue.get("specification"):
|
|
325
|
+
return asset_sku_structure(QueryValue) #sku
|
|
326
|
+
else:
|
|
327
|
+
return asset_spu_structure(QueryValue)
|
|
328
|
+
else:
|
|
329
|
+
return accessory_sku_structure(QueryValue)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def equipmentreturn_structure(QueryValue):
|
|
335
|
+
"""
|
|
336
|
+
设备退还时的请求参数
|
|
337
|
+
"""
|
|
338
|
+
parm = {
|
|
339
|
+
"From": 0,
|
|
340
|
+
"Size": 10,
|
|
341
|
+
"MinScore": 0.1,
|
|
342
|
+
"AssetModelFieldsWithOr": [
|
|
343
|
+
{
|
|
344
|
+
"FieldName": "vec_name",
|
|
345
|
+
"FieldType": "knn",
|
|
346
|
+
"QueryValue": [
|
|
347
|
+
QueryValue.get("asset_name")
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
"AssetModelBizTypes": [
|
|
352
|
+
"accessory_sku"
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
return parm
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def GetBestMatchItemonline(SearchKey,HardwareMatchType,clientinfo):
|
|
359
|
+
url = "https://it.bytedance.com/itam-byte/api/itservice/common/GetBestMatchItem"
|
|
360
|
+
payload = json.dumps({
|
|
361
|
+
"SearchKey": SearchKey,
|
|
362
|
+
"TopN": 10,
|
|
363
|
+
"AiUseType": 5,
|
|
364
|
+
"QueryAssetModelScopeRequestV2": {
|
|
365
|
+
"HardwareMatchType": HardwareMatchType,
|
|
366
|
+
"TemplateType": "6883418246797986828",
|
|
367
|
+
"ApplyRegionID": "7145432241957506086",
|
|
368
|
+
"Page": {
|
|
369
|
+
"PageNum": 1,
|
|
370
|
+
"PageSize": 10
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
"psm": "athena"
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
headers = {
|
|
377
|
+
'authorization': clientinfo.get('authorization') or 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InYyIiwidHlwIjoiSldUIn0.eyJleHAiOjE3NTEwOTI3NjksImp0aSI6ImR1M3o1UEh3ZDNla2tLUlUiLCJpYXQiOjE3NDk3OTY3NjksImlzcyI6InRhbm5hIiwic3ViIjoiMzgzMDMxOUBieXRlZGFuY2UucGVvcGxlIiwidGVuYW50X2lkIjoiYnl0ZWRhbmNlLnBlb3BsZSIsInRlbmFudF9uYW1lIjoiIiwicHJvamVjdF9rZXkiOiJjcm1TZmdIVmU1dXhIMHJyIiwidW5pdCI6ImV1X25jIiwiYXV0aF9ieSI6Mn0.GGUPJ3FzxW131PovtM_BUANXWUPIJTfG6zbNlb80ZIiPviQ3U0t4hxVMty9Dj4PYfiLfLMQ1r3E9xsIWfvQDL-CGC7EsnqBDT6Vc4_ZGvW_mx-z3YVzs7TJ8cKE0YZUI8gB-ZsAgztMJF5Jlja0zqdWNi7sdc-YnYISzrxv6aiY',
|
|
378
|
+
'cookie': clientinfo.get('cookie') or'MONITOR_WEB_ID=ce5a3279-6ed5-4ede-9b00-29aa7c1a1311; bd_sso_3b6da9=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTAzMzYyMzMsImlhdCI6MTc0OTczMTQzMywiaXNzIjoic3NvLmJ5dGVkYW5jZS5jb20iLCJzdWIiOiJkZWdubjk2MWtma2treW9waDd5cyIsInRlbmFudF9pZCI6ImhncTN0Y2NwM2kxc2pqbjU4emlrIn0.dMO0OWpMvIXmHGHfgxU3FRvwLOqNWAW_kiWDiHWt9wMxQd5qsi9PILBXCEYP4NVq5CaNbU_XO488CJz0vxxNh50hLdk5Jgf7n1lm-FaTJ-AtD7tqBlUl94ZB38GiAb2m7U4xC-7iHWVH2Mp-M92Z7_jgB0xJcEiDmOhlLqBviatlLGcoeAIjhpK01MA04T6Efb5M_OgeJbbqOZgl-jSdIvY6SD5my9kSzg1KE3E1caquPzYMDtgjIy9L8rkqYz0A77DXac6l0tv6daHshoPvgtc4urTV9QdT6XAYyPO_yf8ISXz03opaKkmHtZ5slIFSqgTPbLJ9Y_dmaZuX9D_NRg; MONITOR_WEB_ID=ce5a3279-6ed5-4ede-9b00-29aa7c1a1311; _tea_utm_cache_1508={%22utm_source%22:%22startup%22%2C%22utm_medium%22:%22chrome%22}; _tea_utm_cache_1229=undefined; amuserid=7036392@bytedance.people',
|
|
379
|
+
'Content-Type': 'application/json'
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
response = requests.request("POST", url, headers=headers, data=payload)
|
|
383
|
+
|
|
384
|
+
return json.loads(response.text)
|
|
385
|
+
|
|
386
|
+
print(response.text)
|
|
387
|
+
|
|
388
|
+
def GetBestMatchItemandres(keyword0,HardwareMatchType,clientinfo):
|
|
389
|
+
list = {"Score": 0, "Name": "name"
|
|
390
|
+
}
|
|
391
|
+
lista, listc = [], []
|
|
392
|
+
for i in keyword0:
|
|
393
|
+
res0 = GetBestMatchItemonline(i, HardwareMatchType,clientinfo)['data']
|
|
394
|
+
print(1)
|
|
395
|
+
time.sleep(5)
|
|
396
|
+
if res0.get('AiBorrowAndUseResponseList'):
|
|
397
|
+
res = res0['AiBorrowAndUseResponseList']
|
|
398
|
+
for j in res:
|
|
399
|
+
listb = {}
|
|
400
|
+
lista = []
|
|
401
|
+
list["Score"] = j['Score']
|
|
402
|
+
list["Name"] = j['AccessoryModelScope']['AccessoryModelInfo']['Name']['ValueZh']
|
|
403
|
+
lista.append(copy.deepcopy(list))
|
|
404
|
+
listb = {"key": i, "res": lista}
|
|
405
|
+
listc.append(copy.deepcopy(listb))
|
|
406
|
+
|
|
407
|
+
return listc
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def test_():
|
|
411
|
+
|
|
412
|
+
info = {
|
|
413
|
+
'input': {'用户输入/userInput': 'Autodesk 3Ds MAX'},
|
|
414
|
+
'output': {'用户输入/output': 'Autodesk 3Ds MAX'},
|
|
415
|
+
'rt': True,
|
|
416
|
+
'label': []
|
|
417
|
+
|
|
418
|
+
}
|
|
419
|
+
info_list = []
|
|
420
|
+
a = 0
|
|
421
|
+
# 读取文件it_assistant/data/software_spu.csv
|
|
422
|
+
with open('data/software_spu.csv', 'r', encoding='utf-8', newline='') as file:
|
|
423
|
+
reader = csv.DictReader(file)
|
|
424
|
+
for row in reader:
|
|
425
|
+
if row['name_zh'] != "--":
|
|
426
|
+
a = a + 1
|
|
427
|
+
|
|
428
|
+
row_ = row['name_zh'].lower()
|
|
429
|
+
row_ = row_.replace(' ', '')
|
|
430
|
+
info['input'] = {'用户输入/userInput': row['name_zh']}
|
|
431
|
+
info['output'] = {'用户输入/output': row_}
|
|
432
|
+
res = json.loads(get_query_vector(0.6, [row_], 4, "vec_name"))
|
|
433
|
+
for i in res['body']['Results']:
|
|
434
|
+
info['label'].append({'socre': i['Score'], 'label': i['Item']['name_zh']})
|
|
435
|
+
print(a)
|
|
436
|
+
info_list.append(copy.deepcopy(info))
|
|
437
|
+
# 将info_list写入本地文件
|
|
438
|
+
# 异常报错或退出时将info_list写入本地文件
|
|
439
|
+
|
|
440
|
+
with open('test_data/software_spu_res_xiaoxie.csv', 'w', encoding='utf-8') as file:
|
|
441
|
+
json.dump(info_list, file, ensure_ascii=False)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
if __name__ == '__main__':
|
|
445
|
+
keyword0 = ['mac蓝牙鼠标', '西部数据-WDBEPK0020BBK', '安卓手机数据线']
|
|
446
|
+
res = GetBestMatchItemandres(keyword0, 2,clientinfo)
|
|
447
|
+
# 将res写入test.csv文件中
|
|
448
|
+
with open('test_data/test.csv', 'w', encoding='utf-8') as file:
|
|
449
|
+
for i in res:
|
|
450
|
+
file.write(i['key'] + ',' + str(i['res']) + '\n')
|
|
451
|
+
json.dump(res, file, ensure_ascii=False)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
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"]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: itam_assistant
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: 新增线上设备型号接口
|
|
5
|
+
Home-page: https://github.com/liujunmeiD/it_assistant
|
|
6
|
+
Author: liujunmeiD
|
|
7
|
+
Author-email: 1105030421@qq.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests>=2.25.1
|
|
14
|
+
Requires-Dist: numpy>=1.20.0
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
详见https://bytedance.feishu.cn/docs/doccnSOL0o2qtnElftgd2rir2Dc
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
it_assistant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
it_assistant/ailyapp_client.py,sha256=_6cLF80a8SrO7LCujfHe4re7xZyt6GBbDlmApgqbK6A,6326
|
|
3
|
+
it_assistant/config.py,sha256=L_5grm2ZWwg_S1JTOU6XLhQ5GPeYJaBFBLwzP2JA5Ys,5498
|
|
4
|
+
it_assistant/do_ai.py,sha256=FRuP4yZLqBEES0PCLholdHVCbqMRlYssxT631gXRrRk,19953
|
|
5
|
+
it_assistant/intent_detail.py,sha256=xqHELgYmlZIdz6odN1AyRoE5TIPr78zCUKgiqILApOY,16914
|
|
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=AJbhdbsB8PXfMjC0hFy2Nnu52dN1EGIXqoloGGD84Ig,29196
|
|
9
|
+
it_assistant/test.py,sha256=qGSihMYmtZkz_vifwEOz579f_wPBJAx5_rz1sABUyo4,581
|
|
10
|
+
itam_assistant-0.1.1.dist-info/METADATA,sha256=NMHaNgIjpYBMzFWdJDoUK-EVWBuPqqnhm6A0myX2A_Q,738
|
|
11
|
+
itam_assistant-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
itam_assistant-0.1.1.dist-info/top_level.txt,sha256=3g528EjzDs06L1brP8ZvVIvWFyS9K5b8gA6eRoRGdt0,13
|
|
13
|
+
itam_assistant-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
it_assistant
|