async Task InvokeFunctionWithErrorHandling()

in src/WebJobs.Extensions.OpenAI/Assistants/AssistantService.cs [405:435]


    async Task<string?> InvokeFunctionWithErrorHandling(
        string assistantId,
        ChatToolCall call,
        CancellationToken cancellationToken)
    {
        try
        {
            // NOTE: In Consumption plans, calling a function from another function results in double-billing.
            // CONSIDER: Use a background thread to invoke the action to avoid double-billing.
            string? result = await this.skillInvoker.InvokeAsync(call, cancellationToken);

            this.logger.LogInformation(
                "[{id}] Function '{Name}' returned the following content: {Content}",
                assistantId,
                call.FunctionName,
                result);

            return result;
        }
        catch (Exception ex)
        {
            this.logger.LogError(
                ex,
                "[{id}] Function '{Name}' failed with an unhandled exception",
                assistantId,
                call.FunctionName);

            // CONSIDER: Automatic retries?
            return "The function call failed. Let the user know and ask if they'd like you to try again";
        }
    }