Skip to content

Commit

Permalink
Fix to log more details about failed function execution. (microsoft#529)
Browse files Browse the repository at this point in the history
### Motivation and Context

This change is required to allow SK SDK client code/hosting app to get
more details about SK function execution failures.

Open issue: [Important Error Message from Azure OpenAI service is
ignored](microsoft#105)

### Description
This change does two things:
- Passes a logger instance as an argument of Kernel.FromSemanticConfig
method so that the method can write logs at all.
- Adds AIException details to the warning message logged by SKFunction
when handling the function execution failure.
  • Loading branch information
SergeyMenshykh authored Apr 21, 2023
1 parent 7d181ab commit a73bf9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/SemanticKernel/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private ISKFunction CreateSemanticFunction(
$"Function type not supported: {functionConfig.PromptTemplateConfig}");
}

ISKFunction func = SKFunction.FromSemanticConfig(skillName, functionName, functionConfig);
ISKFunction func = SKFunction.FromSemanticConfig(skillName, functionName, functionConfig, this._log);

// Connect the function to the current kernel skill collection, in case the function
// is invoked manually without a context and without a way to find other functions.
Expand Down
12 changes: 9 additions & 3 deletions dotnet/src/SemanticKernel/Orchestration/SKFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.AI;
using Microsoft.SemanticKernel.AI.TextCompletion;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
Expand Down Expand Up @@ -112,11 +113,16 @@ async Task<SKContext> LocalFunc(
string completion = await client.CompleteAsync(prompt, requestSettings, context.CancellationToken);
context.Variables.Update(completion);
}
catch (AIException ex)
{
const string message = "Something went wrong while rendering the semantic function or while executing the text completion. Function: {0}.{1}. Error: {2}. Details: {3}";
log?.LogError(ex, message, skillName, functionName, ex.Message, ex.Detail);
context.Fail(ex.Message, ex);
}
catch (Exception ex) when (!ex.IsCriticalException())
{
log?.LogWarning(ex,
"Something went wrong while rendering the semantic function or while executing the text completion. Function: {0}.{1}. Error: {2}",
skillName, functionName, ex.Message);
const string message = "Something went wrong while rendering the semantic function or while executing the text completion. Function: {0}.{1}. Error: {2}";
log?.LogError(ex, message, skillName, functionName, ex.Message);
context.Fail(ex.Message, ex);
}

Expand Down

0 comments on commit a73bf9a

Please sign in to comment.