diff --git a/apps/application/flow/i_step_node.py b/apps/application/flow/i_step_node.py index b499c96a6..84121ea8c 100644 --- a/apps/application/flow/i_step_node.py +++ b/apps/application/flow/i_step_node.py @@ -103,9 +103,9 @@ class FlowParamsSerializer(serializers.Serializer): stream = serializers.BooleanField(required=True, error_messages=ErrMessage.base("流式输出")) - client_id = serializers.CharField(required=True, error_messages=ErrMessage.char("客户端id")) + client_id = serializers.CharField(required=False, error_messages=ErrMessage.char("客户端id")) - client_type = serializers.CharField(required=True, error_messages=ErrMessage.char("客户端类型")) + client_type = serializers.CharField(required=False, error_messages=ErrMessage.char("客户端类型")) class INode: diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index c6e934582..def9e50c9 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -127,13 +127,13 @@ class BaseChatNode(IChatNode): if stream: r = chat_model.stream(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question}, {}, + 'history_message': history_message, 'question': question.content}, {}, _write_context=write_context_stream, _to_response=to_stream_response) else: r = chat_model.invoke(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question}, {}, + 'history_message': history_message, 'question': question.content}, {}, _write_context=write_context, _to_response=to_response) @staticmethod diff --git a/apps/application/flow/step_node/question_node/impl/base_question_node.py b/apps/application/flow/step_node/question_node/impl/base_question_node.py index 371e55ac0..36071ec49 100644 --- a/apps/application/flow/step_node/question_node/impl/base_question_node.py +++ b/apps/application/flow/step_node/question_node/impl/base_question_node.py @@ -126,13 +126,13 @@ class BaseQuestionNode(IQuestionNode): r = chat_model.stream(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, 'get_to_response_write_context': get_to_response_write_context, - 'history_message': history_message, 'question': question}, {}, + 'history_message': history_message, 'question': question.content}, {}, _write_context=write_context_stream, _to_response=to_stream_response) else: r = chat_model.invoke(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question}, {}, + 'history_message': history_message, 'question': question.content}, {}, _write_context=write_context, _to_response=to_response) @staticmethod diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index 88957d040..a0231310b 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -143,13 +143,18 @@ class WorkflowManage: @param prompt: 提示词信息 @return: 格式化后的提示词 """ - prompt_template = PromptTemplate.from_template(prompt, template_format='jinja2') context = { 'global': self.context, } for node in self.node_context: + fields = node.node.properties.get('fields') + if fields is not None: + for field in fields: + prompt = prompt.replace(field.get('globeLabel'), field.get('globeValue')) context[node.id] = node.context + prompt_template = PromptTemplate.from_template(prompt, template_format='jinja2') + value = prompt_template.format(context=context) return value diff --git a/apps/application/serializers/chat_message_serializers.py b/apps/application/serializers/chat_message_serializers.py index eb3f0bac4..41155acd9 100644 --- a/apps/application/serializers/chat_message_serializers.py +++ b/apps/application/serializers/chat_message_serializers.py @@ -231,7 +231,7 @@ class ChatMessageSerializer(serializers.Serializer): stream = self.data.get('stream') client_id = self.data.get('client_id') client_type = self.data.get('client_type') - work_flow_manage = WorkflowManage(Flow.new_instance(json.loads(chat_info.application.work_flow)), + work_flow_manage = WorkflowManage(Flow.new_instance(chat_info.application.work_flow), {'history_chat_record': chat_info.chat_record_list, 'question': message, 'chat_id': chat_info.chat_id, 'chat_record_id': str(uuid.uuid1()), 'stream': stream, @@ -241,7 +241,7 @@ class ChatMessageSerializer(serializers.Serializer): def chat(self): super().is_valid(raise_exception=True) - application = QuerySet(Application).filter(self.data.get('application_id')) + application = QuerySet(Application).filter(id=self.data.get('application_id')).first() if application.type == ApplicationTypeChoices.SIMPLE: chat_info = self.is_valid_application_simple(raise_exception=True) return self.chat_simple(chat_info) diff --git a/ui/src/workflow/common/app-node.ts b/ui/src/workflow/common/app-node.ts index 06c04d7df..620ac1216 100644 --- a/ui/src/workflow/common/app-node.ts +++ b/ui/src/workflow/common/app-node.ts @@ -38,12 +38,12 @@ class AppNode extends HtmlNode { if (filterNodes.length - 1 > 0) { props.model.properties.stepName = props.model.properties.stepName + (filterNodes.length - 1) } - if (props.model.properties?.fields?.length > 0) { - props.model.properties.fields.map((item: any) => { - item['globeLabel'] = `{{${props.model.properties.stepName}.${item.value}}}` - item['globeValue'] = `{{context['${props.model.id}'].${item.value}}}` - }) - } + } + if (props.model.properties?.fields?.length > 0) { + props.model.properties.fields.map((item: any) => { + item['globeLabel'] = `{{${props.model.properties.stepName}.${item.value}}}` + item['globeValue'] = `{{context['${props.model.id}'].${item.value}}}` + }) } }