@@ -55,6 +55,13 @@ function usePersistedState<T>(key: string, defaultValue: T): [T, SetState<T>] {
55
55
return [ state , setState ]
56
56
}
57
57
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
+
58
65
const Chat = ( ) => {
59
66
// Null when in general chat
60
67
const { courseId } = useParams ( )
@@ -66,6 +73,8 @@ const Chat = () => {
66
73
refetch : refetchStatus ,
67
74
} = useUserStatus ( courseId )
68
75
76
+ const [ model , setModel ] = useState ( getInitialModel ( ) )
77
+
69
78
const { infoTexts, isLoading : infoTextsLoading } = useInfoTexts ( )
70
79
71
80
const [ activePromptId , setActivePromptId ] = useState ( '' )
@@ -78,7 +87,6 @@ const Chat = () => {
78
87
const inputFileRef = useRef < HTMLInputElement > ( null )
79
88
const [ fileName , setFileName ] = useState < string > ( '' )
80
89
const [ completion , setCompletion ] = useState ( '' )
81
- const [ model , setModel ] = useState ( localStorage . getItem ( 'model' ) ?? 'gpt-4o' )
82
90
const [ streamController , setStreamController ] = useState < AbortController > ( )
83
91
const [ alertOpen , setAlertOpen ] = useState ( false )
84
92
const [ disallowedFileType , setDisallowedFileType ] = useState ( '' )
0 commit comments