Skip to content

Commit 628e7cd

Browse files
authored
feat: application node (#3480)
1 parent e21d53b commit 628e7cd

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

apps/application/flow/step_node/application_node/impl/base_application_node.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,19 @@ def save_context(self, details, workflow_manage):
171171
if self.node_params.get('is_result', False):
172172
self.answer_text = details.get('answer')
173173

174-
def execute(self, application_id, message, chat_id, chat_record_id, stream, re_chat, client_id, client_type,
174+
def execute(self, application_id, message, chat_id, chat_record_id, stream, re_chat,
175+
chat_user_id,
176+
chat_user_type,
175177
app_document_list=None, app_image_list=None, app_audio_list=None, child_node=None, node_data=None,
176178
**kwargs) -> NodeResult:
177-
from application.serializers.chat_message_serializers import ChatMessageSerializer
179+
from chat.serializers.chat import ChatSerializers
178180
# 生成嵌入应用的chat_id
179181
current_chat_id = string_to_uuid(chat_id + application_id)
180182
Chat.objects.get_or_create(id=current_chat_id, defaults={
181183
'application_id': application_id,
182184
'abstract': message[0:1024],
183-
'client_id': client_id,
185+
'chat_user_id': chat_user_id,
186+
'chat_user_type': chat_user_type
184187
})
185188
if app_document_list is None:
186189
app_document_list = []
@@ -197,22 +200,26 @@ def execute(self, application_id, message, chat_id, chat_record_id, stream, re_c
197200
child_node_value = child_node.get('child_node')
198201
application_node_dict = self.context.get('application_node_dict')
199202
reset_application_node_dict(application_node_dict, runtime_node_id, node_data)
203+
response = ChatSerializers(data={
204+
"chat_id": current_chat_id,
205+
"chat_user_id": chat_user_id,
206+
'chat_user_type': chat_user_type,
207+
'application_id': application_id,
208+
'debug': False
209+
}).chat(instance=
210+
{'message': message,
211+
're_chat': re_chat,
212+
'stream': stream,
213+
'document_list': app_document_list,
214+
'image_list': app_image_list,
215+
'audio_list': app_audio_list,
216+
'runtime_node_id': runtime_node_id,
217+
'chat_record_id': record_id,
218+
'child_node': child_node_value,
219+
'node_data': node_data,
220+
'form_data': kwargs}
221+
)
200222

201-
response = ChatMessageSerializer(
202-
data={'chat_id': current_chat_id, 'message': message,
203-
're_chat': re_chat,
204-
'stream': stream,
205-
'application_id': application_id,
206-
'client_id': client_id,
207-
'client_type': client_type,
208-
'document_list': app_document_list,
209-
'image_list': app_image_list,
210-
'audio_list': app_audio_list,
211-
'runtime_node_id': runtime_node_id,
212-
'chat_record_id': record_id,
213-
'child_node': child_node_value,
214-
'node_data': node_data,
215-
'form_data': kwargs}).chat()
216223
if response.status_code == 200:
217224
if stream:
218225
content_generator = response.streaming_content

apps/chat/serializers/chat.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def re_open_chat(self, chat_id: str):
274274
application = QuerySet(Application).filter(id=chat.application_id).first()
275275
if application is None:
276276
raise ChatException(500, _("Application does not exist"))
277+
application_version = QuerySet(ApplicationVersion).filter(application_id=application.id).order_by(
278+
'-create_time')[0:1].first()
279+
if application_version is None:
280+
raise ChatException(500, _("The application has not been published. Please use it after publishing."))
277281
if application.type == ApplicationTypeChoices.SIMPLE:
278282
return self.re_open_chat_simple(chat_id, application)
279283
else:
@@ -299,11 +303,6 @@ def re_open_chat_simple(self, chat_id, application):
299303
return chat_info
300304

301305
def re_open_chat_work_flow(self, chat_id, application):
302-
application_version = QuerySet(ApplicationVersion).filter(application_id=application.id).order_by(
303-
'-create_time')[0:1].first()
304-
if application_version is None:
305-
raise ChatException(500, _("The application has not been published. Please use it after publishing."))
306-
307306
chat_info = ChatInfo(chat_id, self.data.get('chat_user_id'), self.data.get('chat_user_type'), [], [],
308307
application.id)
309308
chat_record_list = list(QuerySet(ChatRecord).filter(chat_id=chat_id).order_by('-create_time')[0:5])
@@ -334,6 +333,14 @@ def open(self):
334333
self.is_valid(raise_exception=True)
335334
application_id = self.data.get('application_id')
336335
application = QuerySet(Application).get(id=application_id)
336+
debug = self.data.get("debug")
337+
if not debug:
338+
application_version = QuerySet(ApplicationVersion).filter(application_id=application_id).order_by(
339+
'-create_time')[0:1].first()
340+
if application_version is None:
341+
raise AppApiException(500,
342+
gettext(
343+
"The application has not been published. Please use it after publishing."))
337344
if application.type == ApplicationTypeChoices.SIMPLE:
338345
return self.open_simple(application)
339346
else:
@@ -346,13 +353,6 @@ def open_work_flow(self, application):
346353
chat_user_type = self.data.get("chat_user_type")
347354
debug = self.data.get("debug")
348355
chat_id = str(uuid.uuid7())
349-
if not debug:
350-
application_version = QuerySet(ApplicationVersion).filter(application_id=application_id).order_by(
351-
'-create_time')[0:1].first()
352-
if application_version is None:
353-
raise AppApiException(500,
354-
gettext(
355-
"The application has not been published. Please use it after publishing."))
356356
ChatInfo(chat_id, chat_user_id, chat_user_type, [],
357357
[],
358358
application_id, debug).set_cache()

0 commit comments

Comments
 (0)