From 206964462ffa0c4fa3723b60f2151bd3ec0e3f1f Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 1 Nov 2024 09:44:27 +1030 Subject: [PATCH] feat(dotnet): Add run trigger to bootstrap --- bootstrap-dotnet/Program.cs | 44 +++++++++++++++++++----- bootstrap-dotnet/bootstrap-dotnet.csproj | 2 +- sdk-dotnet/README.md | 8 ++--- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/bootstrap-dotnet/Program.cs b/bootstrap-dotnet/Program.cs index be9622ca..1f33d1a0 100644 --- a/bootstrap-dotnet/Program.cs +++ b/bootstrap-dotnet/Program.cs @@ -24,43 +24,71 @@ Env.Load(); } -var inferable = app.Services.GetService(); +var client = app.Services.GetService(); -if (inferable == null) +if (client == null) { throw new Exception("Could not get InferableClient"); } -inferable.Default.RegisterFunction(new FunctionRegistration { +client.Default.RegisterFunction(new FunctionRegistration { Name = "SearchInventory", Description = "Searches the inventory", Func = new Func(input => InventorySystem.SearchInventory(input)) }); -inferable.Default.RegisterFunction(new FunctionRegistration { +client.Default.RegisterFunction(new FunctionRegistration { Name = "GetInventoryItem", Description = "Gets an inventory item", Func = new Func(input => InventorySystem.GetInventoryItem(input)) }); -inferable.Default.RegisterFunction(new FunctionRegistration { +client.Default.RegisterFunction(new FunctionRegistration { Name = "ListOrders", Description = "Lists all orders", Func = new Func(input => InventorySystem.ListOrders()) }); -inferable.Default.RegisterFunction(new FunctionRegistration { +client.Default.RegisterFunction(new FunctionRegistration { Name = "TotalOrderValue", Description = "Calculates the total value of all orders", Func = new Func(input => InventorySystem.TotalOrderValue()) }); -inferable.Default.RegisterFunction(new FunctionRegistration { +client.Default.RegisterFunction(new FunctionRegistration { Name = "MakeOrder", Description = "Makes an order", Func = new Func(input => InventorySystem.MakeOrder(input)) }); -await inferable.Default.Start(); +_ = client.Default.StartAsync(); + +var run = await client.CreateRunAsync(new Inferable.API.CreateRunInput +{ + Message = "Can you make an order for 2 lightsabers?", + // Optional: Explicitly attach the `sayHello` function (All functions attached by default) + // AttachedFunctions = new List + // { + // new FunctionReference { + // Function = "SayHello", + // Service = "default" + // } + // }, + // Optional: Define a schema for the result to conform to + //ResultSchema = JsonSchema.FromType(); + // Optional: Subscribe an Inferable function to receive notifications when the run status changes + //OnStatusChange = new OnStatusChange + //{ + // Function = OnStatusChangeFunction + //} +}); + +Console.WriteLine($"Run started: {run.ID}"); + +// Wait for the run to complete and log +var result = await run.PollAsync(null); + +Console.WriteLine($"Run result: {result}"); app.Run(); + diff --git a/bootstrap-dotnet/bootstrap-dotnet.csproj b/bootstrap-dotnet/bootstrap-dotnet.csproj index dda36059..a6558b42 100644 --- a/bootstrap-dotnet/bootstrap-dotnet.csproj +++ b/bootstrap-dotnet/bootstrap-dotnet.csproj @@ -9,7 +9,7 @@ - + diff --git a/sdk-dotnet/README.md b/sdk-dotnet/README.md index 7e9a613a..68b39729 100644 --- a/sdk-dotnet/README.md +++ b/sdk-dotnet/README.md @@ -60,7 +60,7 @@ client.Default.RegisterFunction(new FunctionRegistration }), }); -await client.Default.Start(); +_ = client.Default.Start(); ```
@@ -81,7 +81,7 @@ The following code will create an [Inferable run](https://docs.inferable.ai/page > - in the [CLI](https://www.npmjs.com/package/@inferable/cli) via `inf runs list` ```csharp -var run = await inferable.CreateRun(new CreateRunInput +var run = await inferable.CreateRunAsync(new CreateRunInput { Message = "Say hello to John", // Optional: Explicitly attach the `sayHello` function (All functions attached by default) @@ -101,10 +101,10 @@ var run = await inferable.CreateRun(new CreateRunInput //} }); -Console.WriteLine($"Run started: {run.Id}"); +Console.WriteLine($"Run started: {run.ID}"); // Wait for the run to complete and log -var result = await run.Poll(null); +var result = await run.PollAsync(null); Console.WriteLine($"Run result: {result}"); ```