convo change also changes model selection

This commit is contained in:
Daniel Avila 2023-03-04 21:10:45 -05:00
parent d64f914552
commit fc899da944
4 changed files with 23 additions and 10 deletions

View file

@ -1,9 +1,9 @@
import React, { useState, useRef } from 'react';
import RenameButton from './RenameButton';
import DeleteButton from './DeleteButton';
import { useDispatch } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { setConversation } from '~/store/convoSlice';
import { setCustomGpt, setModel } from '~/store/submitSlice';
import { setCustomGpt, setModel, setCustomModel } from '~/store/submitSlice';
import { setMessages } from '~/store/messageSlice';
import { setText } from '~/store/textSlice';
import manualSWR from '~/utils/fetchers';
@ -20,6 +20,7 @@ export default function Conversation({
}) {
const [renaming, setRenaming] = useState(false);
const [titleInput, setTitleInput] = useState(title);
const { modelMap } = useSelector((state) => state.models);
const inputRef = useRef(null);
const dispatch = useDispatch();
const { trigger } = manualSWR(`http://localhost:3050/messages/${id}`, 'get');
@ -62,6 +63,13 @@ export default function Conversation({
dispatch(setModel(data[1].sender));
}
if (modelMap[data[1].sender.toLowerCase()]) {
console.log('sender', data[1].sender);
dispatch(setCustomModel(data[1].sender.toLowerCase()));
} else {
dispatch(setCustomModel(null));
}
dispatch(setMessages(data));
dispatch(setCustomGpt(convo));
dispatch(setText(''));

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { setModel, setDisabled, setCustomGpt } from '~/store/submitSlice';
import { setModel, setDisabled, setCustomGpt, setCustomModel } from '~/store/submitSlice';
import { setConversation } from '~/store/convoSlice';
import ModelDialog from './ModelDialog';
import MenuItems from './MenuItems';
@ -23,8 +23,7 @@ import { Dialog } from '../ui/Dialog.tsx';
export default function ModelMenu() {
const dispatch = useDispatch();
const { model } = useSelector((state) => state.submit);
const [customModel, setCustomModel] = useState(false);
const { model, customModel } = useSelector((state) => state.submit);
const { models, modelMap, initial } = useSelector((state) => state.models);
const { trigger } = manualSWR('http://localhost:3050/customGpts', 'get', (res) => {
console.log('models data (response)', res);
@ -69,13 +68,15 @@ export default function ModelMenu() {
} else if (initial[value]) {
dispatch(setModel(value));
dispatch(setDisabled(false));
setCustomModel(false);
setCustomModel(null);
} else if (!initial[value]) {
const chatGptLabel = modelMap[value]?.chatGptLabel;
const promptPrefix = modelMap[value]?.promptPrefix;
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
dispatch(setModel('chatgptCustom'));
setCustomModel(value);
} else if (!modelMap[value]) {
setCustomModel(null);
}
// Set new conversation
@ -84,7 +85,7 @@ export default function ModelMenu() {
title: 'New Chat',
error: false,
conversationId: null,
parentMessageId: null,
parentMessageId: null
})
);
};

View file

@ -32,7 +32,6 @@ const currentSlice = createSlice({
initialState,
reducers: {
setModels: (state, action) => {
console.log('setModels', action.payload);
const models = [...initialState.models, ...action.payload];
state.models = models;
const modelMap = {};

View file

@ -6,6 +6,7 @@ const initialState = {
model: 'chatgpt',
promptPrefix: '',
chatGptLabel: '',
customModel: null
};
const currentSlice = createSlice({
@ -25,9 +26,13 @@ const currentSlice = createSlice({
state.promptPrefix = action.payload.promptPrefix;
state.chatGptLabel = action.payload.chatGptLabel;
},
setCustomModel: (state, action) => {
state.customModel = action.payload;
}
}
});
export const { setSubmitState, setDisabled, setModel, setCustomGpt } = currentSlice.actions;
export const { setSubmitState, setDisabled, setModel, setCustomGpt, setCustomModel } =
currentSlice.actions;
export default currentSlice.reducer;