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
2 changed files with 13 additions and 4 deletions
+10 -2
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);