Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def execute(self, model_id, system, prompt, dialogue_number, history_chat_record
**model_params_setting)
history_message = self.get_history_message(history_chat_record, dialogue_number, dialogue_type,
self.runtime_node_id)
self.context['history_message'] = history_message
self.context['history_message'] = [{'content': message.content, 'role': message.type} for message in
(history_message if history_message is not None else [])]
question = self.generate_prompt_question(prompt)
self.context['question'] = question.content
system = self.workflow_manage.generate_prompt(system)
Expand All @@ -197,8 +198,6 @@ def execute(self, model_id, system, prompt, dialogue_number, history_chat_record
if stream:
r = chat_model.stream(message_list)
return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list,
'history_message': [{'content': message.content, 'role': message.type} for message in
(history_message if history_message is not None else [])],
'question': question.content}, {},
_write_context=write_context_stream)
else:
Expand Down
15 changes: 13 additions & 2 deletions apps/application/flow/workflow_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def init_fields(self):
node_name = properties.get('stepName')
node_id = node.id
node_config = properties.get('config')
field_list.append(
{'label': '异常信息', 'value': 'exception_message', 'node_id': node_id, 'node_name': node_name})
if node_config is not None:
fields = node_config.get('fields')
if fields is not None:
Expand Down Expand Up @@ -473,7 +475,12 @@ def hand_event_node_result(self, current_node, node_result_future):
else:
list(result)
if current_node.status == 500:
return None
current_node.context['exception_message'] = current_node.err_message
current_node.context['branch_id'] = 'exception'
r = NodeResult({'branch_id': 'exception', 'exception': current_node.err_message}, {},
_is_interrupt=lambda node, step_variable, global_variable: False)
r.write_context(current_node, self)
return r
return current_result
except Exception as e:
# 添加节点
Expand All @@ -494,7 +501,11 @@ def hand_event_node_result(self, current_node, node_result_future):
current_node.node_chunk.add_chunk(chunk)
current_node.get_write_error_context(e)
self.status = 500
return None
current_node.context['exception_message'] = current_node.err_message
current_node.context['branch_id'] = 'exception'
return NodeResult({'branch_id': 'exception', 'exception': current_node.err_message}, {},
_is_interrupt=lambda node, step_variable, global_variable: False)

finally:
current_node.node_chunk.end()
# 归还链接到连接池
Expand Down
76 changes: 68 additions & 8 deletions ui/src/workflow/common/NodeContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@
/>
<slot></slot>
<template v-if="nodeFields.length > 0">
<h5 class="title-decoration-1 mb-8 mt-8">
{{ $t('common.param.outputParam') }}
</h5>
<div class="flex-between">
<h5 class="title-decoration-1 mb-8 mt-8">
{{ $t('common.param.outputParam') }}
</h5>
<el-switch
v-if="exceptionNodeList.includes(nodeModel.type)"
v-model="enable_exception"
/>
</div>

<template v-for="(item, index) in nodeFields" :key="index">
<div
class="flex-between border-r-6 p-8-12 mb-8 layout-bg lighter"
Expand Down Expand Up @@ -128,7 +135,8 @@
:show="showAnchor"
:inner="true"
:id="id"
style="left: 100%; top: 50%; transform: translate(0, -50%)"
style="left: 100%; transform: translate(0, -50%)"
:style="dropdownMenuStyle"
@clickNodes="clickNodes"
/>
</el-collapse-transition>
Expand Down Expand Up @@ -170,7 +178,7 @@
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted, inject } from 'vue'
import { ref, computed, onMounted, watch, nextTick } from 'vue'
import { set } from 'lodash'
import { iconComponent } from '../icons/utils'
import { copyClick } from '@/utils/clipboard'
Expand All @@ -180,6 +188,7 @@ import type { FormInstance } from 'element-plus'
import { t } from '@/locales'
import { useRoute } from 'vue-router'
import DropdownMenu from '@/components/workflow-dropdown-menu/index.vue'

const route = useRoute()
const {
params: { id },
Expand All @@ -196,6 +205,13 @@ const height = ref<{
})
const showAnchor = ref<boolean>(false)
const anchorData = ref<any>()
const dropdownMenuStyle = computed(() => {
return {
top: anchorData.value
? anchorData.value.y - props.nodeModel.y + props.nodeModel.height / 2 + 'px'
: '0px',
}
})
const titleFormRef = ref()
const nodeNameDialogVisible = ref<boolean>(false)
const form = ref<any>({
Expand Down Expand Up @@ -324,10 +340,33 @@ function clickNodes(item: any) {

closeNodeMenu()
}
const enable_exception = computed({
set: (v) => {
set(props.nodeModel.properties, 'enableException', v)
},
get: () => {
if (props.nodeModel.properties.enableException !== undefined) {
return props.nodeModel.properties.enableException
}
set(props.nodeModel.properties, 'enableException', false)
return false
},
})
const props = withDefaults(
defineProps<{
nodeModel: any
exceptionNodeList?: string[]
}>(),
{
exceptionNodeList: () => [
'ai-chat-node',
'video-understand-node',
'image-generate-node',
'image-understand-node',
],
},
)

const props = defineProps<{
nodeModel: any
}>()
const nodeFields = computed(() => {
if (props.nodeModel.properties.config.fields) {
const fields = props.nodeModel.properties.config.fields?.map((field: any) => {
Expand All @@ -338,10 +377,31 @@ const nodeFields = computed(() => {
globeValue: `{{context['${props.nodeModel.id}'].${field.value}}}`,
}
})
if (enable_exception.value) {
return [
...fields,
{
label: '异常信息',
value: 'exception_message',
globeLabel: `{{${props.nodeModel.properties.stepName}.exception_message}}`,
globeValue: `{{context['${props.nodeModel.id}'].exception_message}}`,
},
]
}
return fields
}
return []
})
watch(enable_exception, () => {
props.nodeModel.graphModel.eventCenter.emit(
'delete_edge',
props.nodeModel.outgoing.edges
.filter((item: any) =>
[`${props.nodeModel.id}_exception_right`].includes(item.sourceAnchorId),
)
.map((item: any) => item.id),
)
})

function showOperate(type: string) {
return ![
Expand Down
13 changes: 11 additions & 2 deletions ui/src/workflow/common/app-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class AppNode extends HtmlResize.view {
? `<svg width="100%" height="100%" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_5119_232585)">
<path d="M20.9998 29.8333C28.0875 29.8333 33.8332 24.0876 33.8332 17C33.8332 9.91231 28.0875 4.16663 20.9998 4.16663C13.9122 4.16663 8.1665 9.91231 8.1665 17C8.1665 24.0876 13.9122 29.8333 20.9998 29.8333Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.9998 27.5C26.7988 27.5 31.4998 22.799 31.4998 17C31.4998 11.201 26.7988 6.49996 20.9998 6.49996C15.2008 6.49996 10.4998 11.201 10.4998 17C10.4998 22.799 15.2008 27.5 20.9998 27.5ZM33.8332 17C33.8332 24.0876 28.0875 29.8333 20.9998 29.8333C13.9122 29.8333 8.1665 24.0876 8.1665 17C8.1665 9.91231 13.9122 4.16663 20.9998 4.16663C28.0875 4.16663 33.8332 9.91231 33.8332 17Z" fill="#3370FF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.9998 27.5C26.7988 27.5 31.4998 22.799 31.4998 17C31.4998 11.201 26.7988 6.49996 20.9998 6.49996C15.2008 6.49996 10.4998 11.201 10.4998 17C10.4998 22.799 15.2008 27.5 20.9998 27.5ZM33.8332 17C33.8332 24.0876 28.0875 29.8333 20.9998 29.8333C13.9122 29.8333 8.1665 24.0876 8.1665 17C8.1665 9.91231 13.9122 4.16663 20.9998 4.16663C28.0875 4.16663 33.8332 9.91231 33.8332 17Z" fill="${anchorData.id.endsWith('_exception_right') ? '#FF8800' : '#3370FF'}"/>
</g>
<defs>
<filter id="filter0_d_5119_232585" x="-1" y="-1" width="44" height="44" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
Expand All @@ -201,7 +201,7 @@ class AppNode extends HtmlResize.view {
`
: `<svg width="100%" height="100%" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_5199_166905)">
<path d="M20.9998 29.8333C28.0875 29.8333 33.8332 24.0876 33.8332 17C33.8332 9.91231 28.0875 4.16663 20.9998 4.16663C13.9122 4.16663 8.1665 9.91231 8.1665 17C8.1665 24.0876 13.9122 29.8333 20.9998 29.8333Z" fill="#3370FF"/>
<path d="M20.9998 29.8333C28.0875 29.8333 33.8332 24.0876 33.8332 17C33.8332 9.91231 28.0875 4.16663 20.9998 4.16663C13.9122 4.16663 8.1665 9.91231 8.1665 17C8.1665 24.0876 13.9122 29.8333 20.9998 29.8333Z" fill="${anchorData.id.endsWith('_exception_right') ? '#FF8800' : '#3370FF'}"/>
<path d="M19.8332 11.75C19.8332 11.4278 20.0943 11.1666 20.4165 11.1666H21.5832C21.9053 11.1666 22.1665 11.4278 22.1665 11.75V15.8333H26.2498C26.572 15.8333 26.8332 16.0945 26.8332 16.4166V17.5833C26.8332 17.9055 26.572 18.1666 26.2498 18.1666H22.1665V22.25C22.1665 22.5721 21.9053 22.8333 21.5832 22.8333H20.4165C20.0943 22.8333 19.8332 22.5721 19.8332 22.25V18.1666H15.7498C15.4277 18.1666 15.1665 17.9055 15.1665 17.5833V16.4166C15.1665 16.0945 15.4277 15.8333 15.7498 15.8333H19.8332V11.75Z" fill="white"/>
</g>
<defs>
Expand Down Expand Up @@ -454,6 +454,15 @@ class AppNodeModel extends HtmlResize.model {
type: 'left',
})
}

if (this.properties.enableException) {
anchors.push({
x: x + width / 2 - 10,
y: y + this.height / 2 - 80,
id: `${id}_exception_right`,
type: 'right',
})
}
anchors.push({
x: x + width / 2 - 10,
y: showNode ? y : y - 15,
Expand Down
Loading