Skip to content

Commit

Permalink
chore: use last conversation temperature (mckaywrigley#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotneet authored Apr 18, 2023
1 parent ba1dacb commit 03afa00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions components/Chat/Temperature.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions pages/api/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const Home = ({
tokenLimit: OpenAIModels[defaultModelId].tokenLimit,
},
prompt: DEFAULT_SYSTEM_PROMPT,
temperature: DEFAULT_TEMPERATURE,
temperature: lastConversation?.temperature ?? DEFAULT_TEMPERATURE,
folderId: null,
};

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

0 comments on commit 03afa00

Please sign in to comment.