mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
feat: show model based on configured Keys
This commit is contained in:
parent
41f351786f
commit
131af50034
5 changed files with 38 additions and 7 deletions
|
|
@ -28,6 +28,14 @@ app.use('/api/convos', routes.convos);
|
||||||
app.use('/api/customGpts', routes.customGpts);
|
app.use('/api/customGpts', routes.customGpts);
|
||||||
app.use('/api/prompts', routes.prompts);
|
app.use('/api/prompts', routes.prompts);
|
||||||
|
|
||||||
|
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, () => {
|
app.listen(port, host, () => {
|
||||||
if (host=='0.0.0.0')
|
if (host=='0.0.0.0')
|
||||||
console.log(`Server listening on all interface at port ${port}. Use http://localhost:${port} to access it`);
|
console.log(`Server listening on all interface at port ${port}. Use http://localhost:${port} to access it`);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import TextChat from './components/Main/TextChat';
|
||||||
import Nav from './components/Nav';
|
import Nav from './components/Nav';
|
||||||
import MobileNav from './components/Nav/MobileNav';
|
import MobileNav from './components/Nav/MobileNav';
|
||||||
import useDocumentTitle from '~/hooks/useDocumentTitle';
|
import useDocumentTitle from '~/hooks/useDocumentTitle';
|
||||||
import { useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const { messages, messageTree } = useSelector((state) => state.messages);
|
const { messages, messageTree } = useSelector((state) => state.messages);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ export default function ModelItem({ modelName, value, model, onSelect, id, chatG
|
||||||
|
|
||||||
const icon = getIconOfModel({ size: 16, sender: modelName, isCreatedByUser: false, model, chatGptLabel, promptPrefix, error: false, className: "mr-2" });
|
const icon = getIconOfModel({ size: 16, sender: modelName, isCreatedByUser: false, model, chatGptLabel, promptPrefix, error: false, className: "mr-2" });
|
||||||
|
|
||||||
|
if (!initial[model]) return null
|
||||||
|
|
||||||
if (value === 'chatgptCustom') {
|
if (value === 'chatgptCustom') {
|
||||||
return (
|
return (
|
||||||
<DialogTrigger className="w-full">
|
<DialogTrigger className="w-full">
|
||||||
|
|
@ -45,7 +47,7 @@ export default function ModelItem({ modelName, value, model, onSelect, id, chatG
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initial[value]) {
|
if (initial[value])
|
||||||
return (
|
return (
|
||||||
<DropdownMenuRadioItem
|
<DropdownMenuRadioItem
|
||||||
value={value}
|
value={value}
|
||||||
|
|
@ -56,7 +58,7 @@ export default function ModelItem({ modelName, value, model, onSelect, id, chatG
|
||||||
{value === 'chatgpt' && <sup>$</sup>}
|
{value === 'chatgpt' && <sup>$</sup>}
|
||||||
</DropdownMenuRadioItem>
|
</DropdownMenuRadioItem>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const handleMouseOver = () => {
|
const handleMouseOver = () => {
|
||||||
setIsHovering(true);
|
setIsHovering(true);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
setSubmission,
|
setSubmission,
|
||||||
|
|
@ -11,7 +12,7 @@ import { setNewConvo } from '~/store/convoSlice';
|
||||||
import ModelDialog from './ModelDialog';
|
import ModelDialog from './ModelDialog';
|
||||||
import MenuItems from './MenuItems';
|
import MenuItems from './MenuItems';
|
||||||
import { swr } from '~/utils/fetchers';
|
import { swr } from '~/utils/fetchers';
|
||||||
import { setModels } from '~/store/modelSlice';
|
import { setModels, setInitial } from '~/store/modelSlice';
|
||||||
import { setMessages } from '~/store/messageSlice';
|
import { setMessages } from '~/store/messageSlice';
|
||||||
import { setText } from '~/store/textSlice';
|
import { setText } from '~/store/textSlice';
|
||||||
import GPTIcon from '../svg/GPTIcon';
|
import GPTIcon from '../svg/GPTIcon';
|
||||||
|
|
@ -61,6 +62,23 @@ export default function ModelMenu() {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// 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
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
console.log('Not login!')
|
||||||
|
window.location.href = "/auth/login";
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem('model', JSON.stringify(model));
|
localStorage.setItem('model', JSON.stringify(model));
|
||||||
}, [model]);
|
}, [model]);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ const initialState = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
modelMap: {},
|
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, }
|
// initial: { chatgpt: true, chatgptCustom: true, bingai: true, }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -56,10 +56,13 @@ const currentSlice = createSlice({
|
||||||
});
|
});
|
||||||
|
|
||||||
state.modelMap = modelMap;
|
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;
|
export default currentSlice.reducer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue