zhangxiao
2024-08-05 8742aa1ca9a96e75c18d4f9e3c52bddd8e190898
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<template>
  <div class="main-container">
    <div class="main-container-lf">
      <div class="main-container-lf-top">检索测试</div>
      <div class="main-container-lf-down">
        <div style="color: #999"
          >最后一步! 成功后,剩下的就交给Infiniflow AI吧。</div
        >
        <a-divider style="margin-top: 10px" />
        <a-form
          ref="formRef"
          :model="form"
          :style="{ width: '100%' }"
          layout="vertical"
          @submit="handleSubmit"
        >
          <a-form-item field="similarity_threshold" label="相似度阈值">
            <a-slider v-model="form.similarity_threshold" />
          </a-form-item>
          <a-form-item
            field="slider"
            label="关键字相似度权重"
            :rules="[
              { type: 'number', min: 5, message: 'slider is min than 5' },
            ]"
          >
            <a-slider v-model="form.vector_similarity_weight" />
          </a-form-item>
          <a-form-item
            field="section"
            label="Rerank模型"
            :rules="[{ match: /section one/, message: '请选择' }]"
          >
            <a-space direction="vertical" size="large">
              <a-select
                :size="'large'"
                v-model="form.rerank_id"
                :style="{ width: '100%' }"
                placeholder="请选择 ..."
                allow-clear
              >
                <a-optgroup
                  :label="index"
                  v-for="(item, index) in modelList"
                  :key="index"
                >
                  <a-option
                    v-for="obj in item"
                    :key="obj.fid"
                    :disabled="!obj.available"
                    :value="obj.llm_name"
                  >
                    {{ obj.llm_name }}
                  </a-option>
                </a-optgroup>
              </a-select>
            </a-space>
          </a-form-item>
          <a-form-item
            field="slider"
            label="Top-K"
            :rules="[
              { type: 'number', min: 5, message: 'slider is min than 5' },
            ]"
          >
            <a-slider v-model="form.top_k" :min="1" :max="2048" />
          </a-form-item>
          <a-form-item>
            <div class="main-container-form-item-extra">
              <div class="main-container-form-item-extra-top">测试文本</div>
              <div class="main-container-form-item-extra-down">
                <a-textarea
                  v-model="form.question"
                  style="
                    height: 10rem;
                    border: 1px solid var(--color-fill-3);
                    border-radius: 4px;
                  "
                  placeholder=""
                  allow-clear
                />
              </div>
              <div class="main-container-form-item-extra-btn">
                <a-button type="primary" html-type="submit">测试</a-button>
              </div>
            </div>
          </a-form-item>
        </a-form>
      </div>
    </div>
    <div class="main-container-rt">
      <a-collapse style="width: 96%; margin-top: 1rem; margin-left: 2%">
        <a-collapse-item header="0/0 选定的文件" key="3">
          <template #extra>
            <a-tag size="small">命中数</a-tag>
            <a-tag size="small">看法</a-tag>
          </template>
          <div>
            <a-empty />
          </div>
        </a-collapse-item>
      </a-collapse>
    </div>
  </div>
</template>
 
<script lang="ts" setup>
  import { onMounted, onBeforeMount, reactive, ref, watch } from 'vue';
  import { Message } from '@arco-design/web-vue';
  import { kbretrievalTest, queryModelList } from '@/api/kbList';
  // const props = defineProps(['kbId'])
 
  // watch(() => props.kbId, (newValue, oldValue) => {
  //   console.log('kbId 变化了', newValue, oldValue);
  // },{
  //   deep:true,
  // });
 
  let visible = ref(false);
  let loading = ref(false);
  const formRef = ref(null);
  const kbid = ref('');
  const modelList = ref({});
  let form = reactive({
    page: 1,
    question: '',
    rerank_id: '',
    similarity_threshold: 20,
    size: 10,
    top_k: 1024,
    vector_similarity_weight: 30,
  });
 
  const formatter = (value) => {
    // return String(Math.round(value / 100))
  };
 
  const handleSubmit = async ({ values, errors }) => {
    // console.log(props.kbobj, 'props.kbobj');
    if (!form.question) {
      return;
    }
    let formObj = {
      ...form,
      kb_id: kbid.value,
    };
    formObj.similarity_threshold = formObj.similarity_threshold / 100;
    formObj.vector_similarity_weight = formObj.vector_similarity_weight / 100;
    const data = await kbretrievalTest(formObj);
  };
 
  const handleClick = () => {
    visible.value = true;
  };
  const handleCancel = () => {
    visible.value = false;
  };
 
  const handleOpened = (el) => {
    Object.assign(form, {});
    formRef.value.resetFields();
  };
 
  const changekbid = (value) => {
    kbid.value = value;
  };
 
  const queryModel = async (params) => {
    try {
      const data = await queryModelList(params);
      console.log(data.data, '大模型列表');
      modelList.value = {
        BAAI: [data.data.BAAI[1]],
        Jina: data.data.Jina,
        youdao: data.data.youdao,
      };
    } catch (err) {
      // you can report use errorHandler or other
    } finally {
    }
  };
 
  defineExpose({
    changekbid,
  });
 
  onBeforeMount(() => {
    queryModel({});
  });
  onMounted(() => {});
</script>
 
<script lang="ts">
  export default {
    name: 'config',
    methods: {},
  };
</script>
<style scoped lang="less">
  .main-container {
    display: flex;
    justify-content: space-between;
    height: 100%;
    //background: #626aea;
    &-lf {
      width: 30%;
      height: 100%;
      //border: 1px solid #cccccc;
      //background: #ffffff;
      border-radius: 10px;
      overflow: hidden;
      &-top {
        width: 100%;
        height: 60px;
        line-height: 60px;
        background: rgb(var(--primary-6));
        color: #ffffff;
        text-align: center;
      }
      &-down {
        padding: 20px;
        width: 100%;
      }
    }
    &-form-item-extra {
      width: 100%;
      height: 20rem;
      border: 1px solid var(--color-fill-3);
      border-radius: 6px;
      overflow: hidden;
      &-top {
        width: 100%;
        height: 40px;
        line-height: 40px;
        border-bottom: 1px solid var(--color-fill-3);
        //background: rgb(var(--primary-6));
        color: #999999;
        text-align: center;
      }
      &-down {
        width: 92%;
        margin-left: 4%;
        margin-top: 30px;
      }
      &-btn {
        width: 96%;
        text-align: right;
        margin-top: 1rem;
      }
    }
    &-rt {
      width: 69%;
      height: 100%;
      //background: #626aea;
      //border: 1px solid #cccccc;
      //background: #ffffff;
      border-radius: 10px;
    }
  }
</style>