Skip to content

Commit 4332187

Browse files
committed
Fix for error where users still have gpt-3.5-turbo saved in their local storage. Now localstorage is checked agasint list of validModles
1 parent 9887168 commit 4332187

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/client/components/Chat/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ function usePersistedState<T>(key: string, defaultValue: T): [T, SetState<T>] {
5555
return [state, setState]
5656
}
5757

58+
const allowedModels = validModels.map((m) => m.name) // [gpt-4, gpt-4o, gpt-4o-mini] 22.8.2024
59+
console.log('allowedModels:', allowedModels)
60+
const getInitialModel = () => {
61+
const storedModel = localStorage.getItem('model')
62+
return allowedModels.includes(storedModel) ? storedModel : 'gpt-4o'
63+
}
64+
5865
const Chat = () => {
5966
// Null when in general chat
6067
const { courseId } = useParams()
@@ -66,6 +73,8 @@ const Chat = () => {
6673
refetch: refetchStatus,
6774
} = useUserStatus(courseId)
6875

76+
const [model, setModel] = useState(getInitialModel())
77+
6978
const { infoTexts, isLoading: infoTextsLoading } = useInfoTexts()
7079

7180
const [activePromptId, setActivePromptId] = useState('')
@@ -78,7 +87,6 @@ const Chat = () => {
7887
const inputFileRef = useRef<HTMLInputElement>(null)
7988
const [fileName, setFileName] = useState<string>('')
8089
const [completion, setCompletion] = useState('')
81-
const [model, setModel] = useState(localStorage.getItem('model') ?? 'gpt-4o')
8290
const [streamController, setStreamController] = useState<AbortController>()
8391
const [alertOpen, setAlertOpen] = useState(false)
8492
const [disallowedFileType, setDisallowedFileType] = useState('')

0 commit comments

Comments
 (0)