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

@ -27,7 +27,6 @@ import getDefaultConversation from '~/utils/getDefaultConversation';
// clientId: null,
// invocationId: 1,
// toneStyle: null,
// suggestions: []
// };
const conversation = atom({
@ -62,10 +61,10 @@ const useConversation = () => {
const switchToConversation = useRecoilCallback(
({ snapshot }) =>
async (_conversation, messages = null, targetEndpoint = null) => {
async (_conversation, messages = null, preset = null) => {
const prevConversation = await snapshot.getPromise(conversation);
const endpointsFilter = await snapshot.getPromise(endpoints.endpointsFilter);
_switchToConversation(_conversation, messages, targetEndpoint, {
_switchToConversation(_conversation, messages, preset, {
endpointsFilter,
prevConversation
});
@ -76,7 +75,7 @@ const useConversation = () => {
const _switchToConversation = (
conversation,
messages = null,
targetEndpoint = null,
preset = null,
{ endpointsFilter = {}, prevConversation = {} }
) => {
let { endpoint = null } = conversation;
@ -87,7 +86,7 @@ const useConversation = () => {
conversation,
endpointsFilter,
prevConversation,
targetEndpoint
preset
});
setConversation(conversation);
@ -95,7 +94,7 @@ const useConversation = () => {
resetLatestMessage();
};
const newConversation = (template = {}, targetEndpoint = null) => {
const newConversation = (template = {}, preset) => {
switchToConversation(
{
conversationId: 'new',
@ -103,7 +102,7 @@ const useConversation = () => {
...template
},
[],
targetEndpoint
preset
);
};

View file

@ -6,6 +6,7 @@ import user from './user';
import text from './text';
import submission from './submission';
import search from './search';
import preset from './preset';
export default {
...conversation,
@ -15,5 +16,6 @@ export default {
...user,
text,
...submission,
...search
...search,
...preset
};

View file

@ -0,0 +1,40 @@
import endpoints from './endpoints';
import { atom, selector, useSetRecoilState, useResetRecoilState, useRecoilCallback } from 'recoil';
// preset structure is as same defination as conversation
// sample structure
// {
// presetId: 'new',
// title: 'New Chat',
// user: null,
// // endpoint: [azureOpenAI, openAI, bingAI, chatGPTBrowser]
// endpoint: 'azureOpenAI',
// // for azureOpenAI, openAI, chatGPTBrowser only
// model: 'gpt-3.5-turbo',
// // for azureOpenAI, openAI only
// chatGptLabel: null,
// promptPrefix: null,
// temperature: 1,
// top_p: 1,
// presence_penalty: 0,
// frequency_penalty: 0,
// // for bingAI only
// jailbreak: false,
// jailbreakConversationId: null,
// conversationSignature: null,
// clientId: null,
// invocationId: 1,
// toneStyle: null,
// };
// an array of saved presets.
// sample structure
// [preset1, preset2, preset3]
const presets = atom({
key: 'presets',
default: []
});
export default {
presets
};