mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: workflow Exception branch
This commit is contained in:
parent
c6394f618b
commit
07cf2d4da1
|
|
@ -177,7 +177,8 @@ class BaseChatNode(IChatNode):
|
||||||
**model_params_setting)
|
**model_params_setting)
|
||||||
history_message = self.get_history_message(history_chat_record, dialogue_number, dialogue_type,
|
history_message = self.get_history_message(history_chat_record, dialogue_number, dialogue_type,
|
||||||
self.runtime_node_id)
|
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)
|
question = self.generate_prompt_question(prompt)
|
||||||
self.context['question'] = question.content
|
self.context['question'] = question.content
|
||||||
system = self.workflow_manage.generate_prompt(system)
|
system = self.workflow_manage.generate_prompt(system)
|
||||||
|
|
@ -197,8 +198,6 @@ class BaseChatNode(IChatNode):
|
||||||
if stream:
|
if stream:
|
||||||
r = chat_model.stream(message_list)
|
r = chat_model.stream(message_list)
|
||||||
return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': 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}, {},
|
'question': question.content}, {},
|
||||||
_write_context=write_context_stream)
|
_write_context=write_context_stream)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,8 @@ class WorkflowManage:
|
||||||
node_name = properties.get('stepName')
|
node_name = properties.get('stepName')
|
||||||
node_id = node.id
|
node_id = node.id
|
||||||
node_config = properties.get('config')
|
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:
|
if node_config is not None:
|
||||||
fields = node_config.get('fields')
|
fields = node_config.get('fields')
|
||||||
if fields is not None:
|
if fields is not None:
|
||||||
|
|
@ -473,7 +475,12 @@ class WorkflowManage:
|
||||||
else:
|
else:
|
||||||
list(result)
|
list(result)
|
||||||
if current_node.status == 500:
|
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
|
return current_result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 添加节点
|
# 添加节点
|
||||||
|
|
@ -494,7 +501,11 @@ class WorkflowManage:
|
||||||
current_node.node_chunk.add_chunk(chunk)
|
current_node.node_chunk.add_chunk(chunk)
|
||||||
current_node.get_write_error_context(e)
|
current_node.get_write_error_context(e)
|
||||||
self.status = 500
|
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:
|
finally:
|
||||||
current_node.node_chunk.end()
|
current_node.node_chunk.end()
|
||||||
# 归还链接到连接池
|
# 归还链接到连接池
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,8 @@
|
||||||
:show="showAnchor"
|
:show="showAnchor"
|
||||||
:inner="true"
|
:inner="true"
|
||||||
:id="id"
|
:id="id"
|
||||||
style="left: 100%; top: 50%; transform: translate(0, -50%)"
|
style="left: 100%; transform: translate(0, -50%)"
|
||||||
|
:style="dropdownMenuStyle"
|
||||||
@clickNodes="clickNodes"
|
@clickNodes="clickNodes"
|
||||||
/>
|
/>
|
||||||
</el-collapse-transition>
|
</el-collapse-transition>
|
||||||
|
|
@ -177,7 +178,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, inject } from 'vue'
|
import { ref, computed, onMounted, watch, nextTick } from 'vue'
|
||||||
import { set } from 'lodash'
|
import { set } from 'lodash'
|
||||||
import { iconComponent } from '../icons/utils'
|
import { iconComponent } from '../icons/utils'
|
||||||
import { copyClick } from '@/utils/clipboard'
|
import { copyClick } from '@/utils/clipboard'
|
||||||
|
|
@ -187,6 +188,7 @@ import type { FormInstance } from 'element-plus'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import DropdownMenu from '@/components/workflow-dropdown-menu/index.vue'
|
import DropdownMenu from '@/components/workflow-dropdown-menu/index.vue'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const {
|
const {
|
||||||
params: { id },
|
params: { id },
|
||||||
|
|
@ -203,6 +205,13 @@ const height = ref<{
|
||||||
})
|
})
|
||||||
const showAnchor = ref<boolean>(false)
|
const showAnchor = ref<boolean>(false)
|
||||||
const anchorData = ref<any>()
|
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 titleFormRef = ref()
|
||||||
const nodeNameDialogVisible = ref<boolean>(false)
|
const nodeNameDialogVisible = ref<boolean>(false)
|
||||||
const form = ref<any>({
|
const form = ref<any>({
|
||||||
|
|
@ -348,8 +357,16 @@ const props = withDefaults(
|
||||||
nodeModel: any
|
nodeModel: any
|
||||||
exceptionNodeList?: string[]
|
exceptionNodeList?: string[]
|
||||||
}>(),
|
}>(),
|
||||||
{ exceptionNodeList: () => ['ai-chat-node'] },
|
{
|
||||||
|
exceptionNodeList: () => [
|
||||||
|
'ai-chat-node',
|
||||||
|
'video-understand-node',
|
||||||
|
'image-generate-node',
|
||||||
|
'image-understand-node',
|
||||||
|
],
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const nodeFields = computed(() => {
|
const nodeFields = computed(() => {
|
||||||
if (props.nodeModel.properties.config.fields) {
|
if (props.nodeModel.properties.config.fields) {
|
||||||
const fields = props.nodeModel.properties.config.fields?.map((field: any) => {
|
const fields = props.nodeModel.properties.config.fields?.map((field: any) => {
|
||||||
|
|
@ -365,9 +382,9 @@ const nodeFields = computed(() => {
|
||||||
...fields,
|
...fields,
|
||||||
{
|
{
|
||||||
label: '异常信息',
|
label: '异常信息',
|
||||||
value: 'exception',
|
value: 'exception_message',
|
||||||
globeLabel: `{{${props.nodeModel.properties.stepName}.exception}}`,
|
globeLabel: `{{${props.nodeModel.properties.stepName}.exception_message}}`,
|
||||||
globeValue: `{{context['${props.nodeModel.id}'].exception}}`,
|
globeValue: `{{context['${props.nodeModel.id}'].exception_message}}`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -375,6 +392,16 @@ const nodeFields = computed(() => {
|
||||||
}
|
}
|
||||||
return []
|
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) {
|
function showOperate(type: string) {
|
||||||
return ![
|
return ![
|
||||||
|
|
|
||||||
|
|
@ -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">
|
? `<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)">
|
<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 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>
|
</g>
|
||||||
<defs>
|
<defs>
|
||||||
<filter id="filter0_d_5119_232585" x="-1" y="-1" width="44" height="44" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
<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 {
|
||||||
`
|
`
|
||||||
: `<svg width="100%" height="100%" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
|
: `<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)">
|
<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"/>
|
<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>
|
</g>
|
||||||
<defs>
|
<defs>
|
||||||
|
|
@ -454,14 +454,14 @@ class AppNodeModel extends HtmlResize.model {
|
||||||
type: 'left',
|
type: 'left',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.properties.enableException) {
|
if (this.properties.enableException) {
|
||||||
anchors.push({
|
anchors.push({
|
||||||
x: x + width / 2 - 10,
|
x: x + width / 2 - 10,
|
||||||
y: y+(this.height/2) -80,
|
y: y + this.height / 2 - 80,
|
||||||
id: `${id}_exception_right`,
|
id: `${id}_exception_right`,
|
||||||
type: 'right',
|
type: 'right',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
anchors.push({
|
anchors.push({
|
||||||
x: x + width / 2 - 10,
|
x: x + width / 2 - 10,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue