File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
src/ChatGPT.Core/ViewModels/Chat Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,7 @@ public ChatMessage[] CreateChatMessages()
312312 } ;
313313 }
314314
315+ ChatResponse ? responseData ;
315316 var apiKey = Environment . GetEnvironmentVariable ( Constants . EnvironmentVariableApiKey ) ;
316317 var restoreApiKey = false ;
317318
@@ -320,8 +321,22 @@ public ChatMessage[] CreateChatMessages()
320321 Environment . SetEnvironmentVariable ( Constants . EnvironmentVariableApiKey , chatSettings . ApiKey ) ;
321322 restoreApiKey = true ;
322323 }
324+ else
325+ {
326+ if ( string . IsNullOrEmpty ( apiKey ) )
327+ {
328+ responseData = new ChatResponseError ( )
329+ {
330+ Error = new ChatError
331+ {
332+ Message = "The OpenAI api key is not set."
333+ }
334+ } ;
335+
336+ return responseData ;
337+ }
338+ }
323339
324- ChatResponse ? responseData = null ;
325340 try
326341 {
327342 responseData = await chat . GetResponseDataAsync ( chatServiceSettings , token ) ;
You can’t perform that action at this time.
0 commit comments