mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
prompt prefix and label state changes when customGpt selected
This commit is contained in:
parent
9c3a78f96b
commit
b4b0c123ba
3 changed files with 28 additions and 27 deletions
|
|
@ -43,18 +43,6 @@ module.exports = {
|
||||||
return { customGpt: 'Error getting customGpts' };
|
return { customGpt: 'Error getting customGpts' };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// updateCustomGpt: async ({ _id, ...update }) => {
|
|
||||||
// try {
|
|
||||||
// console.log('updateCustomGpt', _id, update);
|
|
||||||
// return await CustomGpt.findOneAndUpdate({ _id }, update, {
|
|
||||||
// new: true,
|
|
||||||
// upsert: true
|
|
||||||
// }).exec();
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// return { message: 'Error updating customGpt' };
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
updateCustomGpt: async ({ value, ...update }) => {
|
updateCustomGpt: async ({ value, ...update }) => {
|
||||||
try {
|
try {
|
||||||
console.log('updateCustomGpt', value, update);
|
console.log('updateCustomGpt', value, update);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import React, { useState, useRef } from 'react';
|
import React, { useState, useRef } from 'react';
|
||||||
import TextareaAutosize from 'react-textarea-autosize';
|
import TextareaAutosize from 'react-textarea-autosize';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { setModel, setDisabled, setCustomGpt } from '~/store/submitSlice';
|
import { setModel, setCustomGpt } from '~/store/submitSlice';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import { Button } from '../ui/Button.tsx';
|
import { Button } from '../ui/Button.tsx';
|
||||||
import { Input } from '../ui/Input.tsx';
|
import { Input } from '../ui/Input.tsx';
|
||||||
|
|
@ -35,7 +35,7 @@ export default function ModelDialog({ mutate }) {
|
||||||
}
|
}
|
||||||
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
||||||
dispatch(setModel('chatgptCustom'));
|
dispatch(setModel('chatgptCustom'));
|
||||||
dispatch(setDisabled(false));
|
// dispatch(setDisabled(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveHandler = (e) => {
|
const saveHandler = (e) => {
|
||||||
|
|
@ -56,8 +56,8 @@ export default function ModelDialog({ mutate }) {
|
||||||
setSaveText('Save');
|
setSaveText('Save');
|
||||||
}, 2500);
|
}, 2500);
|
||||||
|
|
||||||
// dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
||||||
// dispatch(setModel('chatgptCustom'));
|
dispatch(setModel('chatgptCustom'));
|
||||||
// dispatch(setDisabled(false));
|
// dispatch(setDisabled(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { setModel, setDisabled } from '~/store/submitSlice';
|
import { setModel, setDisabled, setCustomGpt } from '~/store/submitSlice';
|
||||||
import { setConversation } from '~/store/convoSlice';
|
import { setConversation } from '~/store/convoSlice';
|
||||||
import ModelDialog from './ModelDialog';
|
import ModelDialog from './ModelDialog';
|
||||||
import MenuItems from './MenuItems';
|
import MenuItems from './MenuItems';
|
||||||
// import useDidMountEffect from '~/hooks/useDidMountEffect';
|
|
||||||
// import { swr } from '~/utils/fetchers';
|
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
// import { setMessages } from '~/store/messageSlice';
|
|
||||||
import { setModels } from '~/store/modelSlice';
|
import { setModels } from '~/store/modelSlice';
|
||||||
// import ModelItem from './ModelItem';
|
|
||||||
import GPTIcon from '../svg/GPTIcon';
|
import GPTIcon from '../svg/GPTIcon';
|
||||||
import BingIcon from '../svg/BingIcon';
|
import BingIcon from '../svg/BingIcon';
|
||||||
import { Button } from '../ui/Button.tsx';
|
import { Button } from '../ui/Button.tsx';
|
||||||
|
|
||||||
|
const initial = new Set(['chatgpt', 'chatgptCustom', 'bingai', 'chatgptBrowser']);
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
|
@ -29,6 +27,14 @@ export default function ModelMenu() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { model } = useSelector((state) => state.submit);
|
const { model } = useSelector((state) => state.submit);
|
||||||
const { models } = useSelector((state) => state.models);
|
const { models } = useSelector((state) => state.models);
|
||||||
|
const modelMap = new Map(
|
||||||
|
models
|
||||||
|
.slice(4)
|
||||||
|
.map((modelItem) => [
|
||||||
|
modelItem.value,
|
||||||
|
{ chatGptLabel: modelItem.chatGptLabel, promptPrefix: modelItem.promptPrefix }
|
||||||
|
])
|
||||||
|
);
|
||||||
const { trigger } = manualSWR('http://localhost:3050/customGpts', 'get', (res) => {
|
const { trigger } = manualSWR('http://localhost:3050/customGpts', 'get', (res) => {
|
||||||
console.log('models data (response)', res);
|
console.log('models data (response)', res);
|
||||||
if (models.length + res.length === models.length) {
|
if (models.length + res.length === models.length) {
|
||||||
|
|
@ -43,12 +49,10 @@ export default function ModelMenu() {
|
||||||
dispatch(setModels(fetchedModels));
|
dispatch(setModels(fetchedModels));
|
||||||
});
|
});
|
||||||
|
|
||||||
// useDidMountEffect(() => mutate(), [chatGptLabel]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const lastSelectedModel = JSON.parse(localStorage.getItem('model'));
|
const lastSelected = JSON.parse(localStorage.getItem('model'));
|
||||||
if (lastSelectedModel && lastSelectedModel !== 'chatgptCustom') {
|
if (lastSelected && lastSelected !== 'chatgptCustom' && initial.has(lastSelected)) {
|
||||||
dispatch(setModel(lastSelectedModel));
|
dispatch(setModel(lastSelected));
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedModels = JSON.parse(localStorage.getItem('models'));
|
const cachedModels = JSON.parse(localStorage.getItem('models'));
|
||||||
|
|
@ -75,13 +79,22 @@ export default function ModelMenu() {
|
||||||
dispatch(setModel(value));
|
dispatch(setModel(value));
|
||||||
dispatch(setDisabled(false));
|
dispatch(setDisabled(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!initial.has(value)) {
|
||||||
|
const chatGptLabel = modelMap.get(value)?.chatGptLabel;
|
||||||
|
const promptPrefix = modelMap.get(value)?.promptPrefix;
|
||||||
|
|
||||||
|
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
||||||
|
dispatch(setModel('chatgptCustom'));
|
||||||
|
}
|
||||||
|
|
||||||
// Set new conversation
|
// Set new conversation
|
||||||
dispatch(
|
dispatch(
|
||||||
setConversation({
|
setConversation({
|
||||||
title: 'New Chat',
|
title: 'New Chat',
|
||||||
error: false,
|
error: false,
|
||||||
conversationId: null,
|
conversationId: null,
|
||||||
parentMessageId: null
|
parentMessageId: null,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue