chore: use last conversation temperature (#568)

This commit is contained in:
Shinji Yamada 2023-04-18 23:24:47 +09:00 committed by GitHub
parent ba1dacb899
commit 03afa00732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import { FC, useState } from 'react';
import { FC, useContext, useState } from 'react';
import { useTranslation } from 'next-i18next';
import { DEFAULT_TEMPERATURE } from '@/utils/app/const';
import HomeContext from '@/pages/api/home/home.context';
interface Props {
label: string;
onChangeTemperature: (temperature: number) => void;
@ -13,7 +15,13 @@ export const TemperatureSlider: FC<Props> = ({
label,
onChangeTemperature,
}) => {
const [temperature, setTemperature] = useState(DEFAULT_TEMPERATURE);
const {
state: { conversations },
} = useContext(HomeContext);
const lastConversation = conversations[conversations.length - 1];
const [temperature, setTemperature] = useState(
lastConversation?.temperature ?? DEFAULT_TEMPERATURE,
);
const { t } = useTranslation('chat');
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue = parseFloat(event.target.value);

View File

@ -192,7 +192,7 @@ const Home = ({
tokenLimit: OpenAIModels[defaultModelId].tokenLimit,
},
prompt: DEFAULT_SYSTEM_PROMPT,
temperature: DEFAULT_TEMPERATURE,
temperature: lastConversation?.temperature ?? DEFAULT_TEMPERATURE,
folderId: null,
};
@ -326,6 +326,7 @@ const Home = ({
value: cleanedSelectedConversation,
});
} else {
const lastConversation = conversations[conversations.length - 1];
dispatch({
field: 'selectedConversation',
value: {
@ -334,7 +335,7 @@ const Home = ({
messages: [],
model: OpenAIModels[defaultModelId],
prompt: DEFAULT_SYSTEM_PROMPT,
temperature: DEFAULT_TEMPERATURE,
temperature: lastConversation?.temperature ?? DEFAULT_TEMPERATURE,
folderId: null,
},
});