Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Apr 7, 2023
1 parent e9ce9dc commit bbeb63d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ChatGPT.Core/ViewModels/Chat/ChatViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public ChatMessage[] CreateChatMessages()
};
}

ChatResponse? responseData;
var apiKey = Environment.GetEnvironmentVariable(Constants.EnvironmentVariableApiKey);
var restoreApiKey = false;

Expand All @@ -320,8 +321,22 @@ public ChatMessage[] CreateChatMessages()
Environment.SetEnvironmentVariable(Constants.EnvironmentVariableApiKey, chatSettings.ApiKey);
restoreApiKey = true;
}
else
{
if (string.IsNullOrEmpty(apiKey))
{
responseData = new ChatResponseError()
{
Error = new ChatError
{
Message = "The OpenAI api key is not set."
}
};

return responseData;
}
}

ChatResponse? responseData = null;
try
{
responseData = await chat.GetResponseDataAsync(chatServiceSettings, token);
Expand Down

0 comments on commit bbeb63d

Please sign in to comment.