From f62e8d4ceab2038d71d396e5863094a5b5543eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B0=A2=E9=9B=A8?= <554737215@qq.com> Date: Tue, 18 Feb 2025 11:32:36 +0800 Subject: [PATCH] =?UTF-8?q?fetch:=20=E9=A1=B5=E9=9D=A2=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 会话模型、向量模型、文生图模型、向量数据库 --- .../ai/model/chatModel/composables/columns.ts | 85 +++++ .../ai/model/chatModel/composables/consts.ts | 198 ++++++++++++ .../model/chatModel/composables/provider.ts | 37 +++ src/views/ai/model/chatModel/edit.vue | 11 + src/views/ai/model/chatModel/index.vue | 298 +++++++----------- .../ai/model/embedStore/composables/index.ts | 116 +++++++ src/views/ai/model/embedStore/index.vue | 26 ++ .../ai/model/embedding/composables/index.ts | 102 ++++++ src/views/ai/model/embedding/index.vue | 26 ++ src/views/ai/model/image/composables/index.ts | 110 +++++++ src/views/ai/model/image/index.vue | 26 ++ 11 files changed, 856 insertions(+), 179 deletions(-) create mode 100644 src/views/ai/model/chatModel/composables/columns.ts create mode 100644 src/views/ai/model/chatModel/composables/consts.ts create mode 100644 src/views/ai/model/chatModel/composables/provider.ts create mode 100644 src/views/ai/model/chatModel/edit.vue create mode 100644 src/views/ai/model/embedStore/composables/index.ts create mode 100644 src/views/ai/model/embedStore/index.vue create mode 100644 src/views/ai/model/embedding/composables/index.ts create mode 100644 src/views/ai/model/embedding/index.vue create mode 100644 src/views/ai/model/image/composables/index.ts create mode 100644 src/views/ai/model/image/index.vue diff --git a/src/views/ai/model/chatModel/composables/columns.ts b/src/views/ai/model/chatModel/composables/columns.ts new file mode 100644 index 0000000..5a8f68f --- /dev/null +++ b/src/views/ai/model/chatModel/composables/columns.ts @@ -0,0 +1,85 @@ +import {ProviderEnum} from './provider'; + +export const baseColumns = [ + { + label: '模型别名', + field: 'name', + }, + { + label: '模型版本', + field: 'model', + width: '140', + }, + { + label: '回复上限', + field: 'responseLimit', + width: '100', + }, + { + label: '生成随机性', + field: 'temperature', + width: '100', + }, + { + label: 'Top P', + field: 'topP', + width: '100', + }, +]; + +export const openaiColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, +]; + +export const ollamaColumns = [ + ...baseColumns, + { + label: 'Base Url', + field: 'baseUrl', + }, +]; + +export const qfanColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, +]; + +export const qwenColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, +]; +export const zhipuColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, +]; + +export function getColumns(provider: string) { + switch (provider) { + case ProviderEnum.OLLAMA: { + return ollamaColumns; + } + case ProviderEnum.Q_FAN: { + return qfanColumns; + } + case ProviderEnum.Q_WEN: { + return qwenColumns; + } + case ProviderEnum.ZHIPU: { + return zhipuColumns; + } + } + return openaiColumns; +} diff --git a/src/views/ai/model/chatModel/composables/consts.ts b/src/views/ai/model/chatModel/composables/consts.ts new file mode 100644 index 0000000..0b003f5 --- /dev/null +++ b/src/views/ai/model/chatModel/composables/consts.ts @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 LangChat. TyCoding All Rights Reserved. + * + * Licensed under the GNU Affero General Public License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ProviderEnum } from './provider'; + +export const LLMProviders: any[] = [ + { + model: ProviderEnum.OPENAI, + name: 'OpenAI', + models: ['gpt-3.5-turbo', 'gpt-4', 'gpt-4-32k', 'gpt-4-turbo', 'gpt-4o'], + }, + { + model: ProviderEnum.Q_FAN, + name: '百度千帆', + models: [ + 'ERNIE-Bot', + 'ERNIE-Bot 4.0', + 'ERNIE-Bot-8K', + 'ERNIE-Bot-turbo', + 'ERNIE-Speed-128K', + 'EB-turbo-AppBuilder', + 'Yi-34B-Chat', + 'BLOOMZ-7B', + 'Qianfan-BLOOMZ-7B-compressed', + 'Mixtral-8x7B-Instruct', + 'Llama-2-7b-chat', + 'Llama-2-13b-chat', + 'Llama-2-70b-chat', + 'Qianfan-Chinese-Llama-2-7B', + 'ChatGLM2-6B-32K', + 'AquilaChat-7B', + ], + }, + { + model: ProviderEnum.Q_WEN, + name: '阿里百炼', + models: [ + 'qwen-turbo', + 'qwen-plus', + 'qwen-max', + 'qwen-max-longcontext', + 'qwen-7b-chat', + 'qwen-14b-chat', + 'qwen-72b-chat', + ], + }, + { + model: ProviderEnum.ZHIPU, + name: '智谱清言', + models: [ + 'glm-4', + 'glm-4v', + 'glm-4-air', + 'glm-4-airx', + 'glm-4-flash', + 'glm-3-turbo', + 'chatglm_turbo', + ], + }, + { + model: ProviderEnum.GITEEAI, + name: 'Gitee AI', + models: [ + 'Qwen2-72B-Instruct', + 'Qwen2-7B-Instruct', + 'Qwen2.5-72B-Instruct', + 'glm-4-9b-chat', + 'deepseek-coder-33B-instruct', + 'codegeex4-all-9b', + 'Yi-34B-Chat', + 'code-raccoon-v1', + 'Qwen2.5-Coder-32B-Instruct', + ], + }, + { + model: ProviderEnum.DEEPSEEK, + name: 'DeepSeek', + models: ['deepseek-chat', 'deepseek-coder'], + }, + { + model: ProviderEnum.DOUYIN, + name: '抖音豆包', + models: [], + }, + { + model: ProviderEnum.SILICON, + name: '硅基流动', + models: [ + 'deepseek-ai/DeepSeek-V2-Chat', + 'deepseek-ai/DeepSeek-Coder-V2-Instruct', + 'deepseek-ai/DeepSeek-V2.5', + 'Qwen/Qwen2.5-72B-Instruct-128K', + 'Qwen/Qwen2.5-72B-Instruct', + 'Qwen/Qwen2-VL-72B-Instruct', + 'Qwen/Qwen2.5-32B-Instruct', + 'Qwen/Qwen2.5-14B-Instruct', + 'Qwen/Qwen2.5-7B-Instruct', + 'Qwen/Qwen2.5-Math-72B-Instruct', + 'Qwen/Qwen2.5-Coder-7B-Instruct', + 'Qwen/Qwen2-72B-Instruct', + 'Qwen/Qwen2-7B-Instruct', + 'Qwen/Qwen2-1.5B-Instruct', + 'Qwen/Qwen2-57B-A14B-Instruct', + 'TeleAI/TeleChat2', + '01-ai/Yi-1.5-34B-Chat-16K', + '01-ai/Yi-1.5-9B-Chat-16K', + '01-ai/Yi-1.5-6B-Chat', + 'THUDM/chatglm3-6b', + 'THUDM/glm-4-9b-chat', + 'Vendor-A/Qwen/Qwen2-72B-Instruct', + 'Vendor-A/Qwen/Qwen2.5-72B-Instruct', + 'internlm/internlm2_5-7b-chat', + 'internlm/internlm2_5-20b-chat', + 'OpenGVLab/InternVL2-Llama3-76B', + 'OpenGVLab/InternVL2-26B', + 'nvidia/Llama-3.1-Nemotron-70B-Instruct', + 'meta-llama/Meta-Llama-3.1-405B-Instruct', + 'meta-llama/Meta-Llama-3.1-70B-Instruct', + 'meta-llama/Meta-Llama-3.1-8B-Instruct', + 'meta-llama/Meta-Llama-3-8B-Instruct', + 'meta-llama/Meta-Llama-3-70B-Instruct', + 'google/gemma-2-27b-it', + 'google/gemma-2-9b-it', + 'Pro/Qwen/Qwen2.5-7B-Instruct', + 'Pro/Qwen/Qwen2-7B-Instruct', + 'Pro/Qwen/Qwen2-1.5B-Instruct', + 'Pro/Qwen/Qwen2-VL-7B-Instruct', + 'Pro/01-ai/Yi-1.5-9B-Chat-16K', + 'Pro/01-ai/Yi-1.5-6B-Chat', + 'Pro/THUDM/chatglm3-6b', + 'Pro/THUDM/glm-4-9b-chat', + 'Pro/internlm/internlm2_5-7b-chat', + 'Pro/OpenGVLab/InternVL2-8B', + 'Pro/meta-llama/Meta-Llama-3-8B-Instruct', + 'Pro/meta-llama/Meta-Llama-3.1-8B-Instruct', + 'Pro/google/gemma-2-9b-it', + ], + }, + { + model: ProviderEnum.YI, + name: '零一万物', + models: [ + 'yi-lightning', + 'yi-large', + 'yi-medium', + 'yi-medium-200k', + 'yi-spark', + 'yi-large-rag', + 'yi-large-turbo', + ], + }, + { + model: ProviderEnum.SPARK, + name: '讯飞星火', + // models: ['lite', 'generalv3', 'pro-128k', 'generalv3.5', 'max-32k', '4.0Ultra'], + models: [ + { label: 'Spark Lite', value: 'lite' }, + { label: 'Spark Pro', value: 'generalv3' }, + { label: 'Spark Pro-128K', value: 'pro-128k' }, + { label: 'Spark Max', value: 'generalv3.5' }, + { label: 'Spark Max-32K', value: 'max-32k' }, + { label: 'Spark4.0 Ultra', value: '4.0Ultra' }, + ], + }, + { + model: ProviderEnum.OLLAMA, + name: 'Ollama', + models: [], + }, + { + model: ProviderEnum.AZURE_OPENAI, + name: 'Azure OpenAI', + models: ['gpt-3.5-turbo', 'gpt-4', 'gpt-4-32k', 'gpt-4-turbo', 'gpt-4o'], + }, + { + model: ProviderEnum.GEMINI, + name: 'Gemini', + models: ['gemini-1.5-pro'], + }, + { + model: ProviderEnum.CLAUDE, + name: 'Claude', + models: ['claude-3-opus', 'claude-3-opus-20240229', 'claude-3-sonnet', 'claude-3-haiku'], + }, +]; diff --git a/src/views/ai/model/chatModel/composables/provider.ts b/src/views/ai/model/chatModel/composables/provider.ts new file mode 100644 index 0000000..b956cdf --- /dev/null +++ b/src/views/ai/model/chatModel/composables/provider.ts @@ -0,0 +1,37 @@ +export enum ProviderEnum { + OPENAI = 'OPENAI', + AZURE_OPENAI = 'AZURE_OPENAI', + GEMINI = 'GEMINI', + OLLAMA = 'OLLAMA', + CLAUDE = 'CLAUDE', + Q_FAN = 'Q_FAN', + Q_WEN = 'Q_WEN', + ZHIPU = 'ZHIPU', + GITEEAI = 'GITEEAI', + DEEPSEEK = 'DEEPSEEK', + DOUYIN = 'DOUYIN', + SILICON = 'SILICON', + YI = 'YI', + SPARK = 'SPARK', +} + +export function getModels(provider: string, providers: Array) { + const arr = providers.filter((i) => i.model === provider); + if (arr.length === 0) { + return []; + } + if (typeof arr[0].models[0] === 'string') { + return arr[0].models.map((i) => { + return { + label: i, + value: i, + }; + }); + } else { + return arr[0].models; + } +} + +export function getTitle(provider: string, providers: Array) { + return providers.filter((i) => i.model === provider)[0].name; +} diff --git a/src/views/ai/model/chatModel/edit.vue b/src/views/ai/model/chatModel/edit.vue new file mode 100644 index 0000000..eb92e45 --- /dev/null +++ b/src/views/ai/model/chatModel/edit.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/src/views/ai/model/chatModel/index.vue b/src/views/ai/model/chatModel/index.vue index c550674..541dcf3 100644 --- a/src/views/ai/model/chatModel/index.vue +++ b/src/views/ai/model/chatModel/index.vue @@ -1,185 +1,125 @@ + + + - + diff --git a/src/views/ai/model/embedStore/composables/index.ts b/src/views/ai/model/embedStore/composables/index.ts new file mode 100644 index 0000000..1d5a2eb --- /dev/null +++ b/src/views/ai/model/embedStore/composables/index.ts @@ -0,0 +1,116 @@ +import {ref} from "vue"; +import {FormSchema} from "@/types/form"; +import {ElTag} from "element-plus"; + +export enum ProviderEnum { + Redis = 'REDIS', + PgVector = 'PGVECTOR', + Milvus = 'MILVUS', +} + + +export default function () { + const ProviderConst = [ + { label: 'Redis', value: ProviderEnum.Redis }, + { label: 'PgVector', value: ProviderEnum.PgVector }, + { label: 'Milvus', value: ProviderEnum.Milvus }, + ]; + function getProviderLabel(value: any) { + const arr = ProviderConst.filter((i) => i.value === value); + if (arr === undefined || arr.length === 0) { + return value; + } + return arr[0].label; + } + const shema = ref([ + { + label: '模型名称', + field: 'name', + component: 'Input', + colProps: { + span: 6 + }, + } + ]) + const columns = ref([ + { + label: '数据库别名', + field: 'name', + align: 'center', + }, + { + label: '供应商', + field: 'provider', + align: 'center', + width: '120', + render(row) { + return h( + ElTag, + { + type: 'success', + }, + { + default: () => getProviderLabel(row.provider), + } + ); + }, + }, + { + label: '向量纬度', + field: 'dimension', + align: 'center', + width: '80', + render(row) { + return h( + ElTag, + { + size: 'small', + }, + { + default: () => row.dimension, + } + ); + }, + }, + { + label: '数据库地址', + field: 'host', + align: 'center', + width: '110', + }, + { + label: '数据库端口', + field: 'port', + align: 'center', + width: '100', + }, + { + label: '数据库用户名', + field: 'username', + align: 'center', + }, + { + label: '数据库密码', + field: 'password', + align: 'center', + }, + { + label: '数据库名', + field: 'databaseName', + align: 'center', + }, + { + label: '表名称', + field: 'tableName', + align: 'center', + }, + ]) + const tableData = ref([]) + return { + ProviderConst, + getProviderLabel, + shema, + columns, + tableData + } +} diff --git a/src/views/ai/model/embedStore/index.vue b/src/views/ai/model/embedStore/index.vue new file mode 100644 index 0000000..aedef94 --- /dev/null +++ b/src/views/ai/model/embedStore/index.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/views/ai/model/embedding/composables/index.ts b/src/views/ai/model/embedding/composables/index.ts new file mode 100644 index 0000000..e7c73f5 --- /dev/null +++ b/src/views/ai/model/embedding/composables/index.ts @@ -0,0 +1,102 @@ +import {ElTag} from "element-plus"; +import {ref} from "vue"; +import {ProviderEnum} from "@/views/ai/model/chatModel/composables/provider"; +import {FormSchema} from "@/types/form"; + +export default function () { + const LLMProviders: any[] = [ + { + model: ProviderEnum.OPENAI, + name: 'OpenAI', + models: ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002'], + }, + { + model: ProviderEnum.Q_FAN, + name: '百度千帆', + models: ['bge-large-zh', 'bge-large-en', 'tao-8k'], + }, + { + model: ProviderEnum.Q_WEN, + name: '阿里百炼', + models: ['text-embedding-v3'], + }, + { + model: ProviderEnum.ZHIPU, + name: '智谱清言', + models: ['embedding-2', 'embedding-3'], + }, + { + model: ProviderEnum.DOUYIN, + name: '抖音豆包', + models: ['text-240715', 'text-240515'], + }, + { + model: ProviderEnum.OLLAMA, + name: 'Ollama', + models: ['text2vec-bge-large-chinese:latest'], + }, + ]; + const baseColumns = [ + { + label: '模型别名', + field: 'name', + }, + { + label: '模型版本', + field: 'model', + width: '160', + }, + { + label: '向量纬度', + field: 'dimension', + align: 'center', + width: '100', + render(row) { + return h( + ElTag, + { + size: 'small', + }, + { + default: () => row.dimension, + } + ); + }, + }, + { + label: 'Api Key', + field: 'apiKey', + }, + { + label: 'Base Url', + field: 'baseUrl', + }, + ]; + const tableData = ref([ + ]) + const shema = ref([ + { + label: '模型名称', + field: 'name', + component: 'Select', + colProps: { + span: 6 + }, + componentProps: { + style: { + width: '150px', + }, + options: LLMProviders.map((item) => ({ + label: item.name, + value: item.model, + })), + }, + + } + ]) + return { + baseColumns, + shema, + tableData + } +} diff --git a/src/views/ai/model/embedding/index.vue b/src/views/ai/model/embedding/index.vue new file mode 100644 index 0000000..8f7ae8f --- /dev/null +++ b/src/views/ai/model/embedding/index.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/views/ai/model/image/composables/index.ts b/src/views/ai/model/image/composables/index.ts new file mode 100644 index 0000000..063e97d --- /dev/null +++ b/src/views/ai/model/image/composables/index.ts @@ -0,0 +1,110 @@ +export default function () { + enum ProviderEnum { + OPENAI = 'OPENAI', + AZURE_OPENAI = 'AZURE_OPENAI', + ZHIPU = 'ZHIPU', + } + + const LLMProviders: any[] = [ + { + model: ProviderEnum.OPENAI, + name: 'OpenAI', + models: ['dall-e-2', 'dall-e-3'], + }, + { + model: ProviderEnum.AZURE_OPENAI, + name: 'Azure OpenAI', + models: ['dall-e-2', 'dall-e-3'], + }, + { + model: ProviderEnum.ZHIPU, + name: '智谱清言', + models: ['cogview-3'], + }, + ] + const formData = ref({ + provider: ProviderEnum.OPENAI, + }); + const tableData = ref([]) + const shema = ref([ + { + field: 'provider', + label: '模型别名', + component: 'Select', + required: true, + componentProps: { + placeholder: '请输入模型别名', + style: { + width: '180px', + }, + options: LLMProviders.map((item) => ({ + label: item.name, + value: item.model, + })), + }, + }, + ]) + + const baseColumns = [ + { + label: '模型别名', + field: 'name', + }, + { + label: '模型版本', + field: 'model', + }, + ]; + + const openaiColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, + ]; + + const azureOpenaiColumns = [ + ...baseColumns, + { + label: 'Api Key', + field: 'apiKey', + }, + { + label: 'Endpoint', + field: 'endpoint', + }, + { + label: 'Deployment Name', + field: 'azureDeploymentName', + }, + ]; + + const zhipuColumns = [...baseColumns]; + function getColumns(provider: string) { + console.log(provider); + switch (provider) { + case ProviderEnum.OPENAI: { + return openaiColumns; + } + case ProviderEnum.AZURE_OPENAI: { + return azureOpenaiColumns; + } + case ProviderEnum.ZHIPU: { + return zhipuColumns; + } + } + return []; + } + const columns = computed(() => { + nextTick(); + return getColumns(formData.value.provider) + }); + return { + LLMProviders, + columns, + tableData, + shema, + formData + } +} diff --git a/src/views/ai/model/image/index.vue b/src/views/ai/model/image/index.vue new file mode 100644 index 0000000..2ee54bc --- /dev/null +++ b/src/views/ai/model/image/index.vue @@ -0,0 +1,26 @@ + + + + +