feat: 工作流开始节点添加上下文,会话id参数 #1094
This commit is contained in:
parent
3e3b77e34d
commit
f07f5ae804
@ -16,9 +16,6 @@ from application.flow.i_step_node import INode, NodeResult
|
|||||||
class IStarNode(INode):
|
class IStarNode(INode):
|
||||||
type = 'start-node'
|
type = 'start-node'
|
||||||
|
|
||||||
def get_node_params_serializer_class(self) -> Type[serializers.Serializer] | None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
return self.execute(**self.flow_params_serializer.data)
|
return self.execute(**self.flow_params_serializer.data)
|
||||||
|
|
||||||
|
|||||||
@ -15,11 +15,16 @@ from application.flow.step_node.start_node.i_start_node import IStarNode
|
|||||||
|
|
||||||
class BaseStartStepNode(IStarNode):
|
class BaseStartStepNode(IStarNode):
|
||||||
def execute(self, question, **kwargs) -> NodeResult:
|
def execute(self, question, **kwargs) -> NodeResult:
|
||||||
|
history_chat_record = self.flow_params_serializer.data.get('history_chat_record', [])
|
||||||
|
history_context = [{'question': chat_record.problem_text, 'answer': chat_record.answer_text} for chat_record in
|
||||||
|
history_chat_record]
|
||||||
|
chat_id = self.flow_params_serializer.data.get('chat_id')
|
||||||
"""
|
"""
|
||||||
开始节点 初始化全局变量
|
开始节点 初始化全局变量
|
||||||
"""
|
"""
|
||||||
return NodeResult({'question': question},
|
return NodeResult({'question': question},
|
||||||
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time()})
|
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
|
||||||
|
'history_context': history_context, 'chat_id': str(chat_id)})
|
||||||
|
|
||||||
def get_details(self, index: int, **kwargs):
|
def get_details(self, index: int, **kwargs):
|
||||||
global_fields = []
|
global_fields = []
|
||||||
|
|||||||
@ -2,25 +2,18 @@
|
|||||||
<NodeContainer :nodeModel="nodeModel">
|
<NodeContainer :nodeModel="nodeModel">
|
||||||
<h5 class="title-decoration-1 mb-8">全局变量</h5>
|
<h5 class="title-decoration-1 mb-8">全局变量</h5>
|
||||||
<div
|
<div
|
||||||
|
v-for="item in nodeModel.properties.config.globalFields"
|
||||||
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
|
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
|
||||||
@mouseenter="showicon = true"
|
@mouseenter="showicon = true"
|
||||||
@mouseleave="showicon = false"
|
@mouseleave="showicon = false"
|
||||||
>
|
>
|
||||||
<span>当前时间 {time}</span>
|
<span>{{ item.label }} {{ '{' + item.value + '}' }}</span>
|
||||||
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
|
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
|
||||||
<el-button link @click="copyClick(globeLabel)" style="padding: 0">
|
<el-button
|
||||||
<AppIcon iconName="app-copy"></AppIcon>
|
link
|
||||||
</el-button>
|
@click="copyClick('{{' + '全局变量.' + item.value + '}}')"
|
||||||
</el-tooltip>
|
style="padding: 0"
|
||||||
</div>
|
>
|
||||||
<div v-for="(item, index) in inputFieldList" :key="index"
|
|
||||||
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
|
|
||||||
@mouseenter="showicon = true"
|
|
||||||
@mouseleave="showicon = false"
|
|
||||||
>
|
|
||||||
<span>{{ item.name }} {{ '{' + item.variable + '}' }}</span>
|
|
||||||
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
|
|
||||||
<el-button link @click="copyClick('{{' + '全局变量.' + item.variable + '}}')" style="padding: 0">
|
|
||||||
<AppIcon iconName="app-copy"></AppIcon>
|
<AppIcon iconName="app-copy"></AppIcon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
@ -28,42 +21,36 @@
|
|||||||
</NodeContainer>
|
</NodeContainer>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { set } from 'lodash'
|
import { cloneDeep, set } from 'lodash'
|
||||||
import NodeContainer from '@/workflow/common/NodeContainer.vue'
|
import NodeContainer from '@/workflow/common/NodeContainer.vue'
|
||||||
import { copyClick } from '@/utils/clipboard'
|
import { copyClick } from '@/utils/clipboard'
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
|
||||||
const props = defineProps<{ nodeModel: any }>()
|
const props = defineProps<{ nodeModel: any }>()
|
||||||
|
|
||||||
const globeLabel = '{{全局变量.time}}'
|
|
||||||
|
|
||||||
const showicon = ref(false)
|
const showicon = ref(false)
|
||||||
|
const globalFields = [
|
||||||
|
{ label: '当前时间', value: 'time' },
|
||||||
|
{ label: '历史聊天记录', value: 'history_context' },
|
||||||
|
{ label: '对话id', value: 'chat_id' }
|
||||||
|
]
|
||||||
const inputFieldList = ref<any[]>([])
|
const inputFieldList = ref<any[]>([])
|
||||||
|
|
||||||
function handleRefreshFieldList(data: any[]) {
|
const getRefreshFieldList = () => {
|
||||||
props.nodeModel.graphModel.nodes
|
return props.nodeModel.graphModel.nodes
|
||||||
.filter((v: any) => v.id === 'base-node')
|
.filter((v: any) => v.id === 'base-node')
|
||||||
.map((v: any) => {
|
.map((v: any) => cloneDeep(v.properties.input_field_list))
|
||||||
// eslint-disable-next-line vue/no-mutating-props
|
.reduce((x: any, y: any) => [...x, ...y], [])
|
||||||
props.nodeModel.properties.config.globalFields = [
|
.map((i: any) => ({ label: i.name, value: i.variable }))
|
||||||
{
|
|
||||||
label: '当前时间',
|
|
||||||
value: 'time'
|
|
||||||
}, ...v.properties.input_field_list.map((i: any) => {
|
|
||||||
return { label: i.name, value: i.variable }
|
|
||||||
})
|
|
||||||
]
|
|
||||||
inputFieldList.value = v.properties.input_field_list
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
const refreshFieldList = () => {
|
||||||
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', (data: any) => {
|
const refreshFieldList = getRefreshFieldList()
|
||||||
handleRefreshFieldList(data)
|
set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList])
|
||||||
})
|
}
|
||||||
|
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', refreshFieldList)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
handleRefreshFieldList([])
|
refreshFieldList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user