Skip to content

OpenAI skill trigger/Return value from pipeline #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/DurableWorker/DurableController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public bool TryGetInputBindingParameterValue(string bindingName, out object valu

public void AddPipelineOutputIfNecessary(Collection<object> pipelineItems, Hashtable result)
{

if (ShouldSuppressPipelineTraces())
{
var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems);
Expand Down
19 changes: 19 additions & 0 deletions src/FunctionInfoUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System.Linq;

namespace Microsoft.Azure.Functions.PowerShellWorker
{
internal class FunctionInfoUtilities
{
private const string assistantSkillTriggerName = "assistantSkillTrigger";

public static bool hasAssistantSkillTrigger(AzFunctionInfo info)
{
return info.InputBindings.Where(x => x.Value.Type == assistantSkillTriggerName).Any();
}
}
}
4 changes: 2 additions & 2 deletions src/PowerShell/PowerShellManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ public Hashtable InvokeFunction(
else
{
var isActivityFunction = functionInfo.DurableFunctionInfo.IsActivityFunction;
if (!isActivityFunction)
if (!isActivityFunction && !FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo))
{
_pwsh.AddCommand(Utils.TracePipelineObjectCmdlet);
}
return ExecuteUserCode(isActivityFunction, outputBindings);
return ExecuteUserCode(isActivityFunction || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo), outputBindings);
}
}
catch (RuntimeException e)
Expand Down
2 changes: 1 addition & 1 deletion src/RequestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction
}
}

if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue)
if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo))
{
response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData(isDurableData: true);
}
Expand Down
46 changes: 45 additions & 1 deletion test/Unit/PowerShell/PowerShellManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void LoggerContextIsSet()
[InlineData(DurableFunctionType.None, false)]
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
[InlineData(DurableFunctionType.ActivityFunction, true)]
internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
internal void SuppressPipelineTracesForDurableActivityFunction(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
{
s_testLogger.FullLog.Clear();

Expand All @@ -416,6 +416,50 @@ internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFuncti
}
}

[Theory]
[InlineData("httpTrigger", false)]
[InlineData("assistantSkillTrigger", true)]
internal void SuppressPipelineTracesForOpenAIAssistantSkillTrigger(string inputBindingType, bool shouldSuppressPipelineTraces)
{
s_testLogger.FullLog.Clear();

var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1");

BindingInfo bindingInfo = null;
string oldBindingType = "";
foreach(var binding in s_functionLoadRequest.Metadata.Bindings)
{
if (binding.Value.Direction == BindingInfo.Types.Direction.In)
{
bindingInfo = binding.Value;
oldBindingType = binding.Value.Type;
binding.Value.Type = inputBindingType;
break;
}
}

var (functionInfo, testManager) = PrepareFunction(path, string.Empty);

try
{
FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings);

var result = testManager.InvokeFunction(functionInfo, null, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch(), null);

var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList();
var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" };
Assert.Equal(expected, relevantLogs);
}
finally
{
FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId);
if (bindingInfo != null)
{
bindingInfo.Type = oldBindingType;
}
}
}

private static List<ParameterBinding> CreateOrchestratorInputData()
{
var orchestrationContext = new OrchestrationContext
Expand Down
Loading