index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!--
  2. - Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. -
  4. - Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. - you may not use this file except in compliance with the License.
  6. - You may obtain a copy of the License at
  7. -
  8. - https://www.gnu.org/licenses/agpl-3.0.html
  9. -
  10. - Unless required by applicable law or agreed to in writing, software
  11. - distributed under the License is distributed on an "AS IS" BASIS,
  12. - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. - See the License for the specific language governing permissions and
  14. - limitations under the License.
  15. -->
  16. <script lang="ts" setup>
  17. import { BasicForm, useForm } from '@/components/Form';
  18. import { getSchemas, LLMProviders } from './columns';
  19. import { isNullOrWhitespace } from '@/utils/is';
  20. import { add, list as getModels, update } from '@/api/aigc/model';
  21. import { useMessage } from 'naive-ui';
  22. import { onMounted } from 'vue';
  23. import { ModelTypeEnum } from '@/api/models';
  24. import { ref } from 'vue-demi';
  25. const ms = useMessage();
  26. const [register, { setFieldsValue }] = useForm({
  27. labelWidth: 120,
  28. gridProps: { cols: 1 },
  29. layout: 'horizontal',
  30. submitButtonText: '提交',
  31. });
  32. const schemas = ref();
  33. onMounted(async () => {
  34. const data = await getModels({ type: ModelTypeEnum.EMBEDDING });
  35. if (data != null && data.length >= 0) {
  36. setFieldsValue({ ...data[0] });
  37. schemas.value = getSchemas(data[0].provider);
  38. }
  39. });
  40. function onChange(val) {
  41. schemas.value = getSchemas(val);
  42. }
  43. async function onSubmit(values: any) {
  44. if (values !== false) {
  45. const data = { ...values };
  46. if (isNullOrWhitespace(data.id)) {
  47. await add(data);
  48. ms.success('新增成功');
  49. } else {
  50. await update(data);
  51. ms.success('修改成功');
  52. }
  53. } else {
  54. ms.error('请完善表单');
  55. }
  56. }
  57. </script>
  58. <template>
  59. <div class="flex justify-center items-center mb-10">
  60. <div class="w-2/4">
  61. <n-alert
  62. class="w-full mb-4 mt-2 min-alert"
  63. title="如果需要使用知识库的能力,则必须配置Embedding向量模型。Dimensions代表向量纬度,不同的模型配置不一样,此值和VectorStore的配置要完全对应,如果在application.yml已经配置了VectorStore的Dimensions参数,那么这里也应该保持相同,否则需要删除VectorStore表重新启动项目"
  64. type="info"
  65. />
  66. <BasicForm :schemas="schemas" class="mt-5" @register="register" @submit="onSubmit">
  67. <template #providerSlot="{ model, field }">
  68. <n-select
  69. v-model:value="model[field]"
  70. :options="LLMProviders"
  71. label-field="name"
  72. value-field="model"
  73. @change="onChange"
  74. />
  75. </template>
  76. </BasicForm>
  77. </div>
  78. </div>
  79. </template>
  80. <style lang="less" scoped></style>