itam-assistant 0.1.7__py3-none-any.whl → 0.1.9__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/openapi.py DELETED
@@ -1,687 +0,0 @@
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_openapi_vector_v2",
58
- 'Content-Type': 'application/json'
59
- }
60
- time.sleep(2.1)
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
- def software_asset_sku_structure(QueryValue):
78
- """
79
- { "asset_name": "figma", "version": null, "usage": "画画", "other_software": null, "link": "https://www.figma.com" }
80
- """
81
- AssetModelFieldsWithAnd = []
82
- if QueryValue.get('asset_name'):
83
- AssetModelFieldsWithAnd.append(
84
- {"FieldName": "vec_neme", "FieldType": "knn", "QueryValue": QueryValue.get("asset_name")})
85
- if QueryValue.get('version'):
86
- AssetModelFieldsWithAnd.append(
87
- {"FieldName": "vec_version", "FieldType": "knn", "QueryValue": QueryValue.get("version")})
88
- if QueryValue.get('usage'):
89
- AssetModelFieldsWithAnd.append(
90
- {"FieldName": "vec_description", "FieldType": "knn", "QueryValue": QueryValue.get("usage")})
91
-
92
- parm = {
93
- "From": 0,
94
- "Size": 10,
95
- "MinScore": 0.6,
96
- "AssetModelFieldsWithAnd": AssetModelFieldsWithAnd,
97
- "AssetModelBizTypes": "software_asset_sku"
98
- }
99
- return parm
100
-
101
-
102
- def asset_sku_structure(QueryValue):
103
- """
104
- //除4
105
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
106
- """
107
- keyword_parts = [QueryValue.get(key, "") for key in ["asset_name", "brand", "model", "specification"] if
108
- QueryValue.get(key)]
109
- keyword = ''.join(keyword_parts)
110
- keyword = QueryValue['asset_name']
111
- parm = {
112
- "From": 0,
113
- "Size": 10,
114
- "MinScore": 0.1,
115
- "AssetModelFieldsWithOr": [
116
- {
117
- "FieldName": "vec_name",
118
- "FieldType": "knn",
119
- "QueryValue": [keyword]
120
- },
121
- {
122
- "FieldName": "vec_brand",
123
- "FieldType": "knn",
124
- "QueryValue": [keyword]
125
- },
126
- {
127
- "FieldName": "vec_specification",
128
- "FieldType": "knn",
129
- "QueryValue": [keyword]
130
- },
131
- {
132
- "FieldName": "vec_model_name",
133
- "FieldType": "knn",
134
- "QueryValue": [keyword]
135
- }
136
- ],
137
- "AssetModelBizTypes": ["asset_sku"]
138
- }
139
- return parm
140
-
141
-
142
- def asset_spu_structure(QueryValue):
143
- """
144
- //
145
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
146
- """
147
- keyword = QueryValue['asset_name']
148
- parm = {
149
- "From": 0,
150
- "Size": 10,
151
- "MinScore": 0.1,
152
- "AssetModelFieldsWithOr": [
153
- {
154
- "FieldName": "vec_name",
155
- "FieldType": "knn",
156
- "QueryValue": [keyword]
157
- }
158
- ],
159
- "AssetModelBizTypes": [
160
- "asset_spu"
161
- ]
162
- }
163
- return parm
164
-
165
-
166
- def accessory_sku_structure(QueryValue):
167
- """
168
- //除2
169
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
170
- """
171
- keyword = QueryValue['asset_name']
172
- parm = {
173
- "From": 0,
174
- "Size": 10,
175
- "MinScore": 0.1,
176
- "AssetModelFieldsWithOr": [
177
- {
178
- "FieldName": "vec_brand",
179
- "FieldType": "knn",
180
- "QueryValue": [keyword]
181
- },
182
- {
183
- "FieldName": "vec_name",
184
- "FieldType": "knn",
185
- "QueryValue": [keyword]
186
- }
187
- ],
188
- "AssetModelBizTypes": ["accessory_sku"]
189
- }
190
- return parm
191
-
192
-
193
- def asset_sku_structure0(QueryValue):
194
- """
195
- //除4
196
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
197
- """
198
- keyword_parts = [QueryValue.get(key, "") for key in ["asset_name", "brand", "model", "specification"] if
199
- QueryValue.get(key)]
200
- keyword = ''.join(keyword_parts)
201
- keyword = QueryValue['asset_name']
202
- spuid = ["7188375763950259259", "7188376358115380256", "7188376497748560929", "7189141923718220857",
203
- "7189147675056704572", "7195007119644134460", "7195007119644150844", "7195086198350842891",
204
- "7195086198350859275", "7195090795660069921", "7195090795660086305", "7195090795660102689",
205
- "7195090795660119073", "7195090795660135457", "7195090795660151841", "7195090795660168225",
206
- "7195090795660184609", "7195090795660200993", "7195090795660217377", "7195090795660233761",
207
- "7195090795660250145", "7195090795660266529", "7195090795660282913", "7195090795660299297",
208
- "7195090795660315681", "7195090795660332065", "7195090795660348449", "7195090795660364833",
209
- "7195090795660381217", "7195090795660397601", "7195090795660413985", "7195090795660430369",
210
- "7195090795660446753", "7195090795660463137", "7195090795660479521", "7195090795660495905",
211
- "7195090795660512289", "7195090795660528673", "7195090795660545057", "7195090795660561441",
212
- "7195090795660577825", "7195090795660594209", "7195090795660610593", "7195090795660626977",
213
- "7195090795660643361", "7195090795660659745", "7195090795660676129", "7195090795660692513",
214
- "7195090795660708897", "7195090795660725281", "7195090795660741665", "7195090795660758049",
215
- "7195090795660774433", "7195090795660790817", "7195090795660807201", "7195090795660823585",
216
- "7195090795660839969", "7195090795660856353", "7195090795660872737", "7195090795660889121",
217
- "7195090795660905505", "7195090795660921889", "7195090795660938273", "7195090795660954657",
218
- "7195090795660971041", "7195090795660987425", "7195090795661003809", "7195090795661020193",
219
- "7195090795661036577", "7195090795661052961", "7195090795661069345", "7195090795661085729",
220
- "7195090795661102113", "7195090795661118497", "7195090795661134881", "7195090795661151265",
221
- "7195090795661167649", "7195090795661184033", "7195090795661200417", "7195090795661216801",
222
- "7195090795661233185", "7195090795661249569", "7195090795661265953", "7195090795661282337",
223
- "7195090795661298721", "7195090795661315105", "7195090795661331489", "7195090795661347873",
224
- "7195090795661364257", "7195090795661380641", "7195090795661397025", "7195090795661413409",
225
- "7195090795661429793", "7195090795661446177", "7195090795661462561", "7195090795661478945",
226
- "7195090795661495329", "7195090795661511713", "7195090795661528097", "7195090795661544481",
227
- "7195090795661560865", "7195090795661577249", "7195090795661593633", "7195090795661610017",
228
- "7195090795661626401", "7195090795661642785", "7195090795661659169", "7195090795661675553",
229
- "7195092625618111499", "7195092625618127883", "7195092625618144267", "7195092625618160651",
230
- "7195092625618177035", "7195092625618193419", "7195092625618209803", "7195092625618226187",
231
- "7195092625618242571", "7195092625618258955", "7195092625618275339", "7195092625618291723",
232
- "7195092625618308107", "7195092625618324491", "7195092625618340875", "7195092625618357259",
233
- "7195092625618373643", "7195092625618390027", "7195092625618406411", "7195092625618422795",
234
- "7195092625618439179", "7195092625618455563", "7195092625618471947", "7195092625618488331",
235
- "7195092625618504715", "7195092625618521099", "7195092625618537483", "7195092625618553867",
236
- "7195092625618570251", "7195092625618586635", "7195092625618603019", "7195092625618619403",
237
- "7195092625618635787", "7195092625618652171", "7195092625618668555", "7195092625618684939",
238
- "7195092625618701323", "7195092625618717707", "7195092625618734091", "7195092625618750475",
239
- "7195092625618766859", "7195092625618783243", "7195092625618799627", "7195092625618816011",
240
- "7195092625618832395", "7195092625618848779", "7195092625618865163", "7195092625618881547",
241
- "7195092625618897931", "7195092625618914315", "7195092625618930699", "7195092625618947083",
242
- "7195092625618963467", "7195092625618979851", "7195092625618996235", "7195092625619012619",
243
- "7195092625619029003", "7195092625619045387", "7195092625619061771", "7195092625619078155",
244
- "7195092625619094539", "7195092625619110923", "7195092625619127307", "7195092625619143691",
245
- "7195092625619160075", "7195092625619176459", "7195092625619192843", "7195092625619209227",
246
- "7195092625619225611", "7195092625619241995", "7195092625619258379", "7195092625619274763",
247
- "7195092625619291147", "7195092625619307531", "7195092625619323915", "7195092625619340299",
248
- "7195092625619356683", "7195092625619373067", "7195092625619389451", "7195092625619405835",
249
- "7195092625619422219", "7195092625619438603", "7195092625619454987", "7195092625619471371",
250
- "7195092625619487755", "7195092625619504139", "7195092625619520523", "7195092625619536907",
251
- "7195092625619553291", "7195092625619569675", "7195092625619586059", "7195092625619602443",
252
- "7195092625619618827", "7195092625619635211", "7195092625619651595", "7195092625619667979",
253
- "7195092625619684363", "7195092625619700747", "7195092625619717131", "7195092625619733515",
254
- "7195096094198467588", "7195096094198483972", "7195096094198500356", "7195096094198516740",
255
- "7195096094198533124", "7195096094198549508", "7195096094198565892", "7195096094198582276",
256
- "7195096094198598660", "7195096094198615044", "7195096094198631428", "7195096094198647812",
257
- "7195096094198664196", "7195096094198680580", "7195096094198696964", "7195096094198713348",
258
- "7195096094198729732", "7195096094198746116", "7195096094198762500", "7195096094198778884",
259
- "7195096094198795268", "7195096094198811652", "7195096094198828036", "7195096094198844420",
260
- "7195096094198860804", "7195096094198877188", "7195096094198893572", "7195096094198909956",
261
- "7195096094198926340", "7195096094198942724", "7195096094198959108", "7195096094198975492",
262
- "7195096094198991876", "7195096094199008260", "7195096094199024644", "7195096094199041028",
263
- "7195096094199057412", "7195096094199073796", "7195096094199090180", "7195096094199106564"]
264
- parm = {
265
- "From": 0,
266
- "Size": 10,
267
- "MinScore": 0.1,
268
- "AssetModelFieldsWithOr": [
269
- {
270
- "FieldName": "vec_name",
271
- "FieldType": "knn",
272
- "QueryValue": [keyword]
273
- },
274
- {
275
- "FieldName": "vec_brand",
276
- "FieldType": "knn",
277
- "QueryValue": [keyword]
278
- },
279
- {
280
- "FieldName": "vec_specification",
281
- "FieldType": "knn",
282
- "QueryValue": [keyword]
283
- },
284
- {
285
- "FieldName": "vec_model_name",
286
- "FieldType": "knn",
287
- "QueryValue": [keyword]
288
- }
289
- ],
290
- "SPUIDs": spuid,
291
- "AssetModelBizTypes": ["asset_sku"]
292
- }
293
- return parm
294
-
295
-
296
- def asset_spu_structure0(QueryValue):
297
- """
298
- //
299
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
300
- """
301
- keyword = QueryValue['asset_name']
302
- spuid = ["7188375763950250000", "7188376358115380000", "7188376497748560000", "7189141923718220000",
303
- "7189147675056700000", "7195007119644130000", "7195007119644150000", "7195086198350840000",
304
- "7195086198350850000", "7195090795660060000", "7195090795660080000", "7195090795660100000",
305
- "7195090795660110000", "7195090795660130000", "7195090795660150000", "7195090795660160000",
306
- "7195090795660180000", "7195090795660200000", "7195090795660210000", "7195090795660230000",
307
- "7195090795660250000", "7195090795660260000", "7195090795660280000", "7195090795660290000",
308
- "7195090795660310000", "7195090795660330000", "7195090795660340000", "7195090795660360000",
309
- "7195090795660380000", "7195090795660390000", "7195090795660410000", "7195090795660430000",
310
- "7195090795660440000", "7195090795660460000", "7195090795660470000", "7195090795660490000",
311
- "7195090795660510000", "7195090795660520000", "7195090795660540000", "7195090795660560000",
312
- "7195090795660570000", "7195090795660590000", "7195090795660610000", "7195090795660620000",
313
- "7195090795660640000", "7195090795660650000", "7195090795660670000", "7195090795660690000",
314
- "7195090795660700000", "7195090795660720000", "7195090795660740000", "7195090795660750000",
315
- "7195090795660770000", "7195090795660790000", "7195090795660800000", "7195090795660820000",
316
- "7195090795660830000", "7195090795660850000", "7195090795660870000", "7195090795660880000",
317
- "7195090795660900000", "7195090795660920000", "7195090795660930000", "7195090795660950000",
318
- "7195090795660970000", "7195090795660980000", "7195090795661000000", "7195090795661020000",
319
- "7195090795661030000", "7195090795661050000", "7195090795661060000", "7195090795661080000",
320
- "7195090795661100000", "7195090795661110000", "7195090795661130000", "7195090795661150000",
321
- "7195090795661160000", "7195090795661180000", "7195090795661200000", "7195090795661210000",
322
- "7195090795661230000", "7195090795661240000", "7195090795661260000", "7195090795661280000",
323
- "7195090795661290000", "7195090795661310000", "7195090795661330000", "7195090795661340000",
324
- "7195090795661360000", "7195090795661380000", "7195090795661390000", "7195090795661410000",
325
- "7195090795661420000", "7195090795661440000", "7195090795661460000", "7195090795661470000",
326
- "7195090795661490000", "7195090795661510000", "7195090795661520000", "7195090795661540000",
327
- "7195090795661560000", "7195090795661570000", "7195090795661590000", "7195090795661610000",
328
- "7195090795661620000", "7195090795661640000", "7195090795661650000", "7195090795661670000",
329
- "7195092625618110000", "7195092625618120000", "7195092625618140000", "7195092625618160000",
330
- "7195092625618170000", "7195092625618190000", "7195092625618200000", "7195092625618220000",
331
- "7195092625618240000", "7195092625618250000", "7195092625618270000", "7195092625618290000",
332
- "7195092625618300000", "7195092625618320000", "7195092625618340000", "7195092625618350000",
333
- "7195092625618370000", "7195092625618390000", "7195092625618400000", "7195092625618420000",
334
- "7195092625618430000", "7195092625618450000", "7195092625618470000", "7195092625618480000",
335
- "7195092625618500000", "7195092625618520000", "7195092625618530000", "7195092625618550000",
336
- "7195092625618570000", "7195092625618580000", "7195092625618600000", "7195092625618610000",
337
- "7195092625618630000", "7195092625618650000", "7195092625618660000", "7195092625618680000",
338
- "7195092625618700000", "7195092625618710000", "7195092625618730000", "7195092625618750000",
339
- "7195092625618760000", "7195092625618780000", "7195092625618790000", "7195092625618810000",
340
- "7195092625618830000", "7195092625618840000", "7195092625618860000", "7195092625618880000",
341
- "7195092625618890000", "7195092625618910000", "7195092625618930000", "7195092625618940000",
342
- "7195092625618960000", "7195092625618970000", "7195092625618990000", "7195092625619010000",
343
- "7195092625619020000", "7195092625619040000", "7195092625619060000", "7195092625619070000",
344
- "7195092625619090000", "7195092625619110000", "7195092625619120000", "7195092625619140000",
345
- "7195092625619160000", "7195092625619170000", "7195092625619190000", "7195092625619200000",
346
- "7195092625619220000", "7195092625619240000", "7195092625619250000", "7195092625619270000",
347
- "7195092625619290000", "7195092625619300000", "7195092625619320000", "7195092625619340000",
348
- "7195092625619350000", "7195092625619370000", "7195092625619380000", "7195092625619400000",
349
- "7195092625619420000", "7195092625619430000", "7195092625619450000", "7195092625619470000",
350
- "7195092625619480000", "7195092625619500000", "7195092625619520000", "7195092625619530000",
351
- "7195092625619550000", "7195092625619560000", "7195092625619580000", "7195092625619600000",
352
- "7195092625619610000", "7195092625619630000", "7195092625619650000", "7195092625619660000",
353
- "7195092625619680000", "7195092625619700000", "7195092625619710000", "7195092625619730000",
354
- "7195096094198460000", "7195096094198480000", "7195096094198500000", "7195096094198510000",
355
- "7195096094198530000", "7195096094198540000", "7195096094198560000", "7195096094198580000",
356
- "7195096094198590000", "7195096094198610000", "7195096094198630000", "7195096094198640000",
357
- "7195096094198660000", "7195096094198680000", "7195096094198690000", "7195096094198710000",
358
- "7195096094198720000", "7195096094198740000", "7195096094198760000", "7195096094198770000",
359
- "7195096094198790000", "7195096094198810000", "7195096094198820000", "7195096094198840000",
360
- "7195096094198860000", "7195096094198870000", "7195096094198890000", "7195096094198900000",
361
- "7195096094198920000", "7195096094198940000", "7195096094198950000", "7195096094198970000",
362
- "7195096094198990000", "7195096094199000000", "7195096094199020000", "7195096094199040000",
363
- "7195096094199050000", "7195096094199070000", "7195096094199090000", "7195096094199100000"]
364
-
365
- parm = {
366
- "From": 0,
367
- "Size": 10,
368
- "MinScore": 0.1,
369
- "AssetModelFieldsWithOr": [
370
- {
371
- "FieldName": "vec_name",
372
- "FieldType": "knn",
373
- "QueryValue": [keyword]
374
- }
375
- ],
376
- "SPUIDs": spuid,
377
- "AssetModelBizTypes": [
378
- "asset_spu"
379
- ]
380
- }
381
- return parm
382
-
383
-
384
- def accessory_sku_structure0(QueryValue):
385
- """
386
- //除2
387
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
388
- """
389
- keyword = QueryValue['asset_name']
390
- aid = ["7255990503152471077", "7256617984164285452", "7256686318809091129", "7256686749950004281",
391
- "7256687225969986618", "7256690778088442899", "7262681101586811916", "7263392934995921977",
392
- "7268230229804747813", "7268232128557550653", "7268234687477910586", "7268241171808357415",
393
- "7268255937588087864", "7268270717870197771", "7269732837775182887", "7269763472186002495",
394
- "7270845670796332092", "7272702161690856502", "7272752025073929228", "7273438590867098636",
395
- "7273440306249845814", "7280477482813344825", "7280479475325815868", "7280483298299366456",
396
- "7280498894235667511", "7280764067903065124", "7290837439865310264", "7290842766874889276",
397
- "7291270703461551115", "7291277340449049663", "7291277661333244982", "7291354258590501900",
398
- "7291354258590649356", "7291358098207444009", "7296056359766166567", "7296382679158967332",
399
- "7296382761811069988", "7296382987112680467", "7296388329770503222", "7296388836878879782",
400
- "7296390800186264587", "7296391160079567911", "7299038962449910823", "7299051655970245695",
401
- "7299061913801985035", "7299080091194625065", "7304504856743185462", "7304574626516126730",
402
- "7304864148406897701", "7305960363957799948", "7316741301058866239", "7316852547615149110",
403
- "7340991996498660389", "7340992199092259890", "7379095110077697087", "7399862706805558281",
404
- "7399862706805574665", "7399862706805591049", "7399862706805607433", "7399862706805623817",
405
- "7399862706805640201", "7399862706805656585", "7399862706805672969", "7399862706805689353",
406
- "7399862706805705737", "7399862706805722121", "7399862706805738505", "7399862706805754889",
407
- "7399862706806000649", "7399862706806017033", "7399862706806033417", "7399862706806049801",
408
- "7399906761391852556", "7399906761392245772", "7399906761392262156", "7399906761392278540",
409
- "7399906761392294924", "7399906761392311308", "7399906761392327692", "7399906761392344076",
410
- "7399906761392360460", "7399906890068904979", "7399906890069429267", "7399906890069445651",
411
- "7399906890069462035", "7399906890069478419", "7399906890069494803", "7399906890069511187",
412
- "7399952345222433843", "7399952345222450227", "7399952345222515763", "7399952345222663219",
413
- "7399952345222679603", "7399952345222695987", "7399952345222712371", "7399952345222728755",
414
- "7399952345222745139", "7399952345222761523", "7399952345222777907", "7399952345222794291",
415
- "7399952345222810675", "7399952345222827059", "7399952345222843443", "7399952345222859827",
416
- "7400306254902873115", "7401103218090822683", "7401103559464389641", "7401158275641658404",
417
- "7401170324039224356", "7401176177328753705", "7401191208268139561", "7401193223491685388",
418
- "7402187910122474505", "7402561710756334603", "7402563646222437395", "7402564170141666367",
419
- "7402564170141682751", "7402564472043113483", "7402565735024102463", "7402565735024200767",
420
- "7408913120209751090", "7425532006169906227", "7425532006170266675", "7425536204962565130",
421
- "7425537037367479322", "7425537037367495706", "7425537037367594010", "7425537518110805042",
422
- "7425537637102652425", "7425538636952685594", "7425538636953013274", "7425540136253770789",
423
- "7425543080369507355", "7425545975999089701", "7425552650253470770", "7427045751215541298"]
424
- parm = {
425
- "From": 0,
426
- "Size": 10,
427
- "MinScore": 0.1,
428
- "AssetModelFieldsWithOr": [
429
- {
430
- "FieldName": "vec_brand",
431
- "FieldType": "knn",
432
- "QueryValue": [keyword]
433
- },
434
- {
435
- "FieldName": "vec_name",
436
- "FieldType": "knn",
437
- "QueryValue": [keyword]
438
- }
439
- ],
440
- "SPUIDs": aid,
441
- "AssetModelBizTypes": ["accessory_sku"]
442
- }
443
- return parm
444
-
445
-
446
- def equipmentrequest_structure(QueryValue, asset_type):
447
- """
448
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
449
- """
450
-
451
- if "asset_sku" in asset_type:
452
- return asset_sku_structure(QueryValue)
453
- if "asset_spu" in asset_type:
454
- return asset_spu_structure(QueryValue)
455
- if "accessory_sku" in asset_type:
456
- return accessory_sku_structure(QueryValue)
457
-
458
-
459
- def equipmentreturn_structure0(QueryValue, asset_type):
460
- """
461
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
462
- """
463
-
464
- if "asset_sku" in asset_type:
465
- return asset_sku_structure0(QueryValue)
466
- if "asset_spu" in asset_type:
467
- return asset_spu_structure0(QueryValue)
468
- if "accessory_sku" in asset_type:
469
- return accessory_sku_structure0(QueryValue)
470
-
471
-
472
- def equipmentrequest_structure0(QueryValue):
473
- """
474
- {"asset_name": "pc笔记本", "apply_num": 1, "device_type": "asset", "brand": "Xiaomi", "model": "MiBook", "specification": null }
475
- """
476
-
477
- if QueryValue.get("device_type") and QueryValue.get("device_type") == "asset":
478
- if QueryValue.get("brand") or QueryValue.get("model") or QueryValue.get("specification"):
479
- return asset_sku_structure(QueryValue) # sku
480
- else:
481
- return asset_spu_structure(QueryValue)
482
- else:
483
- return accessory_sku_structure(QueryValue)
484
-
485
-
486
- def equipmentreturn_structure(QueryValue):
487
- """
488
- 设备退还时的请求参数
489
- """
490
- parm = {
491
- "From": 0,
492
- "Size": 10,
493
- "MinScore": 0.1,
494
- "AssetModelFieldsWithOr": [
495
- {
496
- "FieldName": "vec_name",
497
- "FieldType": "knn",
498
- "QueryValue": [
499
- QueryValue.get("asset_name")
500
- ]
501
- }
502
- ],
503
- "AssetModelBizTypes": [
504
- "accessory_sku"
505
- ]
506
- }
507
- return parm
508
-
509
-
510
- def GetBestMatchItemonline(SearchKey, HardwareMatchType, clientinfo):
511
- url = "https://it.bytedance.com/itam-byte/api/itservice/common/GetBestMatchItem"
512
- payload = json.dumps({
513
- "SearchKey": SearchKey,
514
- "TopN": 10,
515
- "AiUseType": 5,
516
- "QueryAssetModelScopeRequestV2": {
517
- "HardwareMatchType": HardwareMatchType,
518
- "TemplateType": "6883418246797986828",
519
- "ApplyRegionID": "7145432241957506086",
520
- "Page": {
521
- "PageNum": 1,
522
- "PageSize": 10
523
- }
524
- },
525
- "psm": "athena"
526
- })
527
- time.sleep(5)
528
- headers = {
529
- 'authorization': clientinfo.get(
530
- 'authorization') or 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InYyIiwidHlwIjoiSldUIn0.eyJleHAiOjE3NTEwOTI3NjksImp0aSI6ImR1M3o1UEh3ZDNla2tLUlUiLCJpYXQiOjE3NDk3OTY3NjksImlzcyI6InRhbm5hIiwic3ViIjoiMzgzMDMxOUBieXRlZGFuY2UucGVvcGxlIiwidGVuYW50X2lkIjoiYnl0ZWRhbmNlLnBlb3BsZSIsInRlbmFudF9uYW1lIjoiIiwicHJvamVjdF9rZXkiOiJjcm1TZmdIVmU1dXhIMHJyIiwidW5pdCI6ImV1X25jIiwiYXV0aF9ieSI6Mn0.GGUPJ3FzxW131PovtM_BUANXWUPIJTfG6zbNlb80ZIiPviQ3U0t4hxVMty9Dj4PYfiLfLMQ1r3E9xsIWfvQDL-CGC7EsnqBDT6Vc4_ZGvW_mx-z3YVzs7TJ8cKE0YZUI8gB-ZsAgztMJF5Jlja0zqdWNi7sdc-YnYISzrxv6aiY',
531
- 'cookie': clientinfo.get(
532
- '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',
533
- 'Content-Type': 'application/json'
534
- }
535
-
536
- response = requests.request("POST", url, headers=headers, data=payload)
537
-
538
- return json.loads(response.text)
539
-
540
-
541
- def GetBestMatchItemonline_old(SearchKey, HardwareMatchType, clientinfo):
542
- url = "https://it.bytedance.com/itam-byte/api/itservice/common/GetBestMatchItem"
543
- payload = json.dumps({
544
- "SearchKey": SearchKey,
545
- "TopN": 1000,
546
- "AiUseType": 3,
547
- "QueryAssetModelScopeRequest":
548
- {"FlowTemplateIDs":
549
- ["6883468409742298119", "7514160571177913371", "6885245774565739523", "6883468929408437256",
550
- "6883715234721188867", "6883457792222579716"],
551
- "SearchName": "",
552
- "ApplyRegionID": "7145432241957506086",
553
- "Page": {"PageNum": 1, "PageSize": 1000}, "Request": {}}, "psm": "athena"}
554
- )
555
- time.sleep(5)
556
- headers = {
557
- 'authorization': clientinfo.get(
558
- 'authorization') or 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InYyIiwidHlwIjoiSldUIn0.eyJleHAiOjE3NTEwOTI3NjksImp0aSI6ImR1M3o1UEh3ZDNla2tLUlUiLCJpYXQiOjE3NDk3OTY3NjksImlzcyI6InRhbm5hIiwic3ViIjoiMzgzMDMxOUBieXRlZGFuY2UucGVvcGxlIiwidGVuYW50X2lkIjoiYnl0ZWRhbmNlLnBlb3BsZSIsInRlbmFudF9uYW1lIjoiIiwicHJvamVjdF9rZXkiOiJjcm1TZmdIVmU1dXhIMHJyIiwidW5pdCI6ImV1X25jIiwiYXV0aF9ieSI6Mn0.GGUPJ3FzxW131PovtM_BUANXWUPIJTfG6zbNlb80ZIiPviQ3U0t4hxVMty9Dj4PYfiLfLMQ1r3E9xsIWfvQDL-CGC7EsnqBDT6Vc4_ZGvW_mx-z3YVzs7TJ8cKE0YZUI8gB-ZsAgztMJF5Jlja0zqdWNi7sdc-YnYISzrxv6aiY',
559
- 'cookie': clientinfo.get(
560
- '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',
561
- 'Content-Type': 'application/json'
562
- }
563
-
564
- response = requests.request("POST", url, headers=headers, data=payload)
565
-
566
- return json.loads(response.text)
567
-
568
-
569
- def GetBestMatchItemandres(keyword0, HardwareMatchType, clientinfo):
570
- list = {"Score": 0, "Name": "name"
571
- }
572
- lista, listc = [], []
573
- for i in keyword0:
574
- res0 = GetBestMatchItemonline(i, HardwareMatchType, clientinfo)['data']
575
- print(1)
576
- time.sleep(5)
577
- listb = {}
578
- if res0.get('AiBorrowAndUseResponseList'):
579
- res = res0['AiBorrowAndUseResponseList']
580
- for j in res:
581
- listb = {}
582
- lista = []
583
- list["Score"] = j['Score']
584
- list["Name"] = j['AccessoryModelScope']['AccessoryModelInfo']['Name']['ValueZh']
585
- lista.append(copy.deepcopy(list))
586
- listb = {"key": i, "res": lista}
587
- listc.append(copy.deepcopy(listb))
588
- return listc
589
-
590
-
591
- def test_hardware_match(keyword0, HardwareMatchType, clientinfo):
592
- url = "https://open-itam-mig-pre.bytedance.net/v1/test_hardware_match"
593
- payload = json.dumps({
594
- "hardware_type": HardwareMatchType,
595
- "search_key": keyword0
596
- })
597
- headers = {
598
- 'Authorization': clientinfo.get(
599
- 'authorization') or 'Basic cm40cmFpdTRwenY1cGlsYTo2bWhvOXV3ZXFrOHZpbDllcXRxMHZ1YmVnc2xjeXBucg==',
600
- 'x-use-ppe': '1',
601
- 'x-tt-env': 'ppe_es_test_match',
602
- 'Content-Type': 'application/json'
603
- }
604
- time.sleep(3)
605
-
606
- response = requests.request("POST", url, headers=headers, data=payload)
607
- print(response.text)
608
-
609
- return json.loads(response.text)
610
-
611
-
612
- def searchListAssetModelScope(key, HardwareMatchType, clientinfo):
613
- if HardwareMatchType == 1:
614
- url = f"https://it.bytedance.com/itam-byte/api/itservice/searchListAssetModelScope?FlowTemplateIDs=6883468409742298119,7514160571177913371,6885245774565739523,6883468929408437256,6883715234721188867,6883457792222579716&SearchName={key}&pageNum=1&pageSize=30&applyRegionID=7145432241957506086&AccessoryApplyType=1"
615
- else:
616
- url = f"https://it.bytedance.com/itam-byte/api/itservice/searchListAssetModelScope?FlowTemplateIDs=6883468409742298119,7514160571177913371,6885245774565739523,6883468929408437256,6883715234721188867,6883457792222579716&SearchName={key}&pageNum=1&pageSize=30&applyRegionID=7145432241957506086&AccessoryApplyType=1"
617
-
618
- payload = {}
619
- headers = {
620
- 'authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InYyIiwidHlwIjoiSldUIn0.eyJleHAiOjE3NTEwMDU1MjQsImp0aSI6IktJVVI5ZkdoZ2Q1cyt4NWIiLCJpYXQiOjE3NDk3MDk1MjQsImlzcyI6InRhbm5hIiwic3ViIjoiMzgzMDMxOUBieXRlZGFuY2UucGVvcGxlIiwidGVuYW50X2lkIjoiYnl0ZWRhbmNlLnBlb3BsZSIsInRlbmFudF9uYW1lIjoiIiwicHJvamVjdF9rZXkiOiJjcm1TZmdIVmU1dXhIMHJyIiwidW5pdCI6ImV1X25jIiwiYXV0aF9ieSI6Mn0.wtuTgUI6posLTQ-WJU539NuIYbMCgYqBrCOvdigR09h8zl_VO7tUJ4GSmfjDH8jZjtGSF-nEoDLPbX2z4BZkwtvoh--oa8KP-IIOOk2KQS2lVHz1mE7HWaEdCpml1_DS0PJB42F3B-L0EjRqQki_g3Jjn1kZjMgwFqpFW-TwcpY',
621
- 'cookie': '_tea_utm_cache_1229=undefined; MONITOR_WEB_ID=ce5a3279-6ed5-4ede-9b00-29aa7c1a1311; amuserid=3830319@bytedance.people; msToken=TYcrN_92buBPnrV9MSb8i_0Uvz5lFxoWtnz8PA8MhLaAtrddfSUuR69V8vEJvRwEMDOyOAFL-PY87wN-oA4tKDroSbEvsjPNFn202nmCEcO9rKH9KINPWA=='
622
- }
623
-
624
- response = requests.request("GET", url, headers=headers, data=payload)
625
-
626
- print(response.text)
627
- return json.loads(response.text)
628
-
629
-
630
- def SoftwareApplyGetBestMatchItem(key, clientinfo):
631
- url = "https://it.bytedance.com/itam-byte/api/itservice/common/GetBestMatchItem"
632
- payload = json.dumps({
633
- "SearchKey": "",
634
- "TopN": 5,
635
- "AiUseType": 100,
636
- "SoftwareApplyRequest": {
637
- "Size": 3,
638
- "Name": key,
639
- "Description": ""
640
- },
641
- "psm": "athena"
642
- })
643
- headers = {
644
- 'authorization': clientinfo.get(
645
- 'authorization') or 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InYyIiwidHlwIjoiSldUIn0.eyJleHAiOjE3NTEwMDU1MjQsImp0aSI6IktJVVI5ZkdoZ2Q1cyt4NWIiLCJpYXQiOjE3NDk3MDk1MjQsImlzcyI6InRhbm5hIiwic3ViIjoiMzgzMDMxOUBieXRlZGFuY2UucGVvcGxlIiwidGVuYW50X2lkIjoiYnl0ZWRhbmNlLnBlb3BsZSIsInRlbmFudF9uYW1lIjoiIiwicHJvamVjdF9rZXkiOiJjcm1TZmdIVmU1dXhIMHJyIiwidW5pdCI6ImV1X25jIiwiYXV0aF9ieSI6Mn0.wtuTgUI6posLTQ-WJU539NuIYbMCgYqBrCOvdigR09h8zl_VO7tUJ4GSmfjDH8jZjtGSF-nEoDLPbX2z4BZkwtvoh--oa8KP-IIOOk2KQS2lVHz1mE7HWaEdCpml1_DS0PJB42F3B-L0EjRqQki_g3Jjn1kZjMgwFqpFW-TwcpY',
646
- 'cookie': clientinfo.get(
647
- 'cookie') or '_tea_utm_cache_1229=undefined; MONITOR_WEB_ID=ce5a3279-6ed5-4ede-9b00-29aa7c1a1311; amuserid=3830319@bytedance.people; msToken=TYcrN_92buBPnrV9MSb8i_0Uvz5lFxoWtnz8PA8MhLaAtrddfSUuR69V8vEJvRwEMDOyOAFL-PY87wN-oA4tKDroSbEvsjPNFn202nmCEcO9rKH9KINPWA==',
648
- 'Content-Type': 'application/json'
649
- }
650
-
651
- response = requests.request("POST", url, headers=headers, data=payload)
652
- time.sleep(5)
653
-
654
- return json.loads(response.text)
655
-
656
-
657
- if __name__ == '__main__':
658
- info = {
659
- 'input': {'用户输入/userInput': 'Autodesk 3Ds MAX'},
660
- 'output': {'用户输入/output': 'Autodesk 3Ds MAX'},
661
- 'rt': True,
662
- 'label': []
663
-
664
- }
665
- info_list = []
666
- a = 0
667
- # 读取文件it_assistant/data/software_spu.csv
668
- with open('data/software_spu.csv', 'r', encoding='utf-8', newline='') as file:
669
- reader = csv.DictReader(file)
670
- for row in reader:
671
- if row['name_zh'] != "--":
672
- a = a + 1
673
-
674
- row_ = row['name_zh'].lower()
675
- row_ = row_.replace(' ', '')
676
- info['input'] = {'用户输入/userInput': row['name_zh']}
677
- info['output'] = {'用户输入/output': row_}
678
- res = json.loads(get_query_vector(0.6, [row_], 4, "vec_name"))
679
- for i in res['body']['Results']:
680
- info['label'].append({'socre': i['Score'], 'label': i['Item']['name_zh']})
681
- print(a)
682
- info_list.append(copy.deepcopy(info))
683
- # 将info_list写入本地文件
684
- # 异常报错或退出时将info_list写入本地文件
685
-
686
- with open('test_data/software_spu_res_xiaoxie.csv', 'w', encoding='utf-8') as file:
687
- json.dump(info_list, file, ensure_ascii=False)