feat: new ui

This commit is contained in:
archer
2023-05-04 23:30:59 +08:00
parent 4d043e0e46
commit 014fb504a4
133 changed files with 2426 additions and 1696 deletions

View File

@@ -1,18 +1,19 @@
import { GET, POST, DELETE } from './request';
import type { ChatItemType } from '@/types/chat';
import type { ChatItemType, HistoryItemType } from '@/types/chat';
import type { InitChatResponse } from './response/chat';
import { RequestPaging } from '../types/index';
/**
* 获取初始化聊天内容
*/
export const getInitChatSiteInfo = (modelId: string, chatId: '' | string) =>
export const getInitChatSiteInfo = (modelId: '' | string, chatId: '' | string) =>
GET<InitChatResponse>(`/chat/init?modelId=${modelId}&chatId=${chatId}`);
/**
* 获取历史记录
*/
export const getChatHistory = () =>
GET<{ _id: string; title: string; modelId: string }[]>('/chat/getHistory');
export const getChatHistory = (data: RequestPaging) =>
POST<HistoryItemType[]>('/chat/getHistory', data);
/**
* 删除一条历史记录

View File

@@ -1,4 +1,3 @@
import { getToken } from '../utils/user';
import { SYSTEM_PROMPT_HEADER, NEW_CHATID_HEADER } from '@/constants/chat';
interface StreamFetchProps {
@@ -14,8 +13,7 @@ export const streamFetch = ({ url, data, onMessage, abortSignal }: StreamFetchPr
const res = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: getToken() || ''
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
signal: abortSignal.signal

View File

@@ -1,13 +1,14 @@
import { GET, POST, DELETE, PUT } from './request';
import type { ModelSchema, ModelDataSchema } from '@/types/mongoSchema';
import { ModelUpdateParams, ShareModelItem } from '@/types/model';
import type { ModelUpdateParams, ShareModelItem } from '@/types/model';
import { RequestPaging } from '../types/index';
import { Obj2Query } from '@/utils/tools';
import type { ModelListResponse } from './response/model';
/**
* 获取模型列表
*/
export const getMyModels = () => GET<ModelSchema[]>('/model/list');
export const getMyModels = () => GET<ModelListResponse>('/model/list');
/**
* 创建一个模型
@@ -100,7 +101,7 @@ export const delOneModelData = (dataId: string) =>
export const getShareModelList = (data: { searchText?: string } & RequestPaging) =>
POST(`/model/share/getModels`, data);
/**
* 获取收藏的模型
* 获取收藏的模型
*/
export const getCollectionModels = () => GET<ShareModelItem[]>(`/model/share/getCollection`);
/**

View File

@@ -1,5 +1,5 @@
import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { getToken, clearToken } from '@/utils/user';
import { clearToken } from '@/utils/user';
import { TOKEN_ERROR_CODE } from '@/service/errorCode';
interface ConfigType {
@@ -17,7 +17,7 @@ interface ResponseDataType {
*/
function requestStart(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig {
if (config.headers) {
config.headers.Authorization = getToken();
// config.headers.Authorization = getToken();
}
return config;

View File

@@ -1,12 +1,15 @@
import type { ChatPopulate, ModelSchema } from '@/types/mongoSchema';
import type { ChatItemType } from '@/types/chat';
export type InitChatResponse = {
export interface InitChatResponse {
chatId: string;
modelId: string;
name: string;
avatar: string;
intro: string;
model: {
name: string;
avatar: string;
intro: string;
canUse: boolean;
};
chatModel: ModelSchema['chat']['chatModel']; // 对话模型名
history: ChatItemType[];
};
}

6
src/api/response/model.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
import { ModelListItemType } from '@/types/model';
export type ModelListResponse = {
myModels: ModelListItemType[];
myCollectionModels: ModelListItemType[];
};

View File

@@ -1,7 +1,6 @@
import type { UserType } from '@/types/user';
import type { PromotionRecordSchema } from '@/types/mongoSchema';
export interface ResLogin {
token: string;
user: UserType;
}