-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
653 lines (553 loc) · 23.3 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
using System.CommandLine;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Events;
using Microsoft.SemanticKernel.Orchestration;
using SkPlayground.Plugins;
using SkPlayground.Extensions;
using Microsoft.SemanticKernel.Planners;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate;
using Microsoft.SemanticKernel.Connectors.Memory.Qdrant;
using Microsoft.SemanticKernel.Connectors.Memory.Sqlite;
using Microsoft.SemanticKernel.Plugins.Memory;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI.TextEmbedding;
using Microsoft.SemanticKernel.TemplateEngine.Basic;
using Microsoft.SemanticKernel.Memory;
using SkPlayground.Models;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI.ChatCompletion;
using SkPlayground.Util.Helpers;
using Microsoft.SemanticKernel.TemplateEngine;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.AI;
using static Microsoft.SemanticKernel.TemplateEngine.PromptTemplateConfig;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Console;
using Serilog;
using Serilog.Events;
using SkPlayground.WebServer.Formatters;
using SkPlayground.WebServer.Filters;
using SkPlayground.WebServer.Middleware;
namespace SkPlayground;
class Program
{
private static IConfiguration? Configuration { get; set; }
public static async Task Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFiles(Directory.GetCurrentDirectory(), "appsettings.*.json", optional: false, reloadOnChange: true);
Configuration = builder.Build();
var fileOption = new Option<FileInfo>(
new[] { "--input", "-i" },
"Path to the input file to be processed");
var functionOption = new Option<string>(
new[] { "--function", "-f" },
"The function to be executed.");
var webServerOption = new Option<bool>(
new[] { "--webserver", "-w" },
"Run the web server.");
var methodOption = new Option<string>(
new[] { "--method", "-m" },
"Method to execute.");
var rootCommand = new RootCommand
{
fileOption,
functionOption,
webServerOption,
methodOption
};
rootCommand.SetHandler(
Run,
fileOption, functionOption, webServerOption, methodOption
);
await rootCommand.InvokeAsync(args);
}
private static async Task Run(FileInfo file, string function, bool runWebServer, string method = "RunDefault")
{
if (runWebServer)
{
method = "WebServer";
}
switch (method)
{
case "RunDefault":
await RunDefault(file, function);
break;
case "RunWithActionPlanner":
await RunWithActionPlanner(file, function);
break;
case "RunWithSequentialPlanner":
await RunWithSequentialPlanner(file, function);
break;
case "RunWithHooks": /* this example uses the native function "ExecuteGet" from HttpPlugin */
await RunWithHooks(file, function);
break;
case "RunWithHooks2": /* this example uses a semantic function and the Markdown converter function */
await RunWithHooks2(file, function);
break;
case "RunWithRag":
await RunWithRag(file, function);
break;
case "WebServer":
await RunWebServer();
break;
default:
Console.WriteLine("Invalid method option.");
break;
}
}
private static async Task RunDefault(FileInfo file, string function)
{
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithCompletionService(kernelSettings)
.Build();
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
var rootDirectory = Configuration!.GetSection("PluginSettings:Root").Get<string>();
var pluginDirectories = Configuration.GetSection("PluginSettings:Plugins").Get<string[]>();
var pluginsRoot = Path.Combine(Directory.GetCurrentDirectory(), rootDirectory!);
var pluginImport = kernel.ImportSemanticFunctionsFromDirectory(pluginsRoot, pluginDirectories!);
string description = await File.ReadAllTextAsync(file.FullName);
var context = new ContextVariables();
string key = "input";
context.Set(key, description);
var result = await kernel.RunAsync(context, pluginImport[function]);
Console.WriteLine(result.GetValue<string>());
}
}
private static async Task RunWebServer()
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = new[] { $"--urls=http://*:{8082}" } });
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.MinimumLevel.Override("System", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("logs/webserver.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
builder.Configuration.AddJsonFiles(Directory.GetCurrentDirectory(), "appsettings.*.json", optional: true, reloadOnChange: true);
builder.Services.AddControllers();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Crypto Asistant Plugin API", Version = "v1" });
c.EnableAnnotations();
});
builder.Logging.AddSerilog();
builder.Logging.AddConsole(options =>
{
options.FormatterName = ConsoleFormatterNames.Simple;
});
builder.Logging.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
});
var app = builder.Build();
app.UseSwagger();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Crypto Assistant API V1");
c.RoutePrefix = string.Empty;
});
}
app.UseMiddleware<ContentTypeMiddleware>();
app.UseStaticFiles();
app.UseRouting();
app.MapControllers();
await app.RunAsync();
}
private static async Task RunWithActionPlanner(FileInfo file, string function)
{
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithCompletionService(kernelSettings)
.Build();
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
var rootDirectory = Configuration!.GetSection("PluginSettings:Root").Get<string>();
var pluginDirectories = Configuration.GetSection("PluginSettings:Plugins").Get<string[]>();
var pluginsRoot = Path.Combine(Directory.GetCurrentDirectory(), rootDirectory!);
var pluginImport = kernel.ImportSemanticFunctionsFromDirectory(pluginsRoot, pluginDirectories!);
var httpPlugin = kernel.ImportFunctions(new HttpPlugin(), nameof(HttpPlugin));
var planner = new ActionPlanner(kernel);
var ask = await File.ReadAllTextAsync(file.FullName);
var plan = await planner.CreatePlanAsync(ask);
Console.WriteLine($"\nPLAN:\n{plan.ToSafePlanString()}");
var result = await plan.InvokeAsync(kernel.CreateNewContext());
Console.WriteLine($"\nRESULT:\n{result.GetValue<string>()}");
}
}
private static async Task RunWithSequentialPlanner(FileInfo file, string function)
{
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithCompletionService(kernelSettings)
.Build();
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
var rootDirectory = Configuration!.GetSection("PluginSettings:Root").Get<string>();
var pluginDirectories = Configuration.GetSection("PluginSettings:Plugins").Get<string[]>();
var pluginsRoot = Path.Combine(Directory.GetCurrentDirectory(), rootDirectory!);
var pluginImport = kernel.ImportSemanticFunctionsFromDirectory(pluginsRoot, pluginDirectories!);
var keyGenPlugin = kernel.ImportFunctions(new KeyAndCertGenerator(), nameof(KeyAndCertGenerator));
var secretsPlugin = kernel.ImportFunctions(new SecretYamlUpdater(), nameof(SecretYamlUpdater));
var planner = new SequentialPlanner(kernel);
var ask = await File.ReadAllTextAsync(file.FullName);
var plan = await planner.CreatePlanAsync(ask);
Console.WriteLine($"\nPLAN:\n{plan.ToSafePlanString()}");
var result = await plan.InvokeAsync(kernel.CreateNewContext());
Console.WriteLine($"\nRESULT:\n{result.GetValue<string>()}");
}
}
private static async Task RunWithHooks(FileInfo file, string function)
{
#region Kernel Setup
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithCompletionService(kernelSettings)
.Build();
#endregion
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
// import the plugin that contains native functions for sending http queries
var httpPlugin = kernel.ImportFunctions(new HttpPlugin(), nameof(HttpPlugin));
// configure hooks
kernel.FunctionInvoking += OnFunctionInvoking;
kernel.FunctionInvoked += OnFunctionInvoked;
// We want to download this document:
// "The Development of the C Language"
// that is located here:
var ask = "https://www.bell-labs.com/usr/dmr/www/chist.html";
// We send our ASK to the Kernel
var result = await kernel.RunAsync(ask, httpPlugin["ExecuteGet"]);
Console.WriteLine($"\nRESULT:\n{result.GetValue<string>()}");
}
}
private static async Task RunWithHooks2(FileInfo file, string function)
{
#region Kernel Setup
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithCompletionService(kernelSettings)
.Build();
#endregion
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
var promptTemplateConfig = new PromptTemplateConfig
{
Description = "Ask something about a person",
Input = {
Parameters = new List<InputParameter>
{
new InputParameter
{
Name = "input",
Description = "Person's names",
DefaultValue = ""
}
}
}
};
var requestSettings = new OpenAIRequestSettings
{
ModelId = kernelSettings.DeploymentOrModelId,
ServiceId = kernelSettings.ServiceId,
MaxTokens = 1000,
PresencePenalty = 0,
FrequencyPenalty = 0,
TopP = 1,
Temperature = 0.79,
};
promptTemplateConfig.ModelSettings.Add(requestSettings);
// we define the semantic function
var askAbutPerson = kernel.CreateSemanticFunction(
"Write a short document about {{$input}}. It must have titles and paragraphs.",
promptTemplateConfig: promptTemplateConfig,
functionName: "askAboutPerson",
pluginName: "PersonPlugin"
);
// configure hooks
kernel.FunctionInvoking += (object? sender, FunctionInvokingEventArgs e) =>
{
Console.WriteLine($"{e.FunctionView.Name}");
};
kernel.FunctionInvoked += (object? sender, FunctionInvokedEventArgs e) =>
{
// convert the result to Markdown
Console.WriteLine($"{ConvertToMarkdown(e.SKContext.Result)}");
};
// We send our ASK to the Kernel
var result = await kernel.RunAsync("Dennis Ritchie", askAbutPerson);
}
}
private static async Task RunWithRag(FileInfo file, string function)
{
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithOpenAITextCompletionService(
modelId: kernelSettings.DeploymentOrModelId,
apiKey: kernelSettings.ApiKey,
orgId: kernelSettings.OrgId,
serviceId: kernelSettings.ServiceId)
.WithOpenAITextEmbeddingGenerationService(
modelId: "text-embedding-ada-002",
apiKey: kernelSettings.ApiKey,
orgId: kernelSettings.OrgId,
serviceId: kernelSettings.ServiceId
)
.Build();
var rootDirectory = Configuration!.GetSection("PluginSettings:Root").Get<string>();
var pluginDirectories = Configuration.GetSection("PluginSettings:Plugins").Get<string[]>();
var pluginsRoot = Path.Combine(Directory.GetCurrentDirectory(), rootDirectory!);
var pluginImport = kernel.ImportSemanticFunctionsFromDirectory(pluginsRoot, pluginDirectories!);
//var memoryStore = new WeaviateMemoryStore(endpoint: "http://localhost:8080/v1", loggerFactory: loggerFactory);
//var memoryStore = new VolatileMemoryStore();
//var memoryStore = new QdrantMemoryStore("http://localhost:6333", 1536, loggerFactory: loggerFactory);
var memoryStore = await SqliteMemoryStore.ConnectAsync("memories2.sqlite");
// Create an embedding generator to use for semantic memory.
var embeddingGenerator = new OpenAITextEmbeddingGeneration(modelId: "text-embedding-ada-002", apiKey: kernelSettings.ApiKey,
organization: kernelSettings.OrgId,
loggerFactory: loggerFactory);
// The combination of the text embedding generator and the memory store makes up the 'SemanticTextMemory' object used to
// store and retrieve memories.
var textMemory = new MemoryBuilder()
.WithLoggerFactory(loggerFactory)
.WithTextEmbeddingGeneration(embeddingGenerator)
.WithMemoryStore(memoryStore)
.Build();
// Alternatively, one could use SemanticTextMemory instance instead
//SemanticTextMemory textMemory = new(memoryStore, embeddingGenerator);
var memoryPlugin = new TextMemoryPlugin(textMemory); // can be replaced with TextMemoryExPlugin
var memoryFunctions = kernel.ImportFunctions(memoryPlugin, "MemoryPlugin");
var collection = "aboutme";
// use this to wipe memory
//await memoryStore.DeleteCollectionAsync(collection); return;
bool exists = await memoryStore.DoesCollectionExistAsync(collection);
if (!exists)
{
// there are two ways to populate the memory:
// * with Kernel + Plugins
await PopulateInterestingFacts(kernel, memoryFunctions, collection, FactHelper.GetFacts());
// * with SemanticTextMemory
//await PopulateInterestingFacts(textMemory, collection, FactHelper.GetFacts());
}
// * Three ways to use the memory
// * 1. By using TextMemory methods
//MemoryQueryResult? lookup = await textMemory.GetAsync(collection, "INSERT_ID_HERE");
//IAsyncEnumerable<MemoryQueryResult> lookup = textMemory.SearchAsync(collection, "Do I have pets?", 1, minRelevanceScore: 0.50);
// await foreach (var r in lookup)
// {
// Console.WriteLine("Answer: " + r.Metadata.Text ?? "ERROR: memory not found");
// }
//return;
// * 2. By using Kernel and TextMemoryPlugin
// var result = await kernel.RunAsync(memoryFunctions["Recall"], new()
// {
// [TextMemoryPlugin.CollectionParam] = collection,
// [TextMemoryPlugin.LimitParam] = "1",
// [TextMemoryPlugin.RelevanceParam] = "0.79",
// ["input"] = "Which season do I prefer?"
// });
// Console.WriteLine($"Answer: {result.GetValue<string>()}");
// * 3. By using the RAG Pattern (Retrieval Augmented Generation)
//var answer = await RunMiniRAG(textMemory, kernel, collection, "Tell me something about my hobbies.");
// Console.WriteLine(answer);
await RunChat(textMemory, kernel, collection);
}
private static async Task RunChat(ISemanticTextMemory textMemory, IKernel kernel, string collection)
{
string input = string.Empty;
while (true)
{
Console.Write("User: ");
input = Console.ReadLine()!;
var answer = await ApplyRAG(textMemory, kernel, collection, input);
Console.WriteLine($"Assistant: {answer}");
// Exit conditions
if (input.Equals("exit", StringComparison.OrdinalIgnoreCase) ||
input.Equals("quit", StringComparison.OrdinalIgnoreCase))
{
break;
}
}
}
private static async Task<string> ApplyRAG(ISemanticTextMemory memory, IKernel kernel, string collectionName, string input)
{
// Exit conditions
if (input.Equals("exit", StringComparison.OrdinalIgnoreCase) ||
input.Equals("quit", StringComparison.OrdinalIgnoreCase))
{
return "Goodbye!";
}
var context = kernel.CreateNewContext();
context.Variables.Add("user_input", input);
// retrieve user-specific context based on the user input
var searchResults = memory.SearchAsync(collectionName, input);
var retrieved = new List<string>();
await foreach (var item in searchResults)
{
retrieved.Add(item.Metadata.Text);
}
context.Variables.Add("user_context", string.Join(',', retrieved));
// run SK function and give it the two variables, input and context
var func = kernel.Functions.GetFunction("Assistant", "Chat");
var answer = await kernel.RunAsync(func, context.Variables);
return answer.GetValue<string>()!.Trim();
}
/// <summary>
/// Populates the memory with facts about an entity
/// </summary>
/// <param name="kernel">Kernel</param>
/// <param name="memoryFunctions">Memory Plugin</param>
/// <param name="collection">Collection name</param>
/// <param name="facts">List of facts</param>
/// <returns>Enumerable containing KernelResults</returns>
private static async Task<IEnumerable<KernelResult?>> PopulateInterestingFacts(IKernel kernel, IDictionary<string, ISKFunction> memoryFunctions, string collection, IEnumerable<Fact> facts)
{
var results = new List<KernelResult?>();
foreach (var fact in facts)
{
var result = await kernel.RunAsync(memoryFunctions["Save"], new()
{
[TextMemoryPlugin.CollectionParam] = collection,
[TextMemoryPlugin.KeyParam] = fact.Id,
["input"] = fact.Text,
//
// only when TextMemoryExPlugin is in use
// *****
//["description"] = fact.Description,
//["additionalMetadata"] = fact.AdditionalMetadata
// *****
//
});
results.Add(result);
}
return results;
}
/// <summary>
/// Populates the memory with facts about an entity
/// </summary>
/// <param name="memory">Memory</param>
/// <param name="collection">Collection name</param>
/// <param name="facts">List of facts</param>
/// <returns></returns>Enumerable containing IDs of saved memory records<summary>
private static async Task<IEnumerable<string>> PopulateInterestingFacts(ISemanticTextMemory memory, string collection, IEnumerable<Fact> facts)
{
var ids = new List<string>();
// Iterate through the facts and populate the memory
foreach (var fact in facts)
{
var id = await memory.SaveInformationAsync(
collection: collection,
text: fact.Text,
id: fact.Id,
description: fact.Description,
additionalMetadata: fact.AdditionalMetadata);
ids.Add(id);
}
return ids;
}
/// <summary>
/// Convert plain text to markdown
/// </summary>
/// <param name="plainText">Plain text string</param>
/// <returns>Content as Markdown string</returns>
private static string ConvertToMarkdown(string text)
{
// This flag is used to differentiate between the document title and the subsequent titles
bool isFirstTitle = true;
// Identify and replace titles in the text.
// The pattern (.*\w)\n looks for any line that ends with a word character (\w),
// ensuring it's a title line and not a blank line or a line of text that's part of a paragraph.
var result = Regex.Replace(text, @"(.*\w)\n", match =>
{
// For the first title, we prefix it with a single hash (#)
if (isFirstTitle)
{
isFirstTitle = false;
return $"# {match.Groups[1].Value}\n\n";
}
else
{
return $"## {match.Groups[1].Value}\n\n";
}
});
return result;
}
//below are the pre/post event handlers
private static void OnFunctionInvoked(object? sender, FunctionInvokedEventArgs e)
{
Console.WriteLine($"{e.FunctionView.Name}");
}
private static void OnFunctionInvoking(object? sender, FunctionInvokingEventArgs e)
{
// By default, the input variable is called INPUT.
// However, the native function "ExecuteGet" from the Plugin expects "url" as its only argument.
// So we must "hook into" the flow and manipulate variables before SK calls the "HttpGet" method.
e.SKContext.Variables.Remove("INPUT", out var urlVal);
e.SKContext.Variables.TryAdd("url", urlVal!);
Console.WriteLine($"{e.FunctionView.Name}");
}
}