in src/WebJobs.Extensions.OpenAI/Assistants/AssistantSkillTriggerBindingProvider.cs [109:135]
public Task<ITriggerData> BindAsync(object value, ValueBindingContext context)
{
Type destinationType = this.parameterInfo.ParameterType;
SkillInvocationContext skillInvocationContext = (SkillInvocationContext)value;
object? convertedValue;
if (!string.IsNullOrEmpty(skillInvocationContext.Arguments?.ToString()))
{
// We expect that input to always be a string value in the form {"paramName":paramValue}
JObject argsJson = JObject.Parse(skillInvocationContext.Arguments.ToString());
JToken? paramValue = argsJson[this.parameterInfo.Name];
convertedValue = paramValue?.ToObject(destinationType);
}
else
{
// Value types in .NET can't be assigned to null, so we use Activator.CreateInstance to
// create a default value of the type (example, 0 for int).
convertedValue = destinationType.IsValueType ? Activator.CreateInstance(destinationType) : null;
}
SimpleValueProvider inputValueProvider = new(convertedValue, destinationType);
Dictionary<string, object?> bindingData = new(StringComparer.OrdinalIgnoreCase); // TODO: Cache
TriggerData triggerData = new(inputValueProvider, bindingData);
return Task.FromResult<ITriggerData>(triggerData);
}