itam-assistant 0.1.3__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/ailyapp_client.py +2 -0
- it_assistant/do_ai.py +110 -39
- it_assistant/intent_detail.py +4 -6
- it_assistant/openapi.py +2 -2
- 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.3.dist-info → itam_assistant-0.1.5.dist-info}/METADATA +2 -2
- 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.3.dist-info/RECORD +0 -19
- itam_assistant-0.1.3.dist-info/top_level.txt +0 -1
- {itam_assistant-0.1.3.dist-info → itam_assistant-0.1.5.dist-info}/WHEEL +0 -0
it_assistant/ailyapp_client.py
CHANGED
|
@@ -9,6 +9,8 @@ from lark_oapi.api.aily.v1 import *
|
|
|
9
9
|
# 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用
|
|
10
10
|
# 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET.
|
|
11
11
|
|
|
12
|
+
pre =['spring_f17d05d924__c']
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
class AilyLarkClient():
|
|
14
16
|
def __init__(self,clientinfo):
|
it_assistant/do_ai.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import time
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
from
|
|
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
7
|
import datetime
|
|
8
8
|
import copy
|
|
9
9
|
import os
|
|
@@ -81,15 +81,18 @@ def do_ai_auto(Testk_data, clientinfo):
|
|
|
81
81
|
startAt = int(time.time())
|
|
82
82
|
# 创建会话
|
|
83
83
|
seseion_id = AilyLarkClient(clientinfo).create_ailysession(tenant_access_token)
|
|
84
|
+
time.sleep(10)
|
|
84
85
|
if not seseion_id:
|
|
85
86
|
raise ValueError("未能成功创建会话")
|
|
86
87
|
# 创建消息
|
|
87
88
|
message_id = AilyLarkClient(clientinfo).create_ailysessionaily_message(tenant_access_token, seseion_id,
|
|
88
89
|
aa)
|
|
90
|
+
time.sleep(5)
|
|
89
91
|
if not message_id:
|
|
90
92
|
raise ValueError("未能成功创建消息")
|
|
91
93
|
# 创建运行实例
|
|
92
94
|
runs = AilyLarkClient(clientinfo).create_ailysession_run(tenant_access_token, seseion_id)
|
|
95
|
+
time.sleep(5)
|
|
93
96
|
num = num + 1
|
|
94
97
|
return startAt, num
|
|
95
98
|
except KeyError as ke:
|
|
@@ -137,22 +140,15 @@ def do_waterlevellineres_list(res, info):
|
|
|
137
140
|
info['rt'] = False
|
|
138
141
|
return info
|
|
139
142
|
|
|
140
|
-
|
|
141
143
|
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
142
144
|
if res["body"]["Results"]:
|
|
145
|
+
info['output']['用户输入/output']='log_id:'+res['log_id']
|
|
143
146
|
# 取["Results"]下前2个结果,若只有1个结果,label1为空
|
|
144
|
-
if len(res["body"]["Results"]) >
|
|
145
|
-
|
|
146
|
-
{'label': res["body"]["Results"][
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
'score': res["body"]["Results"][1]['Score']}]
|
|
150
|
-
|
|
151
|
-
else:
|
|
152
|
-
info['label'] = [
|
|
153
|
-
{'label': res["body"]["Results"][0]['Item']['name_zh'],
|
|
154
|
-
'score': res["body"]["Results"][0]['Score']},
|
|
155
|
-
{'label': '', 'score': 0}]
|
|
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))
|
|
156
152
|
# 判断label0和label1是否为空,为空则:label默认2级
|
|
157
153
|
# 判断exp和label是否一致,一致则:rt=True,不一致则:rt=False
|
|
158
154
|
if info['exp'][0]['label'] == info['label'][0]['label'] and info['exp'][1]['label'] == info['label'][1][
|
|
@@ -168,6 +164,38 @@ def do_waterlevellineres_list(res, info):
|
|
|
168
164
|
|
|
169
165
|
return info
|
|
170
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
|
+
|
|
171
199
|
def do_waterlevellineres_listassetspu(res, info,hardtype):
|
|
172
200
|
"""
|
|
173
201
|
获取结果,并组装水位线info
|
|
@@ -179,10 +207,11 @@ def do_waterlevellineres_listassetspu(res, info,hardtype):
|
|
|
179
207
|
if res["data"].get("AiBorrowAndUseResponseList") == None:
|
|
180
208
|
info['label'] = [{'label': '', 'score': 0},{'label': '', 'score': 0.8}]
|
|
181
209
|
info['rt'] = False
|
|
182
|
-
if info['exp'][
|
|
210
|
+
if info['exp']==[]:
|
|
183
211
|
info['rt'] = True
|
|
184
212
|
return info
|
|
185
213
|
reslist=res["data"]["AiBorrowAndUseResponseList"]
|
|
214
|
+
info['output']['用户输入/output']='requestId:'+res['requestId']
|
|
186
215
|
aaa ={}
|
|
187
216
|
# 判断res["body"]["Results"]不为空,空则:label0 label1 为空,label默认2级
|
|
188
217
|
if reslist:
|
|
@@ -198,12 +227,12 @@ def do_waterlevellineres_listassetspu(res, info,hardtype):
|
|
|
198
227
|
'score': reslist[j]['Score']}
|
|
199
228
|
info['label'].append(copy.deepcopy(aaa))
|
|
200
229
|
# 判断label0和label1是否为空,为空则:label默认2级
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
|
207
236
|
else:
|
|
208
237
|
info['label'] = info['label'] = [{'label': '', 'score': 0}, {'label': '', 'score': 0}]
|
|
209
238
|
info['rt'] = False
|
|
@@ -401,25 +430,60 @@ def do_waterlevelline_autotest(collections, clientinfo, score_threshold):
|
|
|
401
430
|
for i in collections:
|
|
402
431
|
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
403
432
|
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
404
|
-
info['exp'] = [
|
|
405
|
-
|
|
406
|
-
|
|
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
|
|
407
446
|
info['artificial'] = info['exp']
|
|
408
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
|
|
409
455
|
if "软件申请" in i['ext']['BPO标注-AP-分发技能']:
|
|
410
|
-
keywprd = software_asset_sku_structure(
|
|
456
|
+
keywprd = software_asset_sku_structure(asset_name)
|
|
411
457
|
res = json.loads(get_query_vector(keywprd, clientinfo))
|
|
412
458
|
if "设备/配件申请" in i['ext']['BPO标注-AP-分发技能']:
|
|
413
|
-
keywprd = equipmentrequest_structure(
|
|
414
|
-
|
|
415
|
-
|
|
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)
|
|
416
480
|
if "设备/配件退还" in i['ext']['BPO标注-AP-分发技能']:
|
|
417
|
-
keywprd = equipmentreturn_structure0(
|
|
481
|
+
keywprd = equipmentreturn_structure0(asset_name, i['ext']['asset_type'])
|
|
418
482
|
res0 = json.loads(get_query_vector(keywprd, clientinfo))
|
|
419
483
|
res = get_by_AssetModelBizTypes(keywprd, res0)
|
|
420
484
|
else:
|
|
421
485
|
res = ""
|
|
422
|
-
infoout =
|
|
486
|
+
infoout = do_waterlevellineres_listv2(res, info)
|
|
423
487
|
info_list.append(copy.deepcopy(infoout))
|
|
424
488
|
a = a+1
|
|
425
489
|
print("这是"+str(a))
|
|
@@ -449,9 +513,15 @@ def do_waterlevelline_autotest_aseetspu(collections, clientinfo, score_threshold
|
|
|
449
513
|
for i in collections:
|
|
450
514
|
info['input']['用户输入/userInput'] = i['ext']['BPO标注-AP-资产名称']
|
|
451
515
|
info['output']['用户输入/output'] = i['ext']['BPO标注-AP-资产名称']
|
|
452
|
-
info['exp'] = [
|
|
453
|
-
|
|
454
|
-
|
|
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})
|
|
455
525
|
info['artificial'] = info['exp']
|
|
456
526
|
info['label']=[]
|
|
457
527
|
if i['ext']['BPO标注-AP-资产名称']:
|
|
@@ -460,14 +530,15 @@ def do_waterlevelline_autotest_aseetspu(collections, clientinfo, score_threshold
|
|
|
460
530
|
try:
|
|
461
531
|
# 尝试将其解析为 JSON 对象
|
|
462
532
|
if isinstance(asset_name, str):
|
|
463
|
-
|
|
533
|
+
asset_name0 = json.loads(asset_name)
|
|
534
|
+
asset_name = asset_name0['asset_name']
|
|
464
535
|
except json.JSONDecodeError:
|
|
465
536
|
# 若解析失败,说明不是 JSON 格式,保持原样
|
|
466
537
|
pass
|
|
467
538
|
key = asset_name.get('asset_name') if isinstance(asset_name, dict) else asset_name
|
|
468
539
|
if i['ext']['BPO标注-AP-资产类型'] == "设备":
|
|
469
540
|
hardtype = 1
|
|
470
|
-
elif i['ext']['BPO标注-AP-资产类型'] == "配件" :
|
|
541
|
+
elif i['ext']['BPO标注-AP-资产类型'] == "配件" or i['ext']['BPO标注-AP-资产类型'] == '2.0' :
|
|
471
542
|
hardtype = 2
|
|
472
543
|
res = GetBestMatchItemonline(key,hardtype,clientinfo)
|
|
473
544
|
else:
|
|
@@ -824,7 +895,7 @@ def write_excletolist(data_name):
|
|
|
824
895
|
try:
|
|
825
896
|
# 查看当前工作目录
|
|
826
897
|
print(f"当前工作目录: {os.getcwd()}")
|
|
827
|
-
# /Users/bytedance/
|
|
898
|
+
# /Users/bytedance/itam_assistant/itam_assistant/accessory.csv
|
|
828
899
|
# 构建文件路径
|
|
829
900
|
file_path = f'data/{data_name}.csv'
|
|
830
901
|
Candidates = []
|
it_assistant/intent_detail.py
CHANGED
|
@@ -51,14 +51,11 @@ class webapiClient():
|
|
|
51
51
|
"endAt": endAt,
|
|
52
52
|
"matchIntentID": "",
|
|
53
53
|
"matchStatus": [],
|
|
54
|
-
"pageSize": pageSize +
|
|
54
|
+
"pageSize": pageSize + 1000
|
|
55
55
|
})
|
|
56
56
|
try:
|
|
57
57
|
self.conn.request("POST","/ai/api/v1/conversational_runtime/namespaces/spring_f17d05d924__c/stats/intent_detail_list",payload, self.headers)
|
|
58
58
|
res = self.conn.getresponse()
|
|
59
|
-
#url = "https://apaas.feishu.cn/ai/api/v1/conversational_runtime/namespaces/spring_f17d05d924__c/stats/intent_detail_list"
|
|
60
|
-
#response = requests.request("POST", url, headers=self.headers, data=payload)
|
|
61
|
-
|
|
62
59
|
# 检查响应状态码
|
|
63
60
|
if res.status != 200:
|
|
64
61
|
raise http.client.HTTPException(f"请求失败,状态码: {res.status}, 原因: {res.reason}")
|
|
@@ -74,8 +71,9 @@ class webapiClient():
|
|
|
74
71
|
raise ValueError("响应数据缺少必要的字段 'data' 或 'intentDetailList'")
|
|
75
72
|
|
|
76
73
|
res_list = []
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
data_ = data['data']['intentDetailList']
|
|
75
|
+
for i in data_:
|
|
76
|
+
if i['channelType'] in ["LARK_OPEN_API"]:
|
|
79
77
|
res_list.append({
|
|
80
78
|
'对话日志/intentID': i['intentID'],
|
|
81
79
|
'用户输入/userInput': i['userInput'],
|
it_assistant/openapi.py
CHANGED
|
@@ -54,10 +54,10 @@ def get_query_vector(para, clientinfo):
|
|
|
54
54
|
'Authorization': clientinfo.get(
|
|
55
55
|
"authorization") or "Basic cm40cmFpdTRwenY1cGlsYTo2bWhvOXV3ZXFrOHZpbDllcXRxMHZ1YmVnc2xjeXBucg==",
|
|
56
56
|
'x-use-ppe': '1',
|
|
57
|
-
'x-tt-env': clientinfo.get("x_tt_env") or "
|
|
57
|
+
'x-tt-env': clientinfo.get("x_tt_env") or "ppe_openapi_vector_v2",
|
|
58
58
|
'Content-Type': 'application/json'
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
time.sleep(2.1)
|
|
61
61
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
62
62
|
return response.text
|
|
63
63
|
|
|
File without changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import lark_oapi as lark
|
|
4
|
+
from lark_oapi.api.auth.v3 import *
|
|
5
|
+
from lark_oapi.api.aily.v1 import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development
|
|
9
|
+
# 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用
|
|
10
|
+
# 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET.
|
|
11
|
+
|
|
12
|
+
pre =['spring_f17d05d924__c']
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AilyLarkClient():
|
|
16
|
+
def __init__(self,clientinfo):
|
|
17
|
+
"""
|
|
18
|
+
初始化 Client 实例,tenant_access_token 会在 Client 初始化时自动获取
|
|
19
|
+
"""
|
|
20
|
+
self.aily_app_id = clientinfo.get("aily_app_id") or "spring_f17d05d924__c"
|
|
21
|
+
self.app_id = clientinfo.get("app_id") or "cli_a6e3aea1a13c900c"
|
|
22
|
+
self.app_secret = clientinfo.get("app_secret") or "J0fAPt3BL6bv4KUJV0dJMdTUdr0pv3xx"
|
|
23
|
+
# 创建 Lark-tenant tenant客户端
|
|
24
|
+
self.tlark_client = lark.Client.builder().app_id(self.app_id).app_secret(self.app_secret).build()
|
|
25
|
+
|
|
26
|
+
# 创建 Lark-tenant user 客户端
|
|
27
|
+
self.ulark_client = lark.Client.builder().enable_set_token(True).log_level(lark.LogLevel.DEBUG).build()
|
|
28
|
+
|
|
29
|
+
def get_tenant_access_token(self):
|
|
30
|
+
# 构造请求对象
|
|
31
|
+
request: InternalTenantAccessTokenRequest = InternalTenantAccessTokenRequest.builder() \
|
|
32
|
+
.request_body(InternalTenantAccessTokenRequestBody.builder()
|
|
33
|
+
.app_id(self.app_id)
|
|
34
|
+
.app_secret(self.app_secret)
|
|
35
|
+
.build()) \
|
|
36
|
+
.build()
|
|
37
|
+
|
|
38
|
+
# 发起请求
|
|
39
|
+
response: InternalTenantAccessTokenResponse = self.tlark_client.auth.v3.tenant_access_token.internal(request)
|
|
40
|
+
|
|
41
|
+
# 处理失败返回
|
|
42
|
+
if not response.success():
|
|
43
|
+
lark.logger.error(
|
|
44
|
+
f"client.auth.v3.tenant_access_token.internal failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
45
|
+
return
|
|
46
|
+
# 处理业务结果
|
|
47
|
+
lark.logger.info(lark.JSON.marshal(response.raw, indent=4))
|
|
48
|
+
tenant_access_token = json.loads(response.raw.content).get("tenant_access_token")
|
|
49
|
+
if tenant_access_token:
|
|
50
|
+
return tenant_access_token
|
|
51
|
+
else:
|
|
52
|
+
lark.logger.error(
|
|
53
|
+
f"client.auth.v3.tenant_access_token.internal failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
def create_ailysession(self, access_token):
|
|
57
|
+
# 创建会话
|
|
58
|
+
# 构造请求对象
|
|
59
|
+
request: CreateAilySessionRequest = CreateAilySessionRequest.builder() \
|
|
60
|
+
.request_body(CreateAilySessionRequestBody.builder()
|
|
61
|
+
.channel_context("{}")
|
|
62
|
+
.metadata("{}")
|
|
63
|
+
.build()) \
|
|
64
|
+
.build()
|
|
65
|
+
|
|
66
|
+
# 发起请求
|
|
67
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
68
|
+
response: CreateAilySessionResponse = self.ulark_client.aily.v1.aily_session.create(request, option)
|
|
69
|
+
|
|
70
|
+
# 处理失败返回
|
|
71
|
+
if not response.success():
|
|
72
|
+
lark.logger.error(
|
|
73
|
+
f"client.aily.v1.aily_session.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
# 处理业务结果
|
|
77
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
78
|
+
return response.data.session.id
|
|
79
|
+
|
|
80
|
+
def create_ailysessionaily_message(self, access_token, session_id, content):
|
|
81
|
+
# 发送智能伙伴消息
|
|
82
|
+
# 构造请求对象
|
|
83
|
+
request: CreateAilySessionAilyMessageRequest = CreateAilySessionAilyMessageRequest.builder() \
|
|
84
|
+
.aily_session_id(session_id) \
|
|
85
|
+
.request_body(CreateAilySessionAilyMessageRequestBody.builder()
|
|
86
|
+
.content(content)
|
|
87
|
+
.content_type("MDX")
|
|
88
|
+
.idempotent_id("idempotent_id_1")
|
|
89
|
+
.build()) \
|
|
90
|
+
.build()
|
|
91
|
+
# 发起请求
|
|
92
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
93
|
+
response: CreateAilySessionAilyMessageResponse = self.ulark_client.aily.v1.aily_session_aily_message.create(
|
|
94
|
+
request,
|
|
95
|
+
option)
|
|
96
|
+
# 处理失败返回
|
|
97
|
+
if not response.success():
|
|
98
|
+
lark.logger.error(
|
|
99
|
+
f"client.aily.v1.aily_session_aily_message.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
100
|
+
return
|
|
101
|
+
# 处理业务结果
|
|
102
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
103
|
+
return response.data.message.id
|
|
104
|
+
|
|
105
|
+
def create_ailysession_run(self, access_token, aily_session_id):
|
|
106
|
+
# 创建运行
|
|
107
|
+
# 构造请求对象
|
|
108
|
+
request: CreateAilySessionRunRequest = CreateAilySessionRunRequest.builder() \
|
|
109
|
+
.aily_session_id(aily_session_id) \
|
|
110
|
+
.request_body(CreateAilySessionRunRequestBody.builder()
|
|
111
|
+
.app_id(self.aily_app_id)
|
|
112
|
+
.build()) \
|
|
113
|
+
.build()
|
|
114
|
+
# 发起请求
|
|
115
|
+
option = lark.RequestOption.builder().user_access_token(
|
|
116
|
+
access_token).build()
|
|
117
|
+
response: CreateAilySessionRunResponse = self.ulark_client.aily.v1.aily_session_run.create(request, option)
|
|
118
|
+
# 处理失败返回
|
|
119
|
+
if not response.success():
|
|
120
|
+
lark.logger.error(
|
|
121
|
+
f"client.aily.v1.aily_session_run.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
# 处理业务结果
|
|
125
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if __name__ == '__main__':
|
|
129
|
+
aily_app_id = AilyLarkClient({}).get_tenant_access_token()
|
itam_assistant/config.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#初始化 表单数据
|
|
3
|
+
|
|
4
|
+
Clientin = {
|
|
5
|
+
"aily_app_id": "spring_f17d05d924__c",
|
|
6
|
+
"app_id": "cli_a6e3aea1a13c900c",
|
|
7
|
+
"app_secret": "J0fAPt3BL6bv4KUJV0dJMdTUdr0pv3xx",
|
|
8
|
+
"cookie": "X-Kunlun-SessionId=L%3A3b34958803f34f43a52c.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YWwiOnsidGVuYW50X2lkIjozOTAsInVzZXJfaWQiOjE3MjIxNjYwNzMxOTk2NDUsInRlbmFudF9kb21haW5fbmFtZSI6ImFwYWFzIiwic2Vzc2lvbl92ZXJzaW9uIjoidjIwMjAtMDUtMTkiLCJ3c190b2tlbiI6Ilc6OTk3Y2MwNTA3OTRlNGFmYWFkYzEiLCJsb2dpbl90b2tlbiI6IjE3MDE3ZmFlMWJlNjVlMzdzSzBhMzA0ZjY0N2MyZmFjY2QwSjRFYmNmNGVjNzAzZDgwOWYxNDVnNDY0MzY1ZjEyNWI0YmZlZDhhTmMiLCJzb3VyY2VfY2hhbm5lbCI6ImZlaXNodSIsInRlbmFudF9rZXkiOiI3MzY1ODhjOTI2MGYxNzVkIiwiZXh0ZXJuYWxfZG9tYWluX25hbWUiOiJieXRlZGFuY2UiLCJvcmlnaW5hbF90ZW5hbnRfaWQiOjAsIm9yaWdpbmFsX3VzZXJfaWQiOjAsImlkcF9jaGFubmVsIjoiIn0sImV4cCI6MTc1ODk0MTY3MH0.l9yn5zbWFhOEJml5iA69TpFwZ7qgLMzj7L0cj4Ryozc; passport_web_did=7487801556726579201; passport_trace_id=7487801556748156956; QXV0aHpDb250ZXh0=2f506053fdd544e7aa0df84c66a287f9; locale=zh-CN; landing_url=https://accounts.feishu.cn/accounts/page/login?app_id=107&no_trap=1&redirect_uri=https%3A%2F%2Fapaas.feishu.cn%2Fai%2Fspring_f17d05d924__c%2Fmanagement%2Fchat-log; _gcl_au=1.1.1249684330.1743389657; s_v_web_id=verify_m8wh6ssk_JRUTLUkb_AJsu_4Xjm_ANzV_gLPDip941iqw; __tea__ug__uid=7487801495396992562; _ga=GA1.2.1834362348.1743389657; _gid=GA1.2.758422620.1743389658; session=XN0YXJ0-4e7g6c2c-da65-4492-a6f6-6413002bd949-WVuZA; session_list=XN0YXJ0-4e7g6c2c-da65-4492-a6f6-6413002bd949-WVuZA; login_recently=1; _ga_VPYRHN104D=GS1.1.1743389657.1.1.1743389669.48.0.0; msToken=4W_kQaUJyB5jBl5FX8vjfY6SYAFcNAp7NiDqM3-QyBN0XIF24a5SyaOeTpfzIZAuNfH-cGjXK1u3tNXV3ETo8Z2ZTQFLGSTFF2KmMr35XQsODVrddz8FdHAfyJg4F7ayxiDsicO5ObKgK0Y_95Bq1d12vKKbJ99vm9IZWEpcRFLG; kunlun-session-v2=L%3A3b34958803f34f43a52c.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YWwiOnsidGVuYW50X2lkIjozOTAsInVzZXJfaWQiOjE3MjIxNjYwNzMxOTk2NDUsInRlbmFudF9kb21haW5fbmFtZSI6ImFwYWFzIiwic2Vzc2lvbl92ZXJzaW9uIjoidjIwMjAtMDUtMTkiLCJ3c190b2tlbiI6Ilc6OTk3Y2MwNTA3OTRlNGFmYWFkYzEiLCJsb2dpbl90b2tlbiI6IjE3MDE3ZmFlMWJlNjVlMzdzSzBhMzA0ZjY0N2MyZmFjY2QwSjRFYmNmNGVjNzAzZDgwOWYxNDVnNDY0MzY1ZjEyNWI0YmZlZDhhTmMiLCJzb3VyY2VfY2hhbm5lbCI6ImZlaXNodSIsInRlbmFudF9rZXkiOiI3MzY1ODhjOTI2MGYxNzVkIiwiZXh0ZXJuYWxfZG9tYWluX25hbWUiOiJieXRlZGFuY2UiLCJvcmlnaW5hbF90ZW5hbnRfaWQiOjAsIm9yaWdpbmFsX3VzZXJfaWQiOjAsImlkcF9jaGFubmVsIjoiIn0sImV4cCI6MTc1ODk0MTY3MH0.l9yn5zbWFhOEJml5iA69TpFwZ7qgLMzj7L0cj4Ryozc; kunlun-session-token=2b32fc3c28f44fb89bab94ad072a05c9f2f844c49705c95d76bae40479a189b7; _tea_utm_cache_1229=undefined; sl_session=eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDM0MzI4NzEsInVuaXQiOiJldV9uYyIsInJhdyI6eyJtZXRhIjoiQVdIazBuRzhRUUFDQUFBQUFBQUFBQUZuNmdQWUFVNEFBV2ZxQTlnQlRnQUJaK29ENWRES3dBSUNLZ0VBUVVGQlFVRkJRVUZCUVVKdU5tZFFiRE40ZDBGQlp6MDkiLCJzdW0iOiJlMmM4YTIwMTcyMDcxNmVjYTFiOWRlOTQ5Yjc3OGJkNDczOGIzOTAwNWJiNTJhYTkyOTM2YTRhZWIzMGI2ZTY0IiwibG9jIjoiemhfY24iLCJhcGMiOiJSZWxlYXNlIiwiaWF0IjoxNzQzMzg5NjcxLCJzYWMiOnsiVXNlclN0YWZmU3RhdHVzIjoiMSIsIlVzZXJUeXBlIjoiNDIifSwibG9kIjpudWxsLCJjbmYiOnsiamt0IjoiYkx6aTdPRDBHS09mNllOQ0xGamtPZWtuQkNRSHM2ZFh5STdmcTVubE93VSJ9LCJucyI6ImxhcmsiLCJuc191aWQiOiI3MDUzOTk0MzAyMzAwNTUzMjE4IiwibnNfdGlkIjoiMSIsIm90IjozLCJjdCI6MTc0MzM4OTY3MCwicnQiOjE3NDMzODk2NzB9fQ.2pQlqU6fuqnw_iqtJe1sH1FfSSXBpFQ0RAoaRccxHEaHSBvqsdc9_7e4zjgcHOhTjISi3mGw3EC3EXftLj5Otw; passport_app_access_token=eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDM0MzI4NzIsInVuaXQiOiJldV9uYyIsInJhdyI6eyJtX2FjY2Vzc19pbmZvIjp7IjEwNyI6eyJpYXQiOjE3NDMzODk2NzIsImFjY2VzcyI6dHJ1ZX19LCJzdW0iOiJlMmM4YTIwMTcyMDcxNmVjYTFiOWRlOTQ5Yjc3OGJkNDczOGIzOTAwNWJiNTJhYTkyOTM2YTRhZWIzMGI2ZTY0In19.jtfbxALtDnZYTJx4cb6ohPy2uDVCHTuh0x-Dg7Ui1F4vMO3aka7rvOeZTIwGJ7IlAn0b-OjBOWQEVQvHthhEwQ; swp_csrf_token=a239a297-e0f7-4820-aa3a-6349c8a04977; t_beda37=10a0c227407070710f979ef9d5b530118d080fd0ec27f2c3ce04c251a5a20d70",
|
|
9
|
+
"x-kunlun-token": "17017fae1be65e37sK0a304f647c2faccd0J4Ebcf4ec703d809f145g464365f125b4bfed8aNc",
|
|
10
|
+
"x-tt-env": "ppe_cn_env_self_test_feat_cr_a",
|
|
11
|
+
"Authorization": "Basic cm40cmFpdTRwenY1cGlsYTo2bWhvOXV3ZXFrOHZpbDllcXRxMHZ1YmVnc2xjeXBucg==",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class SingletonMeta(type):
|
|
15
|
+
_instances = {}
|
|
16
|
+
|
|
17
|
+
def __call__(cls, *args, **kwargs):
|
|
18
|
+
if cls not in cls._instances:
|
|
19
|
+
cls._instances[cls] = super().__call__(*args, **kwargs)
|
|
20
|
+
return cls._instances[cls]
|
|
21
|
+
|
|
22
|
+
class Clientassign(metaclass=SingletonMeta):
|
|
23
|
+
"""
|
|
24
|
+
定义一个全局变量 Client
|
|
25
|
+
该类为单例类,确保整个应用中只有一个实例
|
|
26
|
+
"""
|
|
27
|
+
def __init__(self, Clientinfox):
|
|
28
|
+
|
|
29
|
+
self.aily_app_id = Clientinfox.get("data_set_ailyappid") or Clientin["aily_app_id"]
|
|
30
|
+
self.app_id = Clientinfox.get("data_set_appid") or Clientin["app_id"]
|
|
31
|
+
self.app_secret = Clientinfox.get("data_set_appsecret") or Clientin["app_secret"]
|
|
32
|
+
self.cookie = Clientinfox.get("data_set_cookie") or Clientin["cookie"]
|
|
33
|
+
self.x_kunlun_token = Clientinfox.get("data_set_kunluntoken") or Clientin["x-kunlun-token"]
|
|
34
|
+
self.x_tt_env = Clientinfox.get("data_set_ppeenv") or Clientin["x-tt-env"]
|
|
35
|
+
self.authorization = Clientinfox.get("data_set_auth") or Clientin["Authorization"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
Clientinfox = {
|
|
40
|
+
"data_set_ailyappid": "123",
|
|
41
|
+
"data_set_appid": "456",
|
|
42
|
+
"data_set_appsecret": "789",
|
|
43
|
+
"data_set_cookie": "012",
|
|
44
|
+
"data_set_kunluntoken": "345",
|
|
45
|
+
"data_set_ppeenv": "678",
|
|
46
|
+
"data_set_auth": "901",
|
|
47
|
+
}
|
|
48
|
+
b=Clientassign(Clientinfox)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|