ModelProvider.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 { onMounted, toRaw } from 'vue';
  18. import { getChatModels } from '@/api/chat';
  19. import { LLMProviders } from '@/views/modules/common/data';
  20. import { ref } from 'vue-demi';
  21. import { useChatStore } from '@/views/modules/chat/store/useChatStore';
  22. const chatStore = useChatStore();
  23. const modelList = ref([]);
  24. onMounted(async () => {
  25. const providers = await getChatModels();
  26. const data: any = [];
  27. if (chatStore.modelId === '' || chatStore.modelId === null) {
  28. chatStore.modelId = providers[0].id;
  29. chatStore.modelName = providers[0].model;
  30. chatStore.modelProvider = providers[0].provider;
  31. }
  32. LLMProviders.forEach((i) => {
  33. const children = providers.filter((m) => m.provider == i.model);
  34. if (children.length === 0) {
  35. return;
  36. }
  37. data.push({
  38. type: 'group',
  39. name: i.name,
  40. id: i.id,
  41. children: children,
  42. });
  43. });
  44. modelList.value = data;
  45. });
  46. function onUpdate(val, opt) {
  47. const obj = toRaw(opt);
  48. chatStore.modelId = obj.id;
  49. chatStore.modelName = obj.model;
  50. chatStore.modelProvider = obj.provider;
  51. }
  52. </script>
  53. <template>
  54. <n-select
  55. v-model:value="chatStore.modelId"
  56. :consistent-menu-width="false"
  57. :label-field="'name'"
  58. :options="modelList"
  59. :value-field="'id'"
  60. class="!w-32"
  61. size="small"
  62. @update:value="onUpdate"
  63. />
  64. </template>
  65. <style lang="less" scoped>
  66. ::v-deep(
  67. .n-base-selection .n-base-selection__border,
  68. .n-base-selection .n-base-selection__state-border
  69. ) {
  70. border: none !important;
  71. }
  72. ::v-deep(.n-base-selection-label) {
  73. font-weight: 600 !important;
  74. gap: 6px !important;
  75. display: flex !important;
  76. }
  77. ::v-deep(.n-base-selection-input) {
  78. margin-right: 4px;
  79. }
  80. </style>