This commit is contained in:
archer
2023-07-01 13:09:02 +08:00
parent 4c54e1821b
commit 9bdd5f522d
85 changed files with 4738 additions and 1236 deletions

View File

@@ -1,5 +1,5 @@
import { GET, POST, DELETE, PUT } from './request';
import type { ModelSchema } from '@/types/mongoSchema';
import type { AppSchema } from '@/types/mongoSchema';
import type { ModelUpdateParams } from '@/types/model';
import { RequestPaging } from '../types/index';
import type { ModelListResponse } from './response/model';
@@ -22,13 +22,13 @@ export const delModelById = (id: string) => DELETE(`/model/del?modelId=${id}`);
/**
* ID
*/
export const getModelById = (id: string) => GET<ModelSchema>(`/model/detail?modelId=${id}`);
export const getModelById = (id: string) => GET<AppSchema>(`/model/detail?modelId=${id}`);
/**
* ID
*/
export const putModelById = (id: string, data: ModelUpdateParams) =>
PUT(`/model/update?modelId=${id}`, data);
export const putAppById = (id: string, data: ModelUpdateParams) =>
PUT(`/model/update?appId=${id}`, data);
/* 共享市场 */
/**

View File

@@ -1,4 +1,4 @@
import { Props, ChatResponseType } from '@/pages/api/openapi/v1/chat/completions';
import { Props } from '@/pages/api/openapi/v1/chat/completions';
import { sseResponseEventEnum } from '@/constants/chat';
import { getErrText } from '@/utils/tools';
import { parseStreamChunk } from '@/utils/adapt';
@@ -9,10 +9,10 @@ interface StreamFetchProps {
abortSignal: AbortController;
}
export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps) =>
new Promise<ChatResponseType & { responseText: string; errMsg: string }>(
new Promise<{ responseText: string; errMsg: string; newChatId: string | null }>(
async (resolve, reject) => {
try {
const response = await window.fetch('/api/openapi/v1/chat/test', {
const response = await window.fetch('/api/openapi/v1/chat/completions2', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@@ -37,9 +37,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
// response data
let responseText = '';
let newChatId = '';
let quoteLen = 0;
let errMsg = '';
const newChatId = response.headers.get('newChatId');
const read = async () => {
try {
@@ -48,9 +47,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
if (response.status === 200) {
return resolve({
responseText,
newChatId,
quoteLen,
errMsg
errMsg,
newChatId
});
} else {
return reject('响应过程出现异常~');
@@ -72,11 +70,6 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
const answer: string = data?.choices?.[0].delta.content || '';
onMessage(answer);
responseText += answer;
} else if (item.event === sseResponseEventEnum.chatResponse) {
const chatResponse = data as ChatResponseType;
newChatId =
chatResponse.newChatId !== undefined ? chatResponse.newChatId : newChatId;
quoteLen = chatResponse.quoteLen !== undefined ? chatResponse.quoteLen : quoteLen;
} else if (item.event === sseResponseEventEnum.error) {
errMsg = getErrText(data, '流响应错误');
}
@@ -86,9 +79,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
if (err?.message === 'The user aborted a request.') {
return resolve({
responseText,
newChatId,
quoteLen,
errMsg
errMsg,
newChatId
});
}
reject(getErrText(err, '请求异常'));

View File

@@ -1,4 +1,4 @@
import type { ChatPopulate, ModelSchema } from '@/types/mongoSchema';
import type { ChatPopulate, AppSchema } from '@/types/mongoSchema';
import type { ChatItemType } from '@/types/chat';
export interface InitChatResponse {
@@ -12,7 +12,7 @@ export interface InitChatResponse {
intro: string;
canUse: boolean;
};
chatModel: ModelSchema['chat']['chatModel']; // 对话模型名
chatModel: AppSchema['chat']['chatModel']; // 对话模型名
history: ChatItemType[];
}
@@ -24,5 +24,5 @@ export interface InitShareChatResponse {
avatar: string;
intro: string;
};
chatModel: ModelSchema['chat']['chatModel']; // 对话模型名
chatModel: AppSchema['chat']['chatModel']; // 对话模型名
}

View File

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