[Doc] Semantic Functions with Multiple Arguments
It's possible that I merely haven't found the right spot in the docs yet, but: what is the preferred way of calling a Semantic Function which takes multiple arguments?
As a concrete example, the Rewriter function (in samples/WriterSkill) has the following prompt file:
Rewrite the given text like it was written in this style or by: {{$style}}.
MUST RETAIN THE MEANING AND FACTUAL CONTENT AS THE ORIGINAL.
{{$input}}
There are obviously two parameters - input for the text to be rewritten, and style to specify how things should be rephrased.
There's also the config.json file, with the following contents:
{
"schema": 1,
"type": "completion",
"description": "Automatically generate compact notes for any text or text document",
"completion": {
"max_tokens": 256,
"temperature": 0.0,
"top_p": 0.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0
}
}
One thing I have noticed is that some other skills have an input key in this JSON, which itself has a parameters key and a list. I'm not sure if this is significant.
Anyway, experimenting with this, it appears that the only way to change the value of the style parameter is by using a context:
context = kernel.create_new_context()
context["style"] = "Shakespeare"
target_text = """
I was walking along a street when I saw my friend. We stopped to say 'Hello' and catch up with recent events.
"""
result = rewriteFunction(target_text, context=context)
print(result)
All my attempts to put the style parameter directly into the rewriteFunction() call have come to naught, but this approach feels quite cumbersome. Have I missed something?
Running:
[x.name for x in rewriteFunction.parameters]
is showing two parameters, named according to the prompt, but I can't figure out how to use these simply in the rewriteFunction() call.
@riedgar-ms - here is what the config.json will look at (FYI) { "schema": 1, "type": "completion", "description": "Automatically generate compact notes for any text or text document", "completion": { "max_tokens": 256, "temperature": 0, "top_p": 0, "presence_penalty": 0, "frequency_penalty": 0 }, "input": { "parameters": [ { "name": "input", "description": "", "defaultValue": "" }, { "name": "style", "description": "", "defaultValue": "" } ] } }
@dluc can you help with how to do the calling.
That would be really helpful; did I miss an example showing how to do this? Passing other things through the context feels wrong.
Ping.....
In the current implementation, if you want to use multiple arguments in your functions, you'll need to make use of the SKContext and then put all the parameters there. I agree it feels strange, and we're reviewing the design of this. Take a look at this notebook for a more in-depth look at native/semantic functions:
https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/python/08-native-function-inline.ipynb
We now have this sample: https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/KernelSyntaxExamples/Example56_TemplateNativeFunctionsWithMultipleArguments.cs
This is now possible so closing this issue.