diff --git a/api/server/index.js b/api/server/index.js
index 102811b60e..2351e8a888 100644
--- a/api/server/index.js
+++ b/api/server/index.js
@@ -51,6 +51,14 @@ app.use('/api/prompts', routes.authenticatedOr401, routes.prompts);
app.use('/auth', routes.auth);
+app.get('/api/models', function (req, res) {
+ const hasOpenAI = !!process.env.OPENAI_KEY;
+ const hasChatGpt = !!process.env.CHATGPT_TOKEN;
+ const hasBing = !!process.env.BING_TOKEN;
+
+ res.send(JSON.stringify({ hasOpenAI, hasChatGpt, hasBing }));
+});
+
app.listen(port, host, () => {
if (host=='0.0.0.0')
console.log(`Server listening on all interface at port ${port}. Use http://localhost:${port} to access it`);
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 0421d14d93..78943710e5 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -7,7 +7,7 @@ import MobileNav from './components/Nav/MobileNav';
import useDocumentTitle from '~/hooks/useDocumentTitle';
import { useSelector, useDispatch } from 'react-redux';
import { setUser } from './store/userReducer';
-import axios from 'axios'
+import axios from 'axios';
const App = () => {
const dispatch = useDispatch();
diff --git a/client/src/components/Models/ModelItem.jsx b/client/src/components/Models/ModelItem.jsx
index bf945162af..2747e1ccca 100644
--- a/client/src/components/Models/ModelItem.jsx
+++ b/client/src/components/Models/ModelItem.jsx
@@ -43,9 +43,9 @@ export default function ModelItem({ modelName, value, model, onSelect, id, chatG
);
- }
+ }
- if (initial[value]) {
+ if (initial[value])
return (
$}
);
- }
+
const handleMouseOver = () => {
setIsHovering(true);
};
diff --git a/client/src/components/Models/ModelMenu.jsx b/client/src/components/Models/ModelMenu.jsx
index d76d8d8030..0202dfb48c 100644
--- a/client/src/components/Models/ModelMenu.jsx
+++ b/client/src/components/Models/ModelMenu.jsx
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react';
+import axios from 'axios';
import { useSelector, useDispatch } from 'react-redux';
import {
setSubmission,
@@ -11,7 +12,7 @@ import { setNewConvo } from '~/store/convoSlice';
import ModelDialog from './ModelDialog';
import MenuItems from './MenuItems';
import { swr } from '~/utils/fetchers';
-import { setModels } from '~/store/modelSlice';
+import { setModels, setInitial } from '~/store/modelSlice';
import { setMessages } from '~/store/messageSlice';
import { setText } from '~/store/textSlice';
import GPTIcon from '../svg/GPTIcon';
@@ -62,10 +63,47 @@ export default function ModelMenu() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ useEffect(() => {
+ axios.get('/api/models', {
+ timeout: 1000,
+ withCredentials: true
+ }).then((res) => {
+ return res.data
+ }).then((data) => {
+ const initial = {chatgpt: data?.hasOpenAI, chatgptCustom: data?.hasOpenAI, bingai: data?.hasBing, sydney: data?.hasBing, chatgptBrowser: data?.hasChatGpt}
+ dispatch(setInitial(initial))
+ // TODO, auto reset default model
+ if (data?.hasOpenAI) {
+ dispatch(setModel('chatgpt'));
+ dispatch(setDisabled(false));
+ dispatch(setCustomModel(null));
+ dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
+ } else if (data?.hasBing) {
+ dispatch(setModel('bingai'));
+ dispatch(setDisabled(false));
+ dispatch(setCustomModel(null));
+ dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
+ } else if (data?.hasChatGpt) {
+ dispatch(setModel('chatgptBrowser'));
+ dispatch(setDisabled(false));
+ dispatch(setCustomModel(null));
+ dispatch(setCustomGpt({ chatGptLabel: null, promptPrefix: null }));
+ } else {
+ dispatch(setDisabled(true));
+ }
+ }).catch((error) => {
+ console.error(error)
+ console.log('Not login!')
+ window.location.href = "/auth/login";
+ })
+ }, [])
+
useEffect(() => {
localStorage.setItem('model', JSON.stringify(model));
}, [model]);
+ const filteredModels = models.filter(({model}) => initial[model])
+
const onChange = (value) => {
if (!value) {
return;
@@ -166,10 +204,12 @@ export default function ModelMenu() {
onValueChange={onChange}
className="overflow-y-auto"
>
-
+ {filteredModels.length?
+ :No model available.
+ }
diff --git a/client/src/store/modelSlice.js b/client/src/store/modelSlice.js
index 7caefdc548..1db760de5d 100644
--- a/client/src/store/modelSlice.js
+++ b/client/src/store/modelSlice.js
@@ -34,7 +34,7 @@ const initialState = {
},
],
modelMap: {},
- initial: { chatgpt: true, chatgptCustom: true, bingai: true, sydney: true, chatgptBrowser: true }
+ initial: { chatgpt: false, chatgptCustom: false, bingai: false, sydney: false, chatgptBrowser: false }
// initial: { chatgpt: true, chatgptCustom: true, bingai: true, }
};
@@ -56,10 +56,13 @@ const currentSlice = createSlice({
});
state.modelMap = modelMap;
+ },
+ setInitial: (state, action) => {
+ state.initial = action.payload;
}
}
});
-export const { setModels } = currentSlice.actions;
+export const { setModels, setInitial } = currentSlice.actions;
export default currentSlice.reducer;
diff --git a/client/src/store/submitSlice.js b/client/src/store/submitSlice.js
index a965c29335..ed6f5771ad 100644
--- a/client/src/store/submitSlice.js
+++ b/client/src/store/submitSlice.js
@@ -4,7 +4,7 @@ const initialState = {
isSubmitting: false,
submission: {},
stopStream: false,
- disabled: false,
+ disabled: true,
model: 'chatgpt',
promptPrefix: null,
chatGptLabel: null,