mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-16 22:51:24 +00:00
refactor: Add frontend code to DB-GPT (#912)
This commit is contained in:
66
web/utils/constants.ts
Normal file
66
web/utils/constants.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { ModelType } from '@/types/chat';
|
||||
import { DBType } from '@/types/db';
|
||||
|
||||
export const MODEL_ICON_MAP: Record<ModelType, { label: string; icon: string }> = {
|
||||
proxyllm: { label: 'Proxy LLM', icon: '/models/chatgpt.png' },
|
||||
'flan-t5-base': { label: 'flan-t5-base', icon: '/models/google.png' },
|
||||
'vicuna-13b': { label: 'vicuna-13b', icon: '/models/vicuna.jpeg' },
|
||||
'vicuna-7b': { label: 'vicuna-7b', icon: '/models/vicuna.jpeg' },
|
||||
'vicuna-13b-v1.5': { label: 'vicuna-13b-v1.5', icon: '/models/vicuna.jpeg' },
|
||||
'vicuna-7b-v1.5': { label: 'vicuna-7b-v1.5', icon: '/models/vicuna.jpeg' },
|
||||
'codegen2-1b': { label: 'codegen2-1B', icon: '/models/vicuna.jpeg' },
|
||||
'codet5p-2b': { label: 'codet5p-2b', icon: '/models/vicuna.jpeg' },
|
||||
'chatglm-6b-int4': { label: 'chatglm-6b-int4', icon: '/models/chatglm.png' },
|
||||
'chatglm-6b': { label: 'chatglm-6b', icon: '/models/chatglm.png' },
|
||||
'chatglm2-6b': { label: 'chatglm2-6b', icon: '/models/chatglm.png' },
|
||||
'chatglm2-6b-int4': { label: 'chatglm2-6b-int4', icon: '/models/chatglm.png' },
|
||||
'guanaco-33b-merged': { label: 'guanaco-33b-merged', icon: '/models/huggingface.svg' },
|
||||
'falcon-40b': { label: 'falcon-40b', icon: '/models/falcon.jpeg' },
|
||||
'gorilla-7b': { label: 'gorilla-7b', icon: '/models/gorilla.png' },
|
||||
'gptj-6b': { label: 'ggml-gpt4all-j-v1.3-groovy.bin', icon: '' },
|
||||
chatgpt_proxyllm: { label: 'chatgpt_proxyllm', icon: '/models/chatgpt.png' },
|
||||
bard_proxyllm: { label: 'bard_proxyllm', icon: '/models/bard.gif' },
|
||||
claude_proxyllm: { label: 'claude_proxyllm', icon: '/models/claude.png' },
|
||||
wenxin_proxyllm: { label: 'wenxin_proxyllm', icon: '' },
|
||||
tongyi_proxyllm: { label: 'tongyi_proxyllm', icon: '/models/qwen2.png' },
|
||||
zhipu_proxyllm: { label: 'zhipu_proxyllm', icon: '/models/zhipu.png' },
|
||||
'llama-2-7b': { label: 'Llama-2-7b-chat-hf', icon: '/models/llama.jpg' },
|
||||
'llama-2-13b': { label: 'Llama-2-13b-chat-hf', icon: '/models/llama.jpg' },
|
||||
'llama-2-70b': { label: 'Llama-2-70b-chat-hf', icon: '/models/llama.jpg' },
|
||||
'baichuan-13b': { label: 'Baichuan-13B-Chat', icon: '/models/baichuan.png' },
|
||||
'baichuan-7b': { label: 'baichuan-7b', icon: '/models/baichuan.png' },
|
||||
'baichuan2-7b': { label: 'Baichuan2-7B-Chat', icon: '/models/baichuan.png' },
|
||||
'baichuan2-13b': { label: 'Baichuan2-13B-Chat', icon: '/models/baichuan.png' },
|
||||
'wizardlm-13b': { label: 'WizardLM-13B-V1.2', icon: '/models/wizardlm.png' },
|
||||
'llama-cpp': { label: 'ggml-model-q4_0.bin', icon: '/models/huggingface.svg' },
|
||||
'internlm-7b': { label: 'internlm-chat-7b-v1_1', icon: '/models/internlm.png' },
|
||||
'internlm-7b-8k': { label: 'internlm-chat-7b-8k', icon: '/models/internlm.png' },
|
||||
};
|
||||
|
||||
export const VECTOR_ICON_MAP: Record<string, string> = {
|
||||
Chroma: '/models/chroma-logo.png',
|
||||
};
|
||||
|
||||
export const dbMapper: Record<DBType, { label: string; icon: string; desc: string }> = {
|
||||
mysql: { label: 'MySQL', icon: '/icons/mysql.png', desc: 'Fast, reliable, scalable open-source relational database management system.' },
|
||||
mssql: { label: 'MSSQL', icon: '/icons/mssql.png', desc: 'Powerful, scalable, secure relational database system by Microsoft.' },
|
||||
duckdb: { label: 'DuckDB', icon: '/icons/duckdb.png', desc: 'In-memory analytical database with efficient query processing.' },
|
||||
sqlite: { label: 'Sqlite', icon: '/icons/sqlite.png', desc: 'Lightweight embedded relational database with simplicity and portability.' },
|
||||
clickhouse: { label: 'ClickHouse', icon: '/icons/clickhouse.png', desc: 'Columnar database for high-performance analytics and real-time queries.' },
|
||||
oracle: { label: 'Oracle', icon: '/icons/oracle.png', desc: 'Robust, scalable, secure relational database widely used in enterprises.' },
|
||||
access: { label: 'Access', icon: '/icons/access.png', desc: 'Easy-to-use relational database for small-scale applications by Microsoft.' },
|
||||
mongodb: { label: 'MongoDB', icon: '/icons/mongodb.png', desc: 'Flexible, scalable NoSQL document database for web and mobile apps.' },
|
||||
starrocks: { label: 'StarRocks', icon: '/icons/starrocks.png', desc: 'An Open-Source, High-Performance Analytical Database.' },
|
||||
db2: { label: 'DB2', icon: '/icons/db2.png', desc: 'Scalable, secure relational database system developed by IBM.' },
|
||||
hbase: { label: 'HBase', icon: '/icons/hbase.png', desc: 'Distributed, scalable NoSQL database for large structured/semi-structured data.' },
|
||||
redis: { label: 'Redis', icon: '/icons/redis.png', desc: 'Fast, versatile in-memory data structure store as cache, DB, or broker.' },
|
||||
cassandra: { label: 'Cassandra', icon: '/icons/cassandra.png', desc: 'Scalable, fault-tolerant distributed NoSQL database for large data.' },
|
||||
couchbase: { label: 'Couchbase', icon: '/icons/couchbase.png', desc: 'High-performance NoSQL document database with distributed architecture.' },
|
||||
postgresql: {
|
||||
label: 'PostgreSQL',
|
||||
icon: '/icons/postgresql.png',
|
||||
desc: 'Powerful open-source relational database with extensibility and SQL standards.',
|
||||
},
|
||||
spark: { label: 'Spark', icon: '/icons/spark.png', desc: 'Unified engine for large-scale data analytics.' },
|
||||
space: { label: 'Space', icon: '/icons/knowledge.png', desc: 'knowledge analytics.' },
|
||||
};
|
14
web/utils/ctx-axios.ts
Normal file
14
web/utils/ctx-axios.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: process.env.API_BASE_URL,
|
||||
});
|
||||
|
||||
api.defaults.timeout = 10000;
|
||||
|
||||
api.interceptors.response.use(
|
||||
response => response.data,
|
||||
err => Promise.reject(err)
|
||||
);
|
||||
|
||||
export default api;
|
9
web/utils/index.ts
Normal file
9
web/utils/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/** Theme */
|
||||
export const STORAGE_THEME_KEY = '__db_gpt_theme_key';
|
||||
/** Language */
|
||||
export const STORAGE_LANG_KEY = '__db_gpt_lng_key';
|
||||
/** Init Message */
|
||||
export const STORAGE_INIT_MESSAGE_KET = '__db_gpt_im_key';
|
||||
|
||||
export * from './storage';
|
||||
export * from './constants';
|
99
web/utils/request.ts
Normal file
99
web/utils/request.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { message } from 'antd';
|
||||
import axios from './ctx-axios';
|
||||
import { isPlainObject } from 'lodash';
|
||||
|
||||
const DEFAULT_HEADERS = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
// body 字段 trim
|
||||
const sanitizeBody = (obj: Record<string, any>): string => {
|
||||
// simple shallow copy to avoid changing original obj
|
||||
if (!isPlainObject(obj)) return JSON.stringify(obj);
|
||||
const resObj = { ...obj };
|
||||
for (const key in resObj) {
|
||||
const val = resObj[key];
|
||||
if (typeof val === 'string') {
|
||||
resObj[key] = val.trim();
|
||||
}
|
||||
}
|
||||
return JSON.stringify(resObj);
|
||||
};
|
||||
|
||||
export const sendGetRequest = (url: string, qs?: { [key: string]: any }) => {
|
||||
if (qs) {
|
||||
const str = Object.keys(qs)
|
||||
.filter((k) => qs[k] !== undefined && qs[k] !== '')
|
||||
.map((k) => `${k}=${qs[k]}`)
|
||||
.join('&');
|
||||
if (str) {
|
||||
url += `?${str}`;
|
||||
}
|
||||
}
|
||||
return axios
|
||||
.get<null, any>('/api' + url, {
|
||||
headers: DEFAULT_HEADERS,
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
message.error(err);
|
||||
Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
export const sendSpaceGetRequest = (url: string, qs?: { [key: string]: any }) => {
|
||||
if (qs) {
|
||||
const str = Object.keys(qs)
|
||||
.filter((k) => qs[k] !== undefined && qs[k] !== '')
|
||||
.map((k) => `${k}=${qs[k]}`)
|
||||
.join('&');
|
||||
if (str) {
|
||||
url += `?${str}`;
|
||||
}
|
||||
}
|
||||
return axios
|
||||
.get<null, any>(url, {
|
||||
headers: DEFAULT_HEADERS,
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
message.error(err);
|
||||
Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
export const sendPostRequest = (url: string, body?: any) => {
|
||||
const reqBody = sanitizeBody(body);
|
||||
return axios
|
||||
.post<null, any>('/api' + url, {
|
||||
body: reqBody,
|
||||
headers: DEFAULT_HEADERS,
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
message.error(err);
|
||||
Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
export const sendSpacePostRequest = (url: string, body?: any) => {
|
||||
return axios
|
||||
.post<null, any>(url, body, {
|
||||
headers: DEFAULT_HEADERS,
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
message.error(err);
|
||||
Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
export const sendSpaceUploadPostRequest = (url: string, body?: any) => {
|
||||
return axios
|
||||
.post<null, any>(url, body)
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
message.error(err);
|
||||
Promise.reject(err);
|
||||
});
|
||||
};
|
11
web/utils/storage.ts
Normal file
11
web/utils/storage.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { STORAGE_INIT_MESSAGE_KET } from '@/utils';
|
||||
|
||||
export function getInitMessage() {
|
||||
const value = localStorage.getItem(STORAGE_INIT_MESSAGE_KET) ?? '';
|
||||
try {
|
||||
const initData = JSON.parse(value) as { id: string; message: string };
|
||||
return initData;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user