forked from EllieBotDevs/elliebot
OpenAI apis will now correctly print an error to the console if the request fails
This commit is contained in:
parent
86a4a1ca99
commit
138d3441e4
1 changed files with 12 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue