mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
1. Fix missing `this.` and `Async` suffix 2. Fix some indentation, spacing, etc. 3. Enable these rules and format accordingly: IDE0001: Simplify name IDE0005: Remove unnecessary using directives IDE0009: Add this or Me qualification IDE0011: Add braces IDE0018: Inline variable declaration IDE0032: Use auto-implemented property IDE0034: Simplify 'default' expression IDE0035: Remove unreachable code IDE0040: Add accessibility modifiers IDE0049: Use language keywords instead of framework type names for type references IDE0050: Convert anonymous type to tuple IDE0051: Remove unused private member IDE0055: Formatting rule IDE0060: Remove unused parameter IDE0070: Use 'System.HashCode.Combine' IDE0071: Simplify interpolation IDE0073: Require file header IDE0082: Convert typeof to nameof IDE0090: Simplify new expression IDE0161: Use file-scoped namespace
59 lines
2.9 KiB
C#
59 lines
2.9 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SemanticKernel;
|
|
using Microsoft.SemanticKernel.Orchestration;
|
|
using RepoUtils;
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
public static class Example21_ChatGptPlugins
|
|
{
|
|
public static async Task RunAsync()
|
|
{
|
|
await RunChatGptPluginAsync();
|
|
}
|
|
|
|
private static async Task RunChatGptPluginAsync()
|
|
{
|
|
var kernel = new KernelBuilder().WithLogger(ConsoleLogger.Log).Build();
|
|
using HttpClient importHttpClient = new();
|
|
importHttpClient.DefaultRequestHeaders.Add("User-Agent", "Microsoft-Semantic-Kernel");
|
|
|
|
//Import a ChatGPT plugin using one of the following Kernel extension methods
|
|
//kernel.ImportChatGptPluginSkillFromResourceAsync
|
|
//kernel.ImportChatGptPluginSkillSkillFromDirectory
|
|
//kernel.ImportChatGptPluginSkillSkillFromFile
|
|
//kernel.ImportChatGptPluginSkillFromUrlAsync
|
|
|
|
var skill = await kernel.ImportChatGptPluginSkillFromUrlAsync("<skill name>", new Uri("<chatGPT-plugin>"), importHttpClient);
|
|
|
|
//Add arguments for required parameters, arguments for optional ones can be skipped.
|
|
var contextVariables = new ContextVariables();
|
|
contextVariables.Set("<parameter-name>", "<parameter-value>");
|
|
|
|
//Run
|
|
var result = await kernel.RunAsync(contextVariables, skill["productsUsingGET"]);
|
|
|
|
Console.WriteLine("Skill execution result: {0}", result);
|
|
Console.ReadLine();
|
|
|
|
//--------------- Example of using Klarna ChatGPT plugin ------------------------
|
|
|
|
//var kernel = new KernelBuilder().WithLogger(ConsoleLogger.Log).Build();
|
|
|
|
//var skill = await kernel.ImportChatGptPluginSkillFromUrlAsync("Klarna", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"), importHttpClient);
|
|
|
|
//var contextVariables = new ContextVariables();
|
|
//contextVariables.Set("q", "Laptop"); //A precise query that matches one very small category or product that needs to be searched for to find the products the user is looking for. If the user explicitly stated what they want, use that as a query. The query is as specific as possible to the product name or category mentioned by the user in its singular form, and don't contain any clarifiers like latest, newest, cheapest, budget, premium, expensive or similar. The query is always taken from the latest topic, if there is a new topic a new query is started.
|
|
//contextVariables.Set("size", "3"); // number of products returned
|
|
//contextVariables.Set("budget", "200"); // maximum price of the matching product in local currency, filters results
|
|
|
|
//var result = await kernel.RunAsync(contextVariables, skill["productsUsingGET"]);
|
|
|
|
//Console.WriteLine("Klarna skill response: {0}", result);
|
|
//Console.ReadLine();
|
|
}
|
|
}
|