Skip to content

Commit 262f2bf

Browse files
committed
feat: 支持 AI 技能开发和直通模式
Signed-off-by: Ke Jie <[email protected]>
1 parent e9a24f3 commit 262f2bf

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

dingtalk_stream/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from .chatbot import TextContent
1313
from .chatbot import AtUser
1414
from .chatbot import ChatbotHandler, AsyncChatbotHandler
15+
from .graph import RequestLine, StatusLine, GraphMessage, GraphRequest, GraphResponse
16+
from .graph import GraphHandler
1517
from .card_replier import AICardStatus, AICardReplier, CardReplier
1618
from .card_instance import MarkdownCardInstance, AIMarkdownCardInstance, CarouselCardInstance, \
1719
MarkdownButtonCardInstance, RPAPluginCardInstance

dingtalk_stream/graph.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import json
4+
from .stream import CallbackHandler, CallbackMessage
5+
6+
class GraphMessage(object):
7+
TOPIC = '/v1.0/graph/api/invoke'
8+
9+
class RequestLine(object):
10+
def __init__(self):
11+
self.method = 'GET'
12+
self.uri = '/'
13+
self.extensions = {}
14+
15+
@classmethod
16+
def from_dict(cls, d):
17+
msg = RequestLine()
18+
for name, value in d.items():
19+
if name == 'method':
20+
msg.method = value
21+
elif name == 'uri':
22+
msg.uri = value
23+
else:
24+
msg.extensions[name] = value
25+
return msg
26+
27+
def to_dict(self):
28+
result = self.extensions.copy()
29+
if self.method is not None:
30+
result['method'] = self.method
31+
if self.uri is not None:
32+
result['uri'] = self.uri
33+
return result
34+
35+
class StatusLine(object):
36+
def __init__(self):
37+
self.code = 200
38+
self.reason_phrase = 'OK'
39+
self.extensions = {}
40+
41+
@classmethod
42+
def from_dict(cls, d):
43+
msg = RequestLine()
44+
for name, value in d.items():
45+
if name == 'code':
46+
msg.code = value
47+
elif name == 'reasonPhrase':
48+
msg.reason_phrase = value
49+
else:
50+
msg.extensions[name] = value
51+
return msg
52+
53+
def to_dict(self):
54+
result = self.extensions.copy()
55+
if self.code is not None:
56+
result['code'] = self.code
57+
if self.reason_phrase is not None:
58+
result['reasonPhrase'] = self.reason_phrase
59+
return result
60+
61+
class GraphRequest(object):
62+
def __init__(self):
63+
self.body = None
64+
self.request_line = RequestLine()
65+
self.headers = {}
66+
self.extensions = {}
67+
68+
@classmethod
69+
def from_dict(cls, d):
70+
msg = GraphRequest()
71+
for name, value in d.items():
72+
if name == 'body':
73+
msg.body = value
74+
elif name == 'headers':
75+
msg.headers = value
76+
elif name == 'requestLine':
77+
msg.request_line = RequestLine.from_dict(value)
78+
else:
79+
msg.extensions[name] = value
80+
return msg
81+
82+
def to_dict(self):
83+
result = self.extensions.copy()
84+
if self.body is not None:
85+
result['body'] = self.body
86+
if self.headers is not None:
87+
result['headers'] = self.headers
88+
if self.request_line is not None:
89+
result['requestLine'] = self.request_line.to_dict()
90+
return result
91+
92+
class GraphResponse(object):
93+
def __init__(self):
94+
self.body = None
95+
self.headers = {}
96+
self.status_line = StatusLine()
97+
self.extensions = {}
98+
99+
@classmethod
100+
def from_dict(cls, d):
101+
msg = GraphResponse()
102+
for name, value in d.items():
103+
if name == 'body':
104+
msg.body = value
105+
elif name == 'headers':
106+
msg.headers = value
107+
elif name == 'statusLine':
108+
msg.status_line = StatusLine.from_dict(value)
109+
else:
110+
msg.extensions[name] = value
111+
return msg
112+
113+
def to_dict(self):
114+
result = self.extensions.copy()
115+
if self.body is not None:
116+
result['body'] = self.body
117+
if self.headers is not None:
118+
result['headers'] = self.headers
119+
if self.status_line is not None:
120+
result['statusLine'] = self.status_line.to_dict()
121+
return result
122+
123+
124+
class GraphHandler(CallbackHandler):
125+
126+
def __init__(self):
127+
super(GraphHandler, self).__init__()
128+
129+

dingtalk_stream/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION_STRING = '0.21.0'
1+
VERSION_STRING = '0.22.0'

0 commit comments

Comments
 (0)