OpenAI apis will now correctly print an error to the console if the request fails

This commit is contained in:
Toastie 2025-02-03 15:37:48 +13:00
parent 86a4a1ca99
commit 138d3441e4
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7

View file

@ -111,8 +111,20 @@ public partial class OpenAiApiSession : IChatterBotSession
});
var dataString = await data.Content.ReadAsStringAsync();
try
{
data.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
Log.Error(ex, "Failed to get response from OpenAI: {Message}", ex.Message);
return new Error<string>("Failed to get response from OpenAI");
}
try
{
var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString);
// Log.Information("Received response: {Response} ", dataString);