wujingjing
2024-12-23 6d82ad4fb10f7015059b1b2cbcf72e8a949e83fa
src/components/vue-flow/ui/nodes/LLMNode.vue
@@ -1,123 +1,86 @@
<template>
   <div
      class="w-max-[520px] border-2 rounded-lg border-solid border-gray-100 bg-white p-3 shadow-md relative hover:border-blue-500 group"
   <NodeBasicLayout
      v-model:title="data.title"
      :type="NodeType.LLM"
      :description="VueFlowHelper.getConfigValue(data, 'description', '调用大模型回答用户问题或者处理任务。')"
   >
      <Handle :id="targetHandleId" type="source" :position="Position.Left" />
      <div
         class="group-hover:visible invisible flex absolute divide-y-[1.5px] divide-solid divide-gray-100 rounded-lg right-0 -top-0.5 translate-y-[-100%]"
         style="box-shadow: 0 0 15px #dbdee6"
      >
         <el-tooltip effect="dark" content="复制" placement="top">
            <div
               class="flex content-center items-center border-x-0 p-1 hover:bg-gray-200 active:bg-gray-300 cursor-pointer"
               @click="handleClickDuplicateBtn"
            >
               <span class="ywifont !text-[20px] mb-1 p-1.5 ywicon-copy"></span>
      <Handle :id="targetHandleId" type="target" :position="Position.Left" />
      <FieldLayout :title="outputParam.name">
         <el-input  class="w-full flex-0" v-model="outputParam.params[0].value" placeholder="输出参数名"> </el-input>
      </FieldLayout>
      <FieldLayout :title="VueFlowHelper.getConfigValue(modelSetting, 'name', '模型设置')">
         <div class="w-[340px] flex-items-center gap-x-2">
            <div class="flex-column gap-y-1.5">
               <span class="text-gray-500">{{ VueFlowHelper.getParams(modelSetting, 'llm_model').label }}</span>
               <el-tree-select
                  v-model="VueFlowHelper.getParams(modelSetting, 'llm_model').value"
                  :data="llmInfoList"
                  :props="{ label: 'name', value: 'id' }"
                  :render-after-expand="false"
                  :check-strictly="false"
                  :show-checkbox="false"
                  :accordion="true"
                  filterable
                  :placeholder="VueFlowHelper.getParams(modelSetting, 'llm_model').placeholder"
               />
               <!-- <el-select
                  v-model="VueFlowHelper.getParams(modelSetting, 'llm_model').value"
                  class="w-[150px]"
                  :placeholder="VueFlowHelper.getParams(modelSetting, 'llm_model').placeholder"
               >
                  <el-option v-for="item in VueFlowConstant.LLM_MODEL_LIST" :key="item.value" :label="item.label" :value="item.value" />
               </el-select> -->
            </div>
         </el-tooltip>
         <el-tooltip effect="dark" content="删除" placement="top">
            <div
               @click="clickDeleteBtn"
               class="flex content-center items-center border-x-0 p-1 hover:bg-gray-200 active:bg-gray-300 hover:text-red-400 cursor-pointer"
            >
               <span class="ywifont !text-[20px] mb-1 p-1.5 ywicon-shanchu"></span>
            </div>
         </el-tooltip>
      </div>
      <div class="flex flex-col gap-y-2">
         <div class="flex justify-between flex-0">
            <div class="flex items-center gap-x-2">
               <img src="/@/components/vue-flow/ui/assets/images/icon_Start.png" class="h-4 w-4" alt="Start icon" />
               <div class="flex flex-col gap-y-1">
                  <p v-if="!titleIsEdit" class="text-xl font-bold text-gray-500" @click="titleIsEdit = true">{{ data.title }}</p>
                  <el-input v-else v-model="data.title" @blur="() => (titleIsEdit = false)"></el-input>
               </div>
            <div class="flex-column gap-y-1.5">
               <span class="text-gray-500">{{ VueFlowHelper.getParams(modelSetting, 'temperature').label }}</span>
               <el-input-number
                  v-model="VueFlowHelper.getParams(modelSetting, 'temperature').value"
                  class="w-[180px]"
                  placeholder=""
               ></el-input-number>
            </div>
         </div>
         <div class="flex-auto gap-y-2 flex-col flex nodrag">
            <div class="text-lg font-bold">模型设置</div>
            <div class="min-w-[340px] flex-items-center gap-x-2">
               <div class="flex-column gap-y-1.5">
                  <span class="text-gray-500">模型</span>
                  <el-select v-model="VueFlowHelper.getParams(modelSetting, 'llm_model').value" class="w-[150px]" placeholder="请选择模型">
                     <el-option v-for="item in VueFlowConstant.LLM_MODEL_LIST" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
               </div>
               <div class="flex-column gap-y-1.5">
                  <span class="text-gray-500">温度</span>
                  <el-input-number
                     v-model="VueFlowHelper.getParams(modelSetting, 'temperature').value"
                     class="w-[180px]"
                     placeholder="温度"
                  ></el-input-number>
               </div>
            </div>
         </div>
         <div class="flex-auto gap-y-2 flex-col flex nodrag w-full">
            <div class="text-lg font-bold">提示词</div>
            <div class="flex-column gap-y-1.5 w-full">
               <!-- <span class="text-gray-500">模型</span> -->
               <el-input v-model="VueFlowHelper.getParams(prompt, 'prompt').value" type="textarea" :rows="3" autocomplete="off"> </el-input>
            </div>
         </div>
      </div>
      </FieldLayout>
      <FieldLayout :title="prompt.name">
         <el-input
            class="nowheel"
            v-model="VueFlowHelper.getParams(prompt, 'prompt').value"
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 6 }"
            autocomplete="off"
         >
         </el-input>
      </FieldLayout>
      <Handle :id="sourceHandleId" type="source" :position="Position.Right" />
   </div>
   <!-- <div>
      <span>起始</span>
      <Handle type="source" :position="Position.Right" />
   </div> -->
   </NodeBasicLayout>
</template>
<script lang="ts" setup>
import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core';
import { ref, watchEffect } from 'vue';
import { ref } from 'vue';
import type { NodeProps } from '@vue-flow/core';
import { computed } from 'vue';
import { VueFlowConstant } from '../../VueFlowConstant';
import { VueFlowHelper } from '../../VueFlowHelper';
import { parameterTypeMap } from '../../vueFlowEnum';
import { LLMNodeData, LLMNodeEvents } from './index';
import type { LLMNodeData, LLMNodeEvents } from './index';
import { deepClone } from '/@/utils/other';
import { NodeType } from '../../vueFlowEnum';
defineProps<NodeProps<LLMNodeData, LLMNodeEvents>>();
import FieldLayout from './components/FieldLayout.vue';
import NodeBasicLayout from './components/NodeBasicLayout.vue';
const props = defineProps(['llmInfoList']);
const node = useNode();
const sourceHandleId = ref(VueFlowHelper.getHandleId(node.node, 'source'));
const targetHandleId = ref(VueFlowHelper.getHandleId(node.node, 'target'));
const data = ref(node.node.data);
const varList = ref(VueFlowHelper.getFieldValue(data.value, 'var_list'));
const titleIsEdit = ref(false);
const modelSetting = ref(VueFlowHelper.getGroupParam(data.value, 0));
const prompt = ref(VueFlowHelper.getGroupParam(data.value,1));
const prompt = ref(VueFlowHelper.getGroupParam(data.value, 1));
const outputParam = ref(VueFlowHelper.getGroupParam(data.value, 2));
VueFlowHelper.getConfigValue(VueFlowHelper.getParams(prompt.value, 'prompt'), 'label', '');
const { removeNodes, nodes, addNodes } = useVueFlow();
function handleClickDuplicateBtn() {
   const { type, position, data } = node.node;
   const newNode = {
      id: VueFlowHelper.genGeometryId(),
      type,
      position: {
         x: position.x + 100,
         y: position.y + 100,
      },
      data: deepClone(data),
   };
   addNodes(newNode);
}
const clickDeleteBtn = () => {
   removeNodes(node.id);
};
</script>