|
@@ -1,4 +1,4 @@
|
|
|
-from typing import List
|
|
|
+from typing import List, Optional
|
|
|
import requests
|
|
|
|
|
|
from pqai_agent.toolkit.base import BaseToolkit
|
|
@@ -13,22 +13,39 @@ class LarkAlertForHumanIntervention(BaseToolkit):
|
|
|
super().__init__()
|
|
|
|
|
|
def send_lark_alert_for_human_intervention(
|
|
|
- self, message: str
|
|
|
+ self, message: str, ack_url: Optional[str] = None
|
|
|
) -> str:
|
|
|
r"""Sends a Lark alert for human intervention.
|
|
|
|
|
|
Args:
|
|
|
message (str): The message to send.
|
|
|
+ ack_url (str): The URL to acknowledge the alert.
|
|
|
Returns:
|
|
|
str: A confirmation message.
|
|
|
"""
|
|
|
if not self.webhook_url:
|
|
|
return "Webhook URL not configured."
|
|
|
|
|
|
+ contents = [{
|
|
|
+ "tag": "text",
|
|
|
+ "text": f"{message}\n"
|
|
|
+ }]
|
|
|
+ if ack_url:
|
|
|
+ contents.append({
|
|
|
+ "tag": "a",
|
|
|
+ "text": "[处理完成点击此处]",
|
|
|
+ "href": ack_url
|
|
|
+ })
|
|
|
+
|
|
|
req_body = {
|
|
|
- "msg_type": "text",
|
|
|
+ "msg_type": "post",
|
|
|
"content": {
|
|
|
- "text": f'[Agent告警]{message}'
|
|
|
+ "post": {
|
|
|
+ "zh_cn": {
|
|
|
+ "title": f'Agent告警',
|
|
|
+ "content": [contents]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
try:
|
|
@@ -48,5 +65,7 @@ if __name__ == '__main__':
|
|
|
tools = toolkit.get_tools()
|
|
|
for tool in tools:
|
|
|
print(f"Tool schema: {tool.get_openai_tool_schema()}")
|
|
|
- resp = toolkit.send_lark_alert_for_human_intervention('测试')
|
|
|
+ ack_url = "http://ai-wechat-hook-internal.piaoquantv.com/manage/insertEvent?" \
|
|
|
+ f"sender=1688855931724582&receiver=1688854492669990&type=103&content=OPERATION"
|
|
|
+ resp = toolkit.send_lark_alert_for_human_intervention('测试', ack_url)
|
|
|
print(resp)
|