itam-assistant 0.1.1__tar.gz
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.
- itam_assistant-0.1.1/PKG-INFO +25 -0
- itam_assistant-0.1.1/README.md +1 -0
- itam_assistant-0.1.1/it_assistant/__init__.py +0 -0
- itam_assistant-0.1.1/it_assistant/ailyapp_client.py +127 -0
- itam_assistant-0.1.1/it_assistant/config.py +51 -0
- itam_assistant-0.1.1/it_assistant/do_ai.py +490 -0
- itam_assistant-0.1.1/it_assistant/intent_detail.py +290 -0
- itam_assistant-0.1.1/it_assistant/lark_client.py +159 -0
- itam_assistant-0.1.1/it_assistant/logger.py +53 -0
- itam_assistant-0.1.1/it_assistant/openapi.py +459 -0
- itam_assistant-0.1.1/it_assistant/test.py +1 -0
- itam_assistant-0.1.1/itam_assistant.egg-info/PKG-INFO +25 -0
- itam_assistant-0.1.1/itam_assistant.egg-info/SOURCES.txt +17 -0
- itam_assistant-0.1.1/itam_assistant.egg-info/dependency_links.txt +1 -0
- itam_assistant-0.1.1/itam_assistant.egg-info/requires.txt +2 -0
- itam_assistant-0.1.1/itam_assistant.egg-info/top_level.txt +1 -0
- itam_assistant-0.1.1/setup.cfg +4 -0
- itam_assistant-0.1.1/setup.py +23 -0
- itam_assistant-0.1.1/test/test.py +75 -0
|
@@ -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 @@
|
|
|
1
|
+
详见https://bytedance.feishu.cn/docs/doccnSOL0o2qtnElftgd2rir2Dc
|
|
File without changes
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
|
|
13
|
+
class AilyLarkClient():
|
|
14
|
+
def __init__(self,clientinfo):
|
|
15
|
+
"""
|
|
16
|
+
初始化 Client 实例,tenant_access_token 会在 Client 初始化时自动获取
|
|
17
|
+
"""
|
|
18
|
+
self.aily_app_id = clientinfo.get("aily_app_id") or "spring_f17d05d924__c"
|
|
19
|
+
self.app_id = clientinfo.get("app_id") or "cli_a6e3aea1a13c900c"
|
|
20
|
+
self.app_secret = clientinfo.get("app_secret") or "J0fAPt3BL6bv4KUJV0dJMdTUdr0pv3xx"
|
|
21
|
+
# 创建 Lark-tenant tenant客户端
|
|
22
|
+
self.tlark_client = lark.Client.builder().app_id(self.app_id).app_secret(self.app_secret).build()
|
|
23
|
+
|
|
24
|
+
# 创建 Lark-tenant user 客户端
|
|
25
|
+
self.ulark_client = lark.Client.builder().enable_set_token(True).log_level(lark.LogLevel.DEBUG).build()
|
|
26
|
+
|
|
27
|
+
def get_tenant_access_token(self):
|
|
28
|
+
# 构造请求对象
|
|
29
|
+
request: InternalTenantAccessTokenRequest = InternalTenantAccessTokenRequest.builder() \
|
|
30
|
+
.request_body(InternalTenantAccessTokenRequestBody.builder()
|
|
31
|
+
.app_id(self.app_id)
|
|
32
|
+
.app_secret(self.app_secret)
|
|
33
|
+
.build()) \
|
|
34
|
+
.build()
|
|
35
|
+
|
|
36
|
+
# 发起请求
|
|
37
|
+
response: InternalTenantAccessTokenResponse = self.tlark_client.auth.v3.tenant_access_token.internal(request)
|
|
38
|
+
|
|
39
|
+
# 处理失败返回
|
|
40
|
+
if not response.success():
|
|
41
|
+
lark.logger.error(
|
|
42
|
+
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)}")
|
|
43
|
+
return
|
|
44
|
+
# 处理业务结果
|
|
45
|
+
lark.logger.info(lark.JSON.marshal(response.raw, indent=4))
|
|
46
|
+
tenant_access_token = json.loads(response.raw.content).get("tenant_access_token")
|
|
47
|
+
if tenant_access_token:
|
|
48
|
+
return tenant_access_token
|
|
49
|
+
else:
|
|
50
|
+
lark.logger.error(
|
|
51
|
+
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)}")
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
def create_ailysession(self, access_token):
|
|
55
|
+
# 创建会话
|
|
56
|
+
# 构造请求对象
|
|
57
|
+
request: CreateAilySessionRequest = CreateAilySessionRequest.builder() \
|
|
58
|
+
.request_body(CreateAilySessionRequestBody.builder()
|
|
59
|
+
.channel_context("{}")
|
|
60
|
+
.metadata("{}")
|
|
61
|
+
.build()) \
|
|
62
|
+
.build()
|
|
63
|
+
|
|
64
|
+
# 发起请求
|
|
65
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
66
|
+
response: CreateAilySessionResponse = self.ulark_client.aily.v1.aily_session.create(request, option)
|
|
67
|
+
|
|
68
|
+
# 处理失败返回
|
|
69
|
+
if not response.success():
|
|
70
|
+
lark.logger.error(
|
|
71
|
+
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)}")
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
# 处理业务结果
|
|
75
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
76
|
+
return response.data.session.id
|
|
77
|
+
|
|
78
|
+
def create_ailysessionaily_message(self, access_token, session_id, content):
|
|
79
|
+
# 发送智能伙伴消息
|
|
80
|
+
# 构造请求对象
|
|
81
|
+
request: CreateAilySessionAilyMessageRequest = CreateAilySessionAilyMessageRequest.builder() \
|
|
82
|
+
.aily_session_id(session_id) \
|
|
83
|
+
.request_body(CreateAilySessionAilyMessageRequestBody.builder()
|
|
84
|
+
.content(content)
|
|
85
|
+
.content_type("MDX")
|
|
86
|
+
.idempotent_id("idempotent_id_1")
|
|
87
|
+
.build()) \
|
|
88
|
+
.build()
|
|
89
|
+
# 发起请求
|
|
90
|
+
option = lark.RequestOption.builder().user_access_token(access_token).build()
|
|
91
|
+
response: CreateAilySessionAilyMessageResponse = self.ulark_client.aily.v1.aily_session_aily_message.create(
|
|
92
|
+
request,
|
|
93
|
+
option)
|
|
94
|
+
# 处理失败返回
|
|
95
|
+
if not response.success():
|
|
96
|
+
lark.logger.error(
|
|
97
|
+
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)}")
|
|
98
|
+
return
|
|
99
|
+
# 处理业务结果
|
|
100
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
101
|
+
return response.data.message.id
|
|
102
|
+
|
|
103
|
+
def create_ailysession_run(self, access_token, aily_session_id):
|
|
104
|
+
# 创建运行
|
|
105
|
+
# 构造请求对象
|
|
106
|
+
request: CreateAilySessionRunRequest = CreateAilySessionRunRequest.builder() \
|
|
107
|
+
.aily_session_id(aily_session_id) \
|
|
108
|
+
.request_body(CreateAilySessionRunRequestBody.builder()
|
|
109
|
+
.app_id(self.aily_app_id)
|
|
110
|
+
.build()) \
|
|
111
|
+
.build()
|
|
112
|
+
# 发起请求
|
|
113
|
+
option = lark.RequestOption.builder().user_access_token(
|
|
114
|
+
access_token).build()
|
|
115
|
+
response: CreateAilySessionRunResponse = self.ulark_client.aily.v1.aily_session_run.create(request, option)
|
|
116
|
+
# 处理失败返回
|
|
117
|
+
if not response.success():
|
|
118
|
+
lark.logger.error(
|
|
119
|
+
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)}")
|
|
120
|
+
return
|
|
121
|
+
|
|
122
|
+
# 处理业务结果
|
|
123
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == '__main__':
|
|
127
|
+
aily_app_id = AilyLarkClient({}).get_tenant_access_token()
|
|
@@ -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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In19.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
|
+
|