Skip to content

Commit bbeb63d

Browse files
committed
Improve error message
1 parent e9ce9dc commit bbeb63d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/ChatGPT.Core/ViewModels/Chat/ChatViewModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)