feat: add preset and edit preset.

This commit is contained in:
Wentao Lyu 2023-04-02 04:15:07 +08:00
parent 80ef5008dd
commit 45e17da241
29 changed files with 592 additions and 493 deletions

View file

@ -0,0 +1,56 @@
const buildPresetByConversation = ({ title, conversation, ...others }) => {
const { endpoint } = conversation;
let preset = {};
if (endpoint === 'azureOpenAI' || endpoint === 'openAI') {
preset = {
endpoint,
model: conversation?.model || 'gpt-3.5-turbo',
chatGptLabel: conversation?.chatGptLabel || null,
promptPrefix: conversation?.promptPrefix || null,
temperature: conversation?.temperature || 1,
top_p: conversation?.top_p || 1,
presence_penalty: conversation?.presence_penalty || 0,
frequency_penalty: conversation?.frequency_penalty || 0,
title,
...others
};
} else if (endpoint === 'bingAI') {
preset = {
endpoint,
jailbreak: conversation?.jailbreak || false,
jailbreakConversationId: conversation?.jailbreakConversationId || null,
conversationSignature: null,
clientId: null,
invocationId: 1,
toneStyle: conversation?.toneStyle || 'fast',
title,
...others
};
} else if (endpoint === 'chatGPTBrowser') {
preset = {
endpoint,
model: conversation?.model || 'text-davinci-002-render-sha',
title,
...others
};
} else if (endpoint === null) {
preset = {
...conversation,
endpoint,
title,
...others
};
} else {
console.error(`Unknown endpoint ${endpoint}`);
preset = {
endpoint: null,
title,
...others
};
}
return preset;
};
export default buildPresetByConversation;

View file

@ -3,14 +3,19 @@ import axios from 'axios';
import useSWR from 'swr';
import useSWRMutation from 'swr/mutation';
const fetcher = (url) => fetch(url, { credentials: 'include' }).then((res) => res.json());
const fetcher = url => fetch(url, { credentials: 'include' }).then(res => res.json());
const axiosFetcher = async (url, params) => {
console.log(params, 'params');
return axios.get(url, params);
};
const postRequest = async (url, { arg }) => {
return await axios.post(url, { withCredentials: true, arg });
export const postRequest = async (url, { arg }) => {
return await axios({
method: 'post',
url: url,
withCredentials: true,
data: { arg }
});
};
export const searchFetcher = async (pre, q, pageNumber, callback) => {

View file

@ -44,7 +44,9 @@ const buildDefaultConversation = ({ conversation, endpoint, lastConversationSetu
return conversation;
};
const getDefaultConversation = ({ conversation, prevConversation, endpointsFilter, targetEndpoint }) => {
const getDefaultConversation = ({ conversation, prevConversation, endpointsFilter, preset }) => {
const { endpoint: targetEndpoint } = preset || {};
if (targetEndpoint) {
// try to use current model
const endpoint = targetEndpoint;
@ -52,7 +54,7 @@ const getDefaultConversation = ({ conversation, prevConversation, endpointsFilte
conversation = buildDefaultConversation({
conversation,
endpoint,
lastConversationSetup: {}
lastConversationSetup: preset
});
return conversation;
} else {