enterEdit()}
/>
diff --git a/client/src/components/Messages/MessageBar.jsx b/client/src/components/Messages/MessageBar.jsx
deleted file mode 100644
index 76611e52a3..0000000000
--- a/client/src/components/Messages/MessageBar.jsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import React, { useRef, useEffect, useState } from 'react';
-
-const MessageBar = ({ children, dynamicProps, handleWheel, clickSearchResult }) => {
- const ref = useRef(null);
- const [isVisible, setIsVisible] = useState(false);
-
- useEffect(() => {
- const observer = new IntersectionObserver(
- ([entry]) => {
- if (entry.isIntersecting) {
- setIsVisible(true);
- observer.unobserve(ref.current);
- }
- },
- { threshold: 0.1 }
- );
-
- observer.observe(ref.current);
-
- return () => {
- observer.unobserve(ref.current);
- };
- }, []);
-
- return (
-
- {isVisible ? children : null}
-
- );
-};
-
-export default MessageBar;
diff --git a/client/src/components/Messages/index.jsx b/client/src/components/Messages/index.jsx
index b112fff57e..e74ff8ba71 100644
--- a/client/src/components/Messages/index.jsx
+++ b/client/src/components/Messages/index.jsx
@@ -20,10 +20,10 @@ export default function Messages({ isSearchView = false }) {
const _messagesTree = isSearchView ? searchResultMessagesTree : messagesTree;
const conversation = useRecoilValue(store.conversation) || {};
- const { conversationId, model, chatGptLabel, toneStyle } = conversation;
+ const { conversationId, endpoint } = conversation;
- const models = useRecoilValue(store.models) || [];
- const modelName = models.find(element => element.model == model)?.name;
+ // const models = useRecoilValue(store.models) || [];
+ // const modelName = models.find(element => element.model == model)?.name;
const searchQuery = useRecoilValue(store.searchQuery);
@@ -82,9 +82,22 @@ export default function Messages({ isSearchView = false }) {
const getConversationTitle = () => {
if (isSearchView) return `Search: ${searchQuery}`;
else {
- let _title = `Model: ${modelName}`;
- if (chatGptLabel) _title += ` of ${chatGptLabel}`;
- if (toneStyle) _title += ` (${toneStyle})`;
+ let _title = `${endpoint}`;
+
+ if (endpoint === 'azureOpenAI' || endpoint === 'openAI') {
+ const { chatGptLabel, model } = conversation;
+ if (model) _title += `: ${model}`;
+ if (chatGptLabel) _title += ` as ${chatGptLabel}`;
+ } else if (endpoint === 'bingAI') {
+ const { jailbreak, toneStyle } = conversation;
+ if (toneStyle) _title += `: ${toneStyle}`;
+ if (jailbreak) _title += ` as Sydney`;
+ } else if (endpoint === 'chatGPTBrowser') {
+ const { model } = conversation;
+ if (model) _title += `: ${model}`;
+ } else if (endpoint === null) {
+ null;
+ }
return _title;
}
};
diff --git a/client/src/store/conversation.js b/client/src/store/conversation.js
index b59aef4af5..c06e6834f0 100644
--- a/client/src/store/conversation.js
+++ b/client/src/store/conversation.js
@@ -1,23 +1,34 @@
-import models from './models';
+import endpoints from './endpoints';
import { atom, selector, useSetRecoilState, useResetRecoilState, useRecoilCallback } from 'recoil';
import buildTree from '~/utils/buildTree';
+import getDefaultConversation from '~/utils/getDefaultConversation';
// current conversation, can be null (need to be fetched from server)
// sample structure
// {
-// conversationId: "new",
-// title: "New Chat",
+// conversationId: '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: 0.8,
+// top_p: 1,
+// presence_penalty: 1,
+// // for bingAI only
+// jailbreak: false,
// jailbreakConversationId: null,
// conversationSignature: null,
// clientId: null,
// invocationId: null,
-// model: "chatgpt",
-// chatGptLabel: null,
-// promptPrefix: null,
-// user: null,
-// suggestions: [],
// toneStyle: null,
-// }
+// suggestions: []
+// };
+
const conversation = atom({
key: 'conversation',
default: null
@@ -52,8 +63,8 @@ const useConversation = () => {
({ snapshot }) =>
async (_conversation, messages = null) => {
const prevConversation = await snapshot.getPromise(conversation);
- const prevModelsFilter = await snapshot.getPromise(models.modelsFilter);
- _switchToConversation(_conversation, messages, { prevModelsFilter, prevConversation });
+ const availableEndpoints = await snapshot.getPromise(endpoints.availableEndpoints);
+ _switchToConversation(_conversation, messages, { availableEndpoints, prevConversation });
},
[]
);
@@ -61,71 +72,25 @@ const useConversation = () => {
const _switchToConversation = (
conversation,
messages = null,
- { prevModelsFilter = {}, prev_conversation = {} }
+ { availableEndpoints = [], prevConversation = {} }
) => {
- let { model = null, chatGptLabel = null, promptPrefix = null } = conversation;
- const getDefaultModel = () => {
- try {
- // try to use current model
- const { _model = null, _chatGptLabel = null, _promptPrefix = null } = prev_conversation || {};
- if (prevModelsFilter[_model]) {
- model = _model;
- chatGptLabel = _chatGptLabel;
- promptPrefix = _promptPrefix;
- return;
- }
- } catch (error) {}
+ let { endpoint = null } = conversation;
- try {
- // try to read latest selected model from local storage
- const lastSelected = JSON.parse(localStorage.getItem('model'));
- const { model: _model, chatGptLabel: _chatGptLabel, promptPrefix: _promptPrefix } = lastSelected;
-
- if (prevModelsFilter[_model]) {
- model = _model;
- chatGptLabel = _chatGptLabel;
- promptPrefix = _promptPrefix;
- return;
- }
- } catch (error) {}
-
- // if anything happens, reset to default model
- if (prevModelsFilter?.chatgpt) model = 'chatgpt';
- else if (prevModelsFilter?.bingai) model = 'bingai';
- else if (prevModelsFilter?.chatgptBrowser) model = 'chatgptBrowser';
- chatGptLabel = null;
- promptPrefix = null;
- };
-
- if (model === null)
+ if (endpoint === null)
// get the default model
- getDefaultModel();
+ conversation = getDefaultConversation({ conversation, availableEndpoints, prevConversation });
- setConversation({
- ...conversation,
- model: model,
- chatGptLabel: chatGptLabel,
- promptPrefix: promptPrefix
- });
+ setConversation(conversation);
setMessages(messages);
resetLatestMessage();
};
- const newConversation = ({ model = null, chatGptLabel = null, promptPrefix = null } = {}) => {
+ const newConversation = (template = {}) => {
switchToConversation(
{
conversationId: 'new',
title: 'New Chat',
- jailbreakConversationId: null,
- conversationSignature: null,
- clientId: null,
- invocationId: null,
- model: model,
- chatGptLabel: chatGptLabel,
- promptPrefix: promptPrefix,
- user: null,
- suggestions: [],
- toneStyle: null
+ ...template
},
[]
);
@@ -135,17 +100,7 @@ const useConversation = () => {
switchToConversation(
{
conversationId: 'search',
- title: 'Search',
- jailbreakConversationId: null,
- conversationSignature: null,
- clientId: null,
- invocationId: null,
- model: null,
- chatGptLabel: null,
- promptPrefix: null,
- user: null,
- suggestions: [],
- toneStyle: null
+ title: 'Search'
},
[]
);
diff --git a/client/src/store/endpoints.js b/client/src/store/endpoints.js
new file mode 100644
index 0000000000..e4f10ce195
--- /dev/null
+++ b/client/src/store/endpoints.js
@@ -0,0 +1,26 @@
+import { atom, selector } from 'recoil';
+
+const endpointsFilter = atom({
+ key: 'endpointsFilter',
+ default: {
+ azureOpenAI: false,
+ openAI: false,
+ bingAI: false,
+ chatGPTBrowser: false
+ }
+});
+
+const availableEndpoints = selector({
+ key: 'availableEndpoints',
+ get: ({ get }) => {
+ const endpoints = ['azureOpenAI', 'openAI', 'bingAI', 'chatGPTBrowser'];
+ const f = get(endpointsFilter);
+ return endpoints.filter(endpoint => f[endpoint]);
+ }
+});
+// const modelAvailable
+
+export default {
+ endpointsFilter,
+ availableEndpoints
+};
diff --git a/client/src/utils/getDefaultConversation.js b/client/src/utils/getDefaultConversation.js
new file mode 100644
index 0000000000..3fb35d4ad0
--- /dev/null
+++ b/client/src/utils/getDefaultConversation.js
@@ -0,0 +1,77 @@
+const buildDefaultConversation = ({ conversation, endpoint, lastConversationSetup = {} }) => {
+ if (endpoint === 'azureOpenAI' || endpoint === 'openAI') {
+ conversation = {
+ ...conversation,
+ endpoint,
+ model: lastConversationSetup?.model || 'gpt-3.5-turbo',
+ chatGptLabel: lastConversationSetup?.chatGptLabel || null,
+ promptPrefix: lastConversationSetup?.promptPrefix || null,
+ temperature: lastConversationSetup?.temperature || 0.8,
+ top_p: lastConversationSetup?.top_p || 1,
+ presence_penalty: lastConversationSetup?.presence_penalty || 1
+ };
+ } else if (endpoint === 'bingAI') {
+ conversation = {
+ ...conversation,
+ endpoint,
+ jailbreak: lastConversationSetup?.jailbreak || false,
+ jailbreakConversationId: lastConversationSetup?.jailbreakConversationId || null,
+ conversationSignature: lastConversationSetup?.conversationSignature || null,
+ clientId: lastConversationSetup?.clientId || null,
+ invocationId: lastConversationSetup?.invocationId || null,
+ toneStyle: lastConversationSetup?.toneStyle || null,
+ suggestions: lastConversationSetup?.suggestions || []
+ };
+ } else if (endpoint === 'chatGPTBrowser') {
+ conversation = {
+ ...conversation,
+ endpoint,
+ model: lastConversationSetup?.model || 'text-davinci-002-render-sha'
+ };
+ } else if (endpoint === null) {
+ conversation = {
+ ...conversation,
+ endpoint
+ };
+ }
+
+ return conversation;
+};
+
+const getDefaultConversation = ({ conversation, prevConversation, availableEndpoints }) => {
+ try {
+ // try to use current model
+ const { endpoint = null } = prevConversation || {};
+ if (endpoint in availableEndpoints) {
+ conversation = buildDefaultConversation({
+ conversation,
+ endpoint,
+ lastConversationSetup: prevConversation
+ });
+ return conversation;
+ }
+ } catch (error) {}
+
+ try {
+ // try to read latest selected model from local storage
+ const lastConversationSetup = JSON.parse(localStorage.getItem('lastConversationSetup'));
+ const { endpoint = null } = lastConversationSetup;
+
+ if (endpoint in availableEndpoints) {
+ conversation = buildDefaultConversation({ conversation, endpoint, lastConversationSetup });
+ return conversation;
+ }
+ } catch (error) {}
+
+ // if anything happens, reset to default model
+ const endpoint = availableEndpoints?.[0];
+ if (endpoint) {
+ conversation = buildDefaultConversation({ conversation, endpoint });
+ return conversation;
+ } else {
+ conversation = buildDefaultConversation({ conversation, endpoint: null });
+ return conversation;
+ }
+};
+
+export default getDefaultConversation;
diff --git a/client/src/utils/index.js b/client/src/utils/index.js
index 4ff806ebaa..2e402e4735 100644
--- a/client/src/utils/index.js
+++ b/client/src/utils/index.js
@@ -38,7 +38,7 @@ export const languages = [
'pascal'
];
-export const getIconOfModel = ({
+export const getIconOfAi = ({
size = 30,
sender,
isCreatedByUser,