+
+ {' '}
{showLabel && (
)}
- {/* {!showLabel && (
+ {/* {!showLabel && (
)} */}
-
- {!showLabel && (
- Model:
-
- )}
+ {!showLabel && Model:}
{`${!showLabel ? '' : ''} ${model}`}
{/* {`${!showLabel ? 'Model: ' : ''} ${model}`} */}
@@ -69,6 +75,7 @@ function ModelDropDown({ model, setModel, endpoint, showAbove = false, showLabel
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
+ style={showAbove ? { transform: 'scaleY(-1)' } : {}}
>
@@ -80,7 +87,7 @@ function ModelDropDown({ model, setModel, endpoint, showAbove = false, showLabel
leave="transition ease-in duration-100"
leaveFrom="opacity-100"
leaveTo="opacity-0"
- className={showAbove ? 'bottom-full mb-1' : 'top-full mt-1'}
+ className={showAbove ? 'bottom-full mb-3' : 'top-full mt-3'}
>
{models.map((modelOption, i) => (
@@ -110,6 +117,68 @@ function ModelDropDown({ model, setModel, endpoint, showAbove = false, showLabel
>
)}
+
+ {/*
+
+
+ Model
+
+
+
+ {model}
+
+
+
+
+
+
+
+ {models.map((modelOption, i) => (
+
+
+
+ {modelOption}
+
+ {modelOption === model && (
+
+
+
+ )}
+
+
+ ))}
+ */}
diff --git a/client/src/components/Input/OpenAIOptions/ModelSelect.jsx b/client/src/components/ui/ModelSelect.jsx
similarity index 94%
rename from client/src/components/Input/OpenAIOptions/ModelSelect.jsx
rename to client/src/components/ui/ModelSelect.jsx
index 6ae9520f04..c8647fbaff 100644
--- a/client/src/components/Input/OpenAIOptions/ModelSelect.jsx
+++ b/client/src/components/ui/ModelSelect.jsx
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
-import { Button } from '../../ui/Button.tsx';
+import { Button } from './Button.tsx';
import {
DropdownMenu,
DropdownMenuContent,
@@ -8,7 +8,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
DropdownMenuRadioItem
-} from '../../ui/DropdownMenu.tsx';
+} from './DropdownMenu.tsx';
const ModelSelect = ({ model, onChange, availableModels, ...props }) => {
const [menuOpen, setMenuOpen] = useState(false);
diff --git a/client/src/components/Prompts/Prompt.jsx b/client/src/components/ui/Prompt.jsx
similarity index 100%
rename from client/src/components/Prompts/Prompt.jsx
rename to client/src/components/ui/Prompt.jsx
diff --git a/client/src/components/Prompts/Templates.jsx b/client/src/components/ui/Templates.jsx
similarity index 100%
rename from client/src/components/Prompts/Templates.jsx
rename to client/src/components/ui/Templates.jsx
diff --git a/client/src/store/conversation.js b/client/src/store/conversation.js
index 6088c9957d..0e312a633d 100644
--- a/client/src/store/conversation.js
+++ b/client/src/store/conversation.js
@@ -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
);
};
diff --git a/client/src/store/index.js b/client/src/store/index.js
index e7c625b92c..f400853ac6 100644
--- a/client/src/store/index.js
+++ b/client/src/store/index.js
@@ -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
};
diff --git a/client/src/store/preset.js b/client/src/store/preset.js
new file mode 100644
index 0000000000..f2f342684e
--- /dev/null
+++ b/client/src/store/preset.js
@@ -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
+};
diff --git a/client/src/utils/buildPresetByConversation.js b/client/src/utils/buildPresetByConversation.js
new file mode 100644
index 0000000000..73799f08c1
--- /dev/null
+++ b/client/src/utils/buildPresetByConversation.js
@@ -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;
diff --git a/client/src/utils/fetchers.js b/client/src/utils/fetchers.js
index 24c430dbd1..175967f37a 100644
--- a/client/src/utils/fetchers.js
+++ b/client/src/utils/fetchers.js
@@ -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) => {
diff --git a/client/src/utils/getDefaultConversation.js b/client/src/utils/getDefaultConversation.js
index e736d5aefd..397f122ab4 100644
--- a/client/src/utils/getDefaultConversation.js
+++ b/client/src/utils/getDefaultConversation.js
@@ -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 {