Skip to content

Commit 9c1d4cf

Browse files
authored
OpenAI skill trigger/Return value from pipeline (#1102)
* OpenAI skill trigger/Return value from pipeline * Add test to ensure pipeline output is not logged for assistantSkillTrigger
1 parent 5d97916 commit 9c1d4cf

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

src/DurableWorker/DurableController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public bool TryGetInputBindingParameterValue(string bindingName, out object valu
144144

145145
public void AddPipelineOutputIfNecessary(Collection<object> pipelineItems, Hashtable result)
146146
{
147-
148147
if (ShouldSuppressPipelineTraces())
149148
{
150149
var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems);

src/FunctionInfoUtilities.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Linq;
7+
8+
namespace Microsoft.Azure.Functions.PowerShellWorker
9+
{
10+
internal class FunctionInfoUtilities
11+
{
12+
private const string assistantSkillTriggerName = "assistantSkillTrigger";
13+
14+
public static bool hasAssistantSkillTrigger(AzFunctionInfo info)
15+
{
16+
return info.InputBindings.Where(x => x.Value.Type == assistantSkillTriggerName).Any();
17+
}
18+
}
19+
}

src/PowerShell/PowerShellManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ public Hashtable InvokeFunction(
243243
else
244244
{
245245
var isActivityFunction = functionInfo.DurableFunctionInfo.IsActivityFunction;
246-
if (!isActivityFunction)
246+
if (!isActivityFunction && !FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo))
247247
{
248248
_pwsh.AddCommand(Utils.TracePipelineObjectCmdlet);
249249
}
250-
return ExecuteUserCode(isActivityFunction, outputBindings);
250+
return ExecuteUserCode(isActivityFunction || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo), outputBindings);
251251
}
252252
}
253253
catch (RuntimeException e)

src/RequestProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction
537537
}
538538
}
539539

540-
if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue)
540+
if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo))
541541
{
542542
response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData(isDurableData: true);
543543
}

test/Unit/PowerShell/PowerShellManagerTests.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public void LoggerContextIsSet()
392392
[InlineData(DurableFunctionType.None, false)]
393393
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
394394
[InlineData(DurableFunctionType.ActivityFunction, true)]
395-
internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
395+
internal void SuppressPipelineTracesForDurableActivityFunction(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
396396
{
397397
s_testLogger.FullLog.Clear();
398398

@@ -416,6 +416,50 @@ internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFuncti
416416
}
417417
}
418418

419+
[Theory]
420+
[InlineData("httpTrigger", false)]
421+
[InlineData("assistantSkillTrigger", true)]
422+
internal void SuppressPipelineTracesForOpenAIAssistantSkillTrigger(string inputBindingType, bool shouldSuppressPipelineTraces)
423+
{
424+
s_testLogger.FullLog.Clear();
425+
426+
var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1");
427+
428+
BindingInfo bindingInfo = null;
429+
string oldBindingType = "";
430+
foreach(var binding in s_functionLoadRequest.Metadata.Bindings)
431+
{
432+
if (binding.Value.Direction == BindingInfo.Types.Direction.In)
433+
{
434+
bindingInfo = binding.Value;
435+
oldBindingType = binding.Value.Type;
436+
binding.Value.Type = inputBindingType;
437+
break;
438+
}
439+
}
440+
441+
var (functionInfo, testManager) = PrepareFunction(path, string.Empty);
442+
443+
try
444+
{
445+
FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings);
446+
447+
var result = testManager.InvokeFunction(functionInfo, null, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch(), null);
448+
449+
var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList();
450+
var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" };
451+
Assert.Equal(expected, relevantLogs);
452+
}
453+
finally
454+
{
455+
FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId);
456+
if (bindingInfo != null)
457+
{
458+
bindingInfo.Type = oldBindingType;
459+
}
460+
}
461+
}
462+
419463
private static List<ParameterBinding> CreateOrchestratorInputData()
420464
{
421465
var orchestrationContext = new OrchestrationContext

0 commit comments

Comments
 (0)