Commit cdf4b9f3 by archer

perf: prompt and gpt4

parent e3c9b817
import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios'; import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { clearToken } from '@/utils/user'; import { clearCookie } from '@/utils/user';
import { TOKEN_ERROR_CODE } from '@/service/errorCode'; import { TOKEN_ERROR_CODE } from '@/service/errorCode';
interface ConfigType { interface ConfigType {
...@@ -58,7 +58,7 @@ function responseError(err: any) { ...@@ -58,7 +58,7 @@ function responseError(err: any) {
// 有报错响应 // 有报错响应
const res = err.response; const res = err.response;
if (res.data.code in TOKEN_ERROR_CODE) { if (res.data.code in TOKEN_ERROR_CODE) {
clearToken(); clearCookie();
return Promise.reject({ message: 'token过期,重新登录' }); return Promise.reject({ message: 'token过期,重新登录' });
} }
} }
......
...@@ -64,6 +64,8 @@ export const postLogin = ({ username, password }: { username: string; password: ...@@ -64,6 +64,8 @@ export const postLogin = ({ username, password }: { username: string; password:
password: createHashPassword(password) password: createHashPassword(password)
}); });
export const loginOut = () => GET('/user/loginout');
export const putUserInfo = (data: UserUpdateParams) => PUT('/user/update', data); export const putUserInfo = (data: UserUpdateParams) => PUT('/user/update', data);
export const getUserBills = (data: RequestPaging) => export const getUserBills = (data: RequestPaging) =>
......
...@@ -29,7 +29,7 @@ export const ChatModelMap = { ...@@ -29,7 +29,7 @@ export const ChatModelMap = {
name: 'ChatGpt', name: 'ChatGpt',
contextMaxToken: 4096, contextMaxToken: 4096,
systemMaxToken: 2500, systemMaxToken: 2500,
maxTemperature: 1.5, maxTemperature: 1.2,
price: 3 price: 3
}, },
[OpenAiChatEnum.GPT4]: { [OpenAiChatEnum.GPT4]: {
...@@ -37,16 +37,16 @@ export const ChatModelMap = { ...@@ -37,16 +37,16 @@ export const ChatModelMap = {
name: 'Gpt4', name: 'Gpt4',
contextMaxToken: 8000, contextMaxToken: 8000,
systemMaxToken: 3500, systemMaxToken: 3500,
maxTemperature: 1.5, maxTemperature: 1.2,
price: 30 price: 50
}, },
[OpenAiChatEnum.GPT432k]: { [OpenAiChatEnum.GPT432k]: {
chatModel: OpenAiChatEnum.GPT432k, chatModel: OpenAiChatEnum.GPT432k,
name: 'Gpt4-32k', name: 'Gpt4-32k',
contextMaxToken: 32000, contextMaxToken: 32000,
systemMaxToken: 6000, systemMaxToken: 6000,
maxTemperature: 1.5, maxTemperature: 1.2,
price: 30 price: 90
}, },
[ClaudeEnum.Claude]: { [ClaudeEnum.Claude]: {
chatModel: ClaudeEnum.Claude, chatModel: ClaudeEnum.Claude,
...@@ -60,6 +60,7 @@ export const ChatModelMap = { ...@@ -60,6 +60,7 @@ export const ChatModelMap = {
export const chatModelList: ChatModelItemType[] = [ export const chatModelList: ChatModelItemType[] = [
ChatModelMap[OpenAiChatEnum.GPT35], ChatModelMap[OpenAiChatEnum.GPT35],
ChatModelMap[OpenAiChatEnum.GPT4],
ChatModelMap[ClaudeEnum.Claude] ChatModelMap[ClaudeEnum.Claude]
]; ];
......
...@@ -68,11 +68,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -68,11 +68,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.send(searchPrompts[0]?.value); return res.send(searchPrompts[0]?.value);
} }
prompts.splice(prompts.length - 1, 0, ...searchPrompts); prompts.splice(prompts.length - 3, 0, ...searchPrompts);
} else { } else {
// 没有用知识库搜索,仅用系统提示词 // 没有用知识库搜索,仅用系统提示词
model.chat.systemPrompt && model.chat.systemPrompt &&
prompts.splice(prompts.length - 1, 0, { prompts.splice(prompts.length - 3, 0, {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: model.chat.systemPrompt value: model.chat.systemPrompt
}); });
......
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { clearCookie } from '@/service/utils/tools';
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
clearCookie(res);
jsonRes(res);
} catch (err) {
jsonRes(res, {
code: 500,
error: err
});
}
}
...@@ -7,7 +7,7 @@ import { useToast } from '@/hooks/useToast'; ...@@ -7,7 +7,7 @@ import { useToast } from '@/hooks/useToast';
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import { useUserStore } from '@/store/user'; import { useUserStore } from '@/store/user';
import { UserType } from '@/types/user'; import { UserType } from '@/types/user';
import { clearToken } from '@/utils/user'; import { clearCookie } from '@/utils/user';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
...@@ -75,7 +75,7 @@ const NumberSetting = () => { ...@@ -75,7 +75,7 @@ const NumberSetting = () => {
); );
const onclickLogOut = useCallback(() => { const onclickLogOut = useCallback(() => {
clearToken(); clearCookie();
setUserInfo(null); setUserInfo(null);
router.replace('/login'); router.replace('/login');
}, [router, setUserInfo]); }, [router, setUserInfo]);
......
...@@ -81,7 +81,7 @@ const OpenApi = () => { ...@@ -81,7 +81,7 @@ const OpenApi = () => {
mr={4} mr={4}
variant={'outline'} variant={'outline'}
onClick={() => { onClick={() => {
copyData(`${location.origin}?inviterId=${userInfo?._id}`, '已复制邀请链接'); copyData(`${location.origin}/?inviterId=${userInfo?._id}`, '已复制邀请链接');
}} }}
> >
复制邀请链接 复制邀请链接
......
...@@ -105,11 +105,11 @@ export const searchKb = async ({ ...@@ -105,11 +105,11 @@ export const searchKb = async ({
: [ : [
{ {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: `我们来玩问答游戏,规则为: value: `我们在玩问答游戏,规则为:
1.你完全忘记你已有的知识 1.你完全忘记你已有的知识
2.你只能回答关于"${model.name}"的问题 2.你只能回答关于"${model.name}"的问题
3.你只能从知识库中选择内容进行回答 3.你只能从知识库中选择内容进行回答
4.如果问题不在知识库中,你会回答"我不知道。" 4.如果问题不在知识库中,你必须回答:我不知道。
务必遵守规则` 务必遵守规则`
} }
]) ])
...@@ -161,7 +161,7 @@ export const searchKb = async ({ ...@@ -161,7 +161,7 @@ export const searchKb = async ({
searchPrompts: [ searchPrompts: [
{ {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: `知识库:'${filterSystemPrompt}'` value: `知识库:${filterSystemPrompt}`
}, },
...fixedPrompts ...fixedPrompts
] ]
......
...@@ -55,11 +55,11 @@ export const getApiKey = async ({ ...@@ -55,11 +55,11 @@ export const getApiKey = async ({
}, },
[OpenAiChatEnum.GPT4]: { [OpenAiChatEnum.GPT4]: {
userOpenAiKey: user.openaiKey || '', userOpenAiKey: user.openaiKey || '',
systemAuthKey: process.env.OPENAIKEY as string systemAuthKey: process.env.GPT4KEY as string
}, },
[OpenAiChatEnum.GPT432k]: { [OpenAiChatEnum.GPT432k]: {
userOpenAiKey: user.openaiKey || '', userOpenAiKey: user.openaiKey || '',
systemAuthKey: process.env.OPENAIKEY as string systemAuthKey: process.env.GPT4KEY as string
}, },
[ClaudeEnum.Claude]: { [ClaudeEnum.Claude]: {
userOpenAiKey: '', userOpenAiKey: '',
......
...@@ -25,9 +25,9 @@ export const lafClaudChat = async ({ ...@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
.filter((item) => item.obj === 'System') .filter((item) => item.obj === 'System')
.map((item) => item.value) .map((item) => item.value)
.join('\n'); .join('\n');
const systemPromptText = systemPrompt ? `\n知识库内容:'${systemPrompt}'\n` : ''; const systemPromptText = systemPrompt ? `你本次知识:${systemPrompt}\n` : '';
const prompt = `${systemPromptText}\n我的问题是:'${messages[messages.length - 1].value}'`; const prompt = `${systemPromptText}我的问题是:'${messages[messages.length - 1].value}'`;
const lafResponse = await axios.post( const lafResponse = await axios.post(
'https://hnvacz.laf.run/claude-gpt', 'https://hnvacz.laf.run/claude-gpt',
......
...@@ -118,8 +118,8 @@ export const ChatContextFilter = ({ ...@@ -118,8 +118,8 @@ export const ChatContextFilter = ({
messages: chats messages: chats
}); });
/* 整体 tokens 超出范围 */ /* 整体 tokens 超出范围, system必须保留 */
if (tokens >= maxTokens) { if (tokens >= maxTokens && formatPrompts[i].obj !== ChatRoleEnum.System) {
return chats.slice(1); return chats.slice(1);
} }
} }
......
import { PRICE_SCALE } from '@/constants/common'; import { PRICE_SCALE } from '@/constants/common';
const tokenKey = 'fast-gpt-token'; import { loginOut } from '@/api/user';
export const clearToken = () => { export const clearCookie = () => {
document.cookie = 'token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; try {
loginOut();
} catch (error) {
error;
}
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment