Skip to content

Commit 07cf2d4

Browse files
committed
feat: workflow Exception branch
1 parent c6394f6 commit 07cf2d4

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ def execute(self, model_id, system, prompt, dialogue_number, history_chat_record
177177
**model_params_setting)
178178
history_message = self.get_history_message(history_chat_record, dialogue_number, dialogue_type,
179179
self.runtime_node_id)
180-
self.context['history_message'] = history_message
180+
self.context['history_message'] = [{'content': message.content, 'role': message.type} for message in
181+
(history_message if history_message is not None else [])]
181182
question = self.generate_prompt_question(prompt)
182183
self.context['question'] = question.content
183184
system = self.workflow_manage.generate_prompt(system)
@@ -197,8 +198,6 @@ def execute(self, model_id, system, prompt, dialogue_number, history_chat_record
197198
if stream:
198199
r = chat_model.stream(message_list)
199200
return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list,
200-
'history_message': [{'content': message.content, 'role': message.type} for message in
201-
(history_message if history_message is not None else [])],
202201
'question': question.content}, {},
203202
_write_context=write_context_stream)
204203
else:

apps/application/flow/workflow_manage.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def init_fields(self):
153153
node_name = properties.get('stepName')
154154
node_id = node.id
155155
node_config = properties.get('config')
156+
field_list.append(
157+
{'label': '异常信息', 'value': 'exception_message', 'node_id': node_id, 'node_name': node_name})
156158
if node_config is not None:
157159
fields = node_config.get('fields')
158160
if fields is not None:
@@ -473,7 +475,12 @@ def hand_event_node_result(self, current_node, node_result_future):
473475
else:
474476
list(result)
475477
if current_node.status == 500:
476-
return None
478+
current_node.context['exception_message'] = current_node.err_message
479+
current_node.context['branch_id'] = 'exception'
480+
r = NodeResult({'branch_id': 'exception', 'exception': current_node.err_message}, {},
481+
_is_interrupt=lambda node, step_variable, global_variable: False)
482+
r.write_context(current_node, self)
483+
return r
477484
return current_result
478485
except Exception as e:
479486
# 添加节点
@@ -494,7 +501,11 @@ def hand_event_node_result(self, current_node, node_result_future):
494501
current_node.node_chunk.add_chunk(chunk)
495502
current_node.get_write_error_context(e)
496503
self.status = 500
497-
return None
504+
current_node.context['exception_message'] = current_node.err_message
505+
current_node.context['branch_id'] = 'exception'
506+
return NodeResult({'branch_id': 'exception', 'exception': current_node.err_message}, {},
507+
_is_interrupt=lambda node, step_variable, global_variable: False)
508+
498509
finally:
499510
current_node.node_chunk.end()
500511
# 归还链接到连接池

ui/src/workflow/common/NodeContainer.vue

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
:show="showAnchor"
136136
:inner="true"
137137
:id="id"
138-
style="left: 100%; top: 50%; transform: translate(0, -50%)"
138+
style="left: 100%; transform: translate(0, -50%)"
139+
:style="dropdownMenuStyle"
139140
@clickNodes="clickNodes"
140141
/>
141142
</el-collapse-transition>
@@ -177,7 +178,7 @@
177178
</div>
178179
</template>
179180
<script setup lang="ts">
180-
import { ref, computed, onMounted, inject } from 'vue'
181+
import { ref, computed, onMounted, watch, nextTick } from 'vue'
181182
import { set } from 'lodash'
182183
import { iconComponent } from '../icons/utils'
183184
import { copyClick } from '@/utils/clipboard'
@@ -187,6 +188,7 @@ import type { FormInstance } from 'element-plus'
187188
import { t } from '@/locales'
188189
import { useRoute } from 'vue-router'
189190
import DropdownMenu from '@/components/workflow-dropdown-menu/index.vue'
191+
190192
const route = useRoute()
191193
const {
192194
params: { id },
@@ -203,6 +205,13 @@ const height = ref<{
203205
})
204206
const showAnchor = ref<boolean>(false)
205207
const anchorData = ref<any>()
208+
const dropdownMenuStyle = computed(() => {
209+
return {
210+
top: anchorData.value
211+
? anchorData.value.y - props.nodeModel.y + props.nodeModel.height / 2 + 'px'
212+
: '0px',
213+
}
214+
})
206215
const titleFormRef = ref()
207216
const nodeNameDialogVisible = ref<boolean>(false)
208217
const form = ref<any>({
@@ -348,8 +357,16 @@ const props = withDefaults(
348357
nodeModel: any
349358
exceptionNodeList?: string[]
350359
}>(),
351-
{ exceptionNodeList: () => ['ai-chat-node'] },
360+
{
361+
exceptionNodeList: () => [
362+
'ai-chat-node',
363+
'video-understand-node',
364+
'image-generate-node',
365+
'image-understand-node',
366+
],
367+
},
352368
)
369+
353370
const nodeFields = computed(() => {
354371
if (props.nodeModel.properties.config.fields) {
355372
const fields = props.nodeModel.properties.config.fields?.map((field: any) => {
@@ -365,16 +382,26 @@ const nodeFields = computed(() => {
365382
...fields,
366383
{
367384
label: '异常信息',
368-
value: 'exception',
369-
globeLabel: `{{${props.nodeModel.properties.stepName}.exception}}`,
370-
globeValue: `{{context['${props.nodeModel.id}'].exception}}`,
385+
value: 'exception_message',
386+
globeLabel: `{{${props.nodeModel.properties.stepName}.exception_message}}`,
387+
globeValue: `{{context['${props.nodeModel.id}'].exception_message}}`,
371388
},
372389
]
373390
}
374391
return fields
375392
}
376393
return []
377394
})
395+
watch(enable_exception, () => {
396+
props.nodeModel.graphModel.eventCenter.emit(
397+
'delete_edge',
398+
props.nodeModel.outgoing.edges
399+
.filter((item: any) =>
400+
[`${props.nodeModel.id}_exception_right`].includes(item.sourceAnchorId),
401+
)
402+
.map((item: any) => item.id),
403+
)
404+
})
378405
379406
function showOperate(type: string) {
380407
return ![

ui/src/workflow/common/app-node.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class AppNode extends HtmlResize.view {
183183
? `<svg width="100%" height="100%" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
184184
<g filter="url(#filter0_d_5119_232585)">
185185
<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"/>
186-
<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"/>
186+
<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'}"/>
187187
</g>
188188
<defs>
189189
<filter id="filter0_d_5119_232585" x="-1" y="-1" width="44" height="44" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
@@ -201,7 +201,7 @@ class AppNode extends HtmlResize.view {
201201
`
202202
: `<svg width="100%" height="100%" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
203203
<g filter="url(#filter0_d_5199_166905)">
204-
<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"/>
204+
<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'}"/>
205205
<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"/>
206206
</g>
207207
<defs>
@@ -454,14 +454,14 @@ class AppNodeModel extends HtmlResize.model {
454454
type: 'left',
455455
})
456456
}
457-
458-
if (this.properties.enableException) {
459-
anchors.push({
460-
x: x + width / 2 - 10,
461-
y: y+(this.height/2) -80,
462-
id: `${id}_exception_right`,
463-
type: 'right',
464-
})
457+
458+
if (this.properties.enableException) {
459+
anchors.push({
460+
x: x + width / 2 - 10,
461+
y: y + this.height / 2 - 80,
462+
id: `${id}_exception_right`,
463+
type: 'right',
464+
})
465465
}
466466
anchors.push({
467467
x: x + width / 2 - 10,

0 commit comments

Comments
 (0)