itam-assistant 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- it_assistant/do_ai.py +5 -5
- itam_assistant/__init__.py +0 -0
- itam_assistant/ailyapp_client.py +129 -0
- itam_assistant/config.py +51 -0
- itam_assistant/do_ai.py +928 -0
- itam_assistant/intent_detail.py +289 -0
- itam_assistant/lark_client.py +159 -0
- itam_assistant/logger.py +53 -0
- itam_assistant/openapi.py +687 -0
- itam_assistant/test.py +1 -0
- {itam_assistant-0.1.4.dist-info → itam_assistant-0.1.5.dist-info}/METADATA +1 -1
- itam_assistant-0.1.5.dist-info/RECORD +28 -0
- itam_assistant-0.1.5.dist-info/top_level.txt +1 -0
- main/do_ai.py +3 -3
- itam_assistant-0.1.4.dist-info/RECORD +0 -19
- itam_assistant-0.1.4.dist-info/top_level.txt +0 -1
- {itam_assistant-0.1.4.dist-info → itam_assistant-0.1.5.dist-info}/WHEEL +0 -0
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
|
|
@@ -895,7 +895,7 @@ def write_excletolist(data_name):
|
|
|
895
895
|
try:
|
|
896
896
|
# 查看当前工作目录
|
|
897
897
|
print(f"当前工作目录: {os.getcwd()}")
|
|
898
|
-
# /Users/bytedance/
|
|
898
|
+
# /Users/bytedance/itam_assistant/itam_assistant/accessory.csv
|
|
899
899
|
# 构建文件路径
|
|
900
900
|
file_path = f'data/{data_name}.csv'
|
|
901
901
|
Candidates = []
|
|
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-cGjXK1u3tNXV3ETo8Z2ZTQFLGSTFF2KmMr35XQsODVrddz8FdHAfyJg4F7ayxiD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Yjc3OGJkNDczOGIzOTAwNWJiNTJhYTkyOTM2YTRhZWIzMGI2ZTY0IiwibG9jIjoiemhfY24iLCJhcGMiOiJSZWxlYXNlIiwiaWF0IjoxNzQzMzg5NjcxLCJzYWMiOnsiVXNlclN0YWZmU3RhdHVzIjoiMSIsIlVzZXJUeXBlIjoiNDIifSwibG9kIjpudWxsLCJjbmYiOnsiamt0IjoiYkx6aTdPRDBHS09mNllOQ0xGamtPZWtuQkNRSHM2ZFh5STdmcTVubE93VSJ9LCJucyI6ImxhcmsiLCJuc191aWQiOiI3MDUzOTk0MzAyMzAwNTUzMjE4IiwibnNfdGlkIjoiMSIsIm90IjozLCJjdCI6MTc0MzM4OTY3MCwicnQiOjE3NDMzODk2NzB9fQ.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
|
+
|