Skip to content

Commit

Permalink
feat: 工作流开始节点添加上下文,会话id参数 #1094
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Sep 18, 2024
1 parent 56853a1 commit 191ed70
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
3 changes: 0 additions & 3 deletions apps/application/flow/step_node/start_node/i_start_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
class IStarNode(INode):
type = 'start-node'

def get_node_params_serializer_class(self) -> Type[serializers.Serializer] | None:
return None

def _run(self):
return self.execute(**self.flow_params_serializer.data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@

class BaseStartStepNode(IStarNode):
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},
{'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):
global_fields = []
Expand Down
61 changes: 24 additions & 37 deletions ui/src/workflow/nodes/start-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,55 @@
<NodeContainer :nodeModel="nodeModel">
<h5 class="title-decoration-1 mb-8">全局变量</h5>
<div
v-for="item in nodeModel.properties.config.globalFields"
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
@mouseenter="showicon = true"
@mouseleave="showicon = false"
>
<span>当前时间 {time}</span>
<span>{{ item.label }} {{ '{' + item.value + '}' }}</span>
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
<el-button link @click="copyClick(globeLabel)" style="padding: 0">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
</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">
<el-button
link
@click="copyClick('{{' + '全局变量.' + item.value + '}}')"
style="padding: 0"
>
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
</div>
</NodeContainer>
</template>
<script setup lang="ts">
import { set } from 'lodash'
import { cloneDeep, set } from 'lodash'
import NodeContainer from '@/workflow/common/NodeContainer.vue'
import { copyClick } from '@/utils/clipboard'
import { ref, computed, onMounted } from 'vue'
const props = defineProps<{ nodeModel: any }>()
const globeLabel = '{{全局变量.time}}'
const showicon = ref(false)
const globalFields = [
{ label: '当前时间', value: 'time' },
{ label: '历史聊天记录', value: 'history_context' },
{ label: '对话id', value: 'chat_id' }
]
const inputFieldList = ref<any[]>([])
function handleRefreshFieldList(data: any[]) {
props.nodeModel.graphModel.nodes
const getRefreshFieldList = () => {
return props.nodeModel.graphModel.nodes
.filter((v: any) => v.id === 'base-node')
.map((v: any) => {
// eslint-disable-next-line vue/no-mutating-props
props.nodeModel.properties.config.globalFields = [
{
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
})
.map((v: any) => cloneDeep(v.properties.input_field_list))
.reduce((x: any, y: any) => [...x, ...y], [])
.map((i: any) => ({ label: i.name, value: i.variable }))
}
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', (data: any) => {
handleRefreshFieldList(data)
})
const refreshFieldList = () => {
const refreshFieldList = getRefreshFieldList()
set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList])
}
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', refreshFieldList)
onMounted(() => {
handleRefreshFieldList([])
refreshFieldList()
})
</script>
<style lang="scss" scoped></style>

0 comments on commit 191ed70

Please sign in to comment.