liudong
2024-08-07 e0219d2121732227922341fb3878e3a4d1b04d9d
src/views/dmx/IntelligentAgent/components/agentConfig.vue
@@ -1,9 +1,23 @@
<template>
  <a-button type="primary" @click="handleClick" style="margin-left: 10px">
  <a-button
    v-if="typeAngint == 'add'"
    type="primary"
    @click="handleClick"
    style="margin-left: 10px">
    <template #icon>
      <icon-plus />
    </template>
    新建智能体
  </a-button>
  <a-button
    v-if="typeAngint == 'edit'"
    type="text"
    size="small"
    @click="editClick"
  >
    <template #icon>
      <icon-tool />
    </template>
  </a-button>
  <a-modal
    v-model:visible="visible"
@@ -18,7 +32,7 @@
  >
    <a-row class="">
      <a-col :span="24">
        <a-tabs type="capsule" size="large">
        <a-tabs type="capsule" size="large" v-model="keyLarge" @tab-click="console.log(keyLarge)">
          <a-tab-pane key="1" title="助理设置">
            <a-divider style="margin-bottom: 20px;margin-top: 0" />
            <div style="width: 100%;" :style="{height:height}">
@@ -184,14 +198,15 @@
                  :data="form.prompt_config.parameters"
                  style="width: 100%"
                >
                  <template #key="{ record }">
                  <template #key="{ record, rowIndex }">
                    <a-input v-model="record.key" placeholder="" />
<!--                    <a-input v-model="form.prompt_config.parameters[rowIndex].key" />-->
                  </template>
                  <template #optional="{ record }">
                    <a-switch v-model="record.optional" size="small" />
                  </template>
                  <template #action="{ record }">
                    <a-button type="text" @click="deleteParameters(record)" style="margin-left: 0px" size="small">
                    <a-button type="text" @click="deleteParameters(record)" style="margin-left: 0" size="small">
                      <template #icon>
                        <icon-delete  />
                      </template>
@@ -285,9 +300,8 @@
import useLoading from "@/hooks/loading";
import { Message } from "@arco-design/web-vue";
import { dialogSet } from "@/api/Agent";
import EventBus from "@/utils/EventBus";
const { loading,setLoading } = useLoading(true);
const props = defineProps(['typeAngint', 'formData']);
const emit = defineEmits(['queryList']);
const visible = ref(false);
const modelList = ref({});
const rankModelList = ref({});
@@ -296,6 +310,7 @@
const formRef = ref();
const formRef1 = ref();
const formRef2 = ref();
const keyLarge = ref('1');
const form = reactive({
  name: "",
  icon: "",
@@ -330,8 +345,9 @@
  rerank_id:'',
  top_k:1024,
});
const height = ref('calc(100vh - 520px)');
const height = ref('calc(500px)');
const props = defineProps(['typeAngint', 'formData']);
const emit = defineEmits(['queryList']);
const columns = [
  {
    title: '关键字',
@@ -423,6 +439,7 @@
  formRef1.value.resetFields();
  formRef2.value.resetFields();
  form.name = "";
  emit('queryList');
};
const handleOpened = (el) => {
@@ -433,36 +450,39 @@
  //   txt: '',// 备注
  // });
  formRef.value.resetFields();
  form.name = "";
  form.prompt_config.system = "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。" +
    "回答需要考虑聊天历史。\n        以下是知识库:\n        {knowledge}\n        以上是知识库。";
  formRef.value.resetFields();
  formRef1.value.resetFields();
  formRef2.value.resetFields();
  if(props.typeAngint=='add'){
    form.name = "";
    form.prompt_config.system = "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。" +
      "回答需要考虑聊天历史。\n        以下是知识库:\n        {knowledge}\n        以上是知识库。";
  }
};
const handleBeforeOk = async (done) => {
  let valid = '';
  let valid1 = '';
  let valid2 = '';
  formRef.value.validate().then(res => {
    console.log('res:', res)
    valid = res;
    // console.log('res:', res)
  })
  formRef1.value.validate().then(res => {
    console.log('res:', res)
    valid1 = res;
    // console.log('res:', res)
  })
  formRef2.value.validate().then(res => {
    console.log('res:', res)
    valid2 = res;
    // console.log('res:', res)
  })
  if (valid || valid1 || valid2) {
    console.log('请求数据');
  if (form.name && form.kb_ids.length>0 && form.prompt_config.system && form.llm_id) {
    let title = '创建成功';
    let formNew = { ...form };
    if(formNew.rerank_id){
      delete formNew.top_k;
    }
    if(formNew.rerank_id){
      delete formNew.top_k;
    }
    if (props.typeAngint == 'edit') {
      formNew.dialog_id = form.id;
      delete formNew.id;
@@ -472,15 +492,16 @@
    setLoading(true)
    try {
      const data = await dialogSet(formNew);
      console.log(data.data, 'data');
      // console.log(data, 'data');
      if (data.code == 0){
        Message.success(title);
        handleCancel();
        emit('queryList');
        EventBus.emit('queryList');
      }else {
        Message.error(data.msg);
      }
      done(true);
      setLoading(false)
    } catch (err) {
      // you can report use errorHandler or other
      setLoading(false)
@@ -491,6 +512,14 @@
  }
};
const editClick = (data) => {
  visible.value = true;
  nextTick(()=>{
    // console.log(props.formData,'传入数据');
    Object.assign(form, props.formData);
    // console.log(form,'表单数据');
  })
};
const addVariable = () => {
  form.prompt_config.parameters.push({
@@ -514,7 +543,7 @@
const queryModel = async (params) => {
  try {
    const data = await queryModelList(params);
    console.log(data.data, '大模型列表');
    // console.log(data.data, '大模型列表');
    modelList.value = data.data;
    rankModelList.value = {
      BAAI: [data.data.BAAI[1]],
@@ -532,10 +561,10 @@
  setLoading(true);
  try {
    const { data } = await queryKbList(params);
    console.log(data, 'data');
    // console.log(data, 'data');
    nextTick(() => {
      tabs.value = data;
      console.log(tabs.value, 'tabs');
      // console.log(tabs.value, 'tabs');
    });
  } catch (err) {
    // you can report use errorHandler or other