Replies: 2 comments 2 replies
-
Adding @SergeyMenshykh for visibility. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @KishanJ98, I can think of a few reasons the function is not called:
If the function still isn't called after you've checked the reasons above, try running this code snippet and let me know if it works: [Fact]
public async Task RunPromptTemplateConfigWithAutoFunctionChoiceBehaviorUsingStreamingAsync()
{
// Create kernel
IKernelBuilder builder = Kernel.CreateBuilder();
builder.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey);
Kernel kernel = builder.Build();
kernel.ImportPluginFromType<ChatPlugin>();
string promptTemplateConfig = """
template_format: semantic-kernel
template: If asked to generate an image, use the GenerateImage method to generate an image url and return the outcome of the method as your answer. {{$prompt}}
execution_settings:
default:
function_choice_behavior:
type: auto
functions:
- ChatPlugin.GenerateImage
""";
KernelFunction promptFunction = kernel.CreateFunctionFromPromptYaml(promptTemplateConfig);
KernelArguments arguments = new()
{
{ "prompt", "Generate an image of a cat." }
};
StringBuilder stringBuilder = new();
await foreach (StreamingChatMessageContent update in kernel.InvokeStreamingAsync(promptFunction, arguments))
{
if(!string.IsNullOrEmpty(update.Content))
{
stringBuilder.Append(update.Content);
}
}
Console.Write(stringBuilder.ToString());
}
private sealed class ChatPlugin
{
[KernelFunction, Description("Generate an image based on the prompt.")]
public async Task<string?> GenerateImageAsync([Description("The user's message or user intent")] string message)
{
return "https://fake-image-url/";
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Based on the examples, I have a YAML prompt with the following settings:
I have a class called ChatPlugin with the following method:
I can see that in the Kernel there is a ChatPlugin with a function called 'GenerateImage'.
In the YAML prompt template I have the instruction: "If asked to generate an image, use the GenerateImage method to generate an image url and return the outcome of the method as your answer."
I'm using the following to execute the function:
However, the model is not calling this method when the user message intent is to generate an image. How to make this work?
Beta Was this translation helpful? Give feedback.
All reactions