This is my code
builder.AddOpenAIChatCompletion(modelId: "gpt-4o", apiKey: openAiKey,
httpClient: new HttpClient(handler));//at this,i add a new httpclient
_kernel = kernel.KernelBuild();
var pluginDirectoryPath = Path.Combine(AppContext.BaseDirectory, "AiFun", "plugins", "OfficePlugin");
_kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginDirectoryPath, "SummarizePlugin"));
_kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginDirectoryPath, "WriterPlugin"));
_kernel.ImportPluginFromType<MathPlugin>();
planner = new HandlebarsPlanner(new HandlebarsPlannerOptions() { AllowLoops = true });
var plan = await planner.CreatePlanAsync(_kernel, target);
var result = (await plan.InvokeAsync(_kernel,new KernelArguments())).Trim();
If target is about “math”. It can be well done, but if I try that target is about WriterPlugin or SummarizePlugin plan can be created, but it can’t be invoked. For a long time, no response. Why?
details:
when target =”5+7+1″ ,can receive plan:
{{!-- Step 0: Extract key values --}}
{{set "value1" 5}}
{{set "value2" 7}}
{{set "value3" 1}}
{{!-- Step 1: Add 5 and 7 --}}
{{set "sum1" (MathPlugin-Add value=value1 amount=value2)}}
{{!-- Step 2: Add the previous sum and 1 --}}
{{set "finalSum" (MathPlugin-Add value=sum1 amount=value3)}}
{{!-- Step 3: Print the final result --}}
{{json finalSum}}
and it can be invoked ,result = 13
when target =”give me a poem”,can receive plan :
{{!-- Step 1: Set the scenario for the poem --}}
{{set "poemScenario" "a peaceful morning by the lake"}}
{{!-- Step 2: Generate the poem using the WriterPlugin-ShortPoem helper --}}
{{set "generatedPoem" (WriterPlugin-ShortPoem input=poemScenario)}}
{{!-- Step 3: Output the generated poem --}}
{{json generatedPoem}}
but it can’t be invoked .because it’s asyn ,app is awaiting for response.no error messages and no exception happen.
i found that ,to the api ,my app send :
{"messages":[{"content":"Generate a short funny poem or limerick to explain the given event. Be creative and be funny. Let your imagination run wild.nEvent:a peaceful morning by the laken","role":"user"}],"max_tokens":60,"temperature":0.5,"top_p":0,"n":1,"presence_penalty":0,"frequency_penalty":0,"model":"gpt-4o"}
and api can receive that :
{"id":"chatcmpl-9axNkvkL1OA9rriIQ5RCbQbwTUTIN","object":"chat.completion","created":1718595100,"model":"gpt-4o","choices":[{"index":0,"message":{"role":"assistant","content":"By the lake on a morning so bright,nA duck tried to take its first flight.nBut it slipped on a log,nFell right into a frog,nWho croaked, "Next time, use a kite!""},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":42,"completion_tokens":44,"total_tokens":86},"system_fingerprint":"fp_f4e629d0a5","code":0,"msg":"ok"}
it’s the same of that invoke plugin,but in plan.invoke,no message.
MathPlugin is from Microsoft.SemanticKernel.Plugins.Core
SummarizePlugin and WriterPlugin is from github “https://github.com/microsoft/semantic-kernel/tree/main/prompt_template_samples”
猫猫秋小裤 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.