fix: variable input and update chat time
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { NextApiResponse } from 'next';
|
||||
import { sseResponse } from '@/service/utils/tools';
|
||||
import { OpenAiChatEnum } from '@/constants/model';
|
||||
import { adaptChatItem_openAI, countOpenAIToken } from '@/utils/plugin/openai';
|
||||
import { modelToolMap } from '@/utils/plugin';
|
||||
import { ChatContextFilter } from '@/service/utils/chat/index';
|
||||
@@ -198,7 +197,6 @@ function filterQuote({
|
||||
model: ChatModelItemType;
|
||||
}) {
|
||||
const sliceResult = modelToolMap.tokenSlice({
|
||||
model: model.model,
|
||||
maxToken: model.quoteMaxToken,
|
||||
messages: quoteQA.map((item) => ({
|
||||
obj: ChatRoleEnum.System,
|
||||
@@ -312,7 +310,6 @@ function getMaxTokens({
|
||||
/* count response max token */
|
||||
|
||||
const promptsToken = modelToolMap.countTokens({
|
||||
model: model.model,
|
||||
messages: filterMessages
|
||||
});
|
||||
maxToken = maxToken + promptsToken > tokensLimit ? tokensLimit - promptsToken : maxToken;
|
||||
@@ -383,7 +380,6 @@ async function streamResponse({
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ChatItemType } from '@/types/chat';
|
||||
import { modelToolMap } from '@/utils/plugin';
|
||||
import { ChatRoleEnum } from '@/constants/chat';
|
||||
import { OpenAiChatEnum } from '@/constants/model';
|
||||
import type { NextApiResponse } from 'next';
|
||||
|
||||
export type ChatCompletionResponseType = {
|
||||
@@ -14,7 +13,7 @@ export type StreamResponseType = {
|
||||
chatResponse: any;
|
||||
prompts: ChatItemType[];
|
||||
res: NextApiResponse;
|
||||
model: `${OpenAiChatEnum}`;
|
||||
model: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
@@ -45,7 +44,6 @@ export const ChatContextFilter = ({
|
||||
|
||||
// reduce token of systemPrompt
|
||||
maxTokens -= modelToolMap.countTokens({
|
||||
model,
|
||||
messages: systemPrompts
|
||||
});
|
||||
|
||||
@@ -57,7 +55,6 @@ export const ChatContextFilter = ({
|
||||
chats.unshift(chatPrompts[i]);
|
||||
|
||||
const tokens = modelToolMap.countTokens({
|
||||
model,
|
||||
messages: chats
|
||||
});
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export async function saveChat({
|
||||
];
|
||||
|
||||
if (chatHistory) {
|
||||
promise.push([
|
||||
promise.push(
|
||||
Chat.updateOne(
|
||||
{ chatId, userId },
|
||||
{
|
||||
@@ -52,7 +52,7 @@ export async function saveChat({
|
||||
updateTime: new Date()
|
||||
}
|
||||
)
|
||||
]);
|
||||
);
|
||||
} else {
|
||||
promise.push(
|
||||
Chat.create({
|
||||
|
||||
Reference in New Issue
Block a user