@@ -65,6 +65,7 @@ export const Chat = () => {
65
65
const [ selectedChatGptModel , setSelectedChatGptModel ] =
66
66
React . useState < string > ( CHAT_GPT_MODELS [ 0 ] ) ;
67
67
const [ systemMessage , setSystemMessage ] = React . useState < string > ( "" ) ;
68
+ const [ missingApiKey , setMissingApiKey ] = React . useState < boolean > ( false ) ;
68
69
const [ error , setError ] = React . useState < Error > ( ) ;
69
70
70
71
React . useEffect ( ( ) => {
@@ -110,14 +111,23 @@ export const Chat = () => {
110
111
} ;
111
112
112
113
const handleUpdateChatGptModel = ( value : string ) => {
114
+ setMissingApiKey ( false ) ;
113
115
setSelectedChatGptModel ( value ) ;
114
116
} ;
115
117
116
118
const onSubmit = ( e : React . FormEvent ) => {
117
- setError ( undefined ) ;
118
- storage ?. setItem ( CHAT_OPENAI_API_KEY , currentApiKey ) ;
119
- scrollToBottom ( ) ;
120
- handleSubmit ( e as unknown as React . FormEvent < HTMLFormElement > ) ;
119
+ if (
120
+ currentApiKey . length === 0 &&
121
+ selectedChatGptModel != CHAT_GPT_MODELS [ 0 ]
122
+ ) {
123
+ setMissingApiKey ( true ) ;
124
+ } else {
125
+ setError ( undefined ) ;
126
+ setMissingApiKey ( false ) ;
127
+ storage ?. setItem ( CHAT_OPENAI_API_KEY , currentApiKey ) ;
128
+ scrollToBottom ( ) ;
129
+ handleSubmit ( e as unknown as React . FormEvent < HTMLFormElement > ) ;
130
+ }
121
131
} ;
122
132
123
133
const messagesWithoutSystem = messages . slice ( 1 ) ;
@@ -143,27 +153,39 @@ export const Chat = () => {
143
153
</ SelectGroup >
144
154
</ SelectContent >
145
155
</ Select >
146
- < Input
147
- value = { getMaskedKey ( currentApiKey ) }
148
- onKeyDown = { ( e ) => {
149
- if ( ! ( ( e . ctrlKey || e . metaKey ) && e . key === "v" ) ) {
150
- e . preventDefault ( ) ;
151
- }
152
- } }
153
- onFocus = { ( e ) => {
154
- e . currentTarget . select ( ) ;
155
- } }
156
- autoComplete = "off"
157
- className = "focus-within:border-white"
158
- placeholder = "Paste Your API Key"
159
- onChange = { handleUpdateApiKey }
160
- onDragStart = { ( e ) => e . preventDefault ( ) }
161
- onDragOver = { ( e ) => e . preventDefault ( ) }
162
- onMouseDown = { ( e ) => {
163
- e . preventDefault ( ) ;
164
- e . currentTarget . focus ( ) ;
165
- } }
166
- />
156
+ { selectedChatGptModel !== CHAT_GPT_MODELS [ 0 ] && (
157
+ < >
158
+ < Input
159
+ value = { getMaskedKey ( currentApiKey ) }
160
+ onKeyDown = { ( e ) => {
161
+ if ( ! ( ( e . ctrlKey || e . metaKey ) && e . key === "v" ) ) {
162
+ e . preventDefault ( ) ;
163
+ }
164
+ } }
165
+ onFocus = { ( e ) => {
166
+ e . currentTarget . select ( ) ;
167
+ } }
168
+ autoComplete = "off"
169
+ className = { cn (
170
+ "focus-within:border-white" ,
171
+ missingApiKey && "border-destructive" ,
172
+ ) }
173
+ placeholder = "Paste Your API Key"
174
+ onChange = { handleUpdateApiKey }
175
+ onDragStart = { ( e ) => e . preventDefault ( ) }
176
+ onDragOver = { ( e ) => e . preventDefault ( ) }
177
+ onMouseDown = { ( e ) => {
178
+ e . preventDefault ( ) ;
179
+ e . currentTarget . focus ( ) ;
180
+ } }
181
+ />
182
+ { missingApiKey && (
183
+ < label className = "w-full text-center mt-2 text-destructive" >
184
+ Please paste an API key
185
+ </ label >
186
+ ) }
187
+ </ >
188
+ ) }
167
189
</ div >
168
190
< div className = "flex flex-col flex-1 overflow-y-hidden" >
169
191
{ /* Col-reverse is used to enable automatic scrolling as content populates the div */ }
0 commit comments