You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
usingMicrosoft.SemanticKernel;varbuilder=Kernel.CreateBuilder();builder.Services.AddDashScopeChatCompletion("your-api-key","qwen-max");varkernel=builder.Build();varprompt="<message role=\"user\">Tell me about the Cnblogs</message>";varresponse=awaitkernel.InvokePromptAsync(prompt);Console.WriteLine(response);
// Kernel Memory stuffvarmemory=newKernelMemoryBuilder(builder.Services).WithDashScope(builder.Configuration).Build();builder.Services.AddSingleton(memory);// SK stuffbuilder.Services.AddDashScopeChatCompletion(builder.Configuration);builder.Services.AddSingleton( sp=>{varplugins=newKernelPluginCollection();plugins.AddFromObject(newMemoryPlugin(sp.GetRequiredService<IKernelMemory>(),waitForIngestionToComplete:true),"memory");returnnewKernel(sp,plugins);});
Services
publicclassYourService(Kernelkernel,IKernelMemorymemory){publicasyncTask<string>GetCompletionAsync(stringprompt){varchatResult=awaitkernel.InvokePromptAsync(prompt);returnchatResult.ToString();}publicasyncTaskImportDocumentAsync(stringfilePath,stringdocumentId){awaitmemory.ImportDocumentAsync(filePath,documentId);}publicasyncTask<string>AskMemoryAsync(stringquestion){// use memory.ask to query kernel memoryvarskPrompt=""" Question to Kernel Memory: {{$input}} Kernel Memory Answer: {{memory.ask $input}} If the answer is empty say 'I don't know' otherwise reply with a preview of the answer, truncated to 15 words. """;// you can bundle created functions into a singleton service to reuse themvarmyFunction=kernel.CreateFunctionFromPrompt(skPrompt);varresult=awaitmyFunction.InvokeAsync(question);returnresult.ToString();}}