Skip to content

Commit

Permalink
feat(dotnet): Add run trigger to bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Oct 31, 2024
1 parent 526daf7 commit 2069644
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
44 changes: 36 additions & 8 deletions bootstrap-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,71 @@
Env.Load();
}

var inferable = app.Services.GetService<InferableClient>();
var client = app.Services.GetService<InferableClient>();

if (inferable == null)
if (client == null)
{
throw new Exception("Could not get InferableClient");
}

inferable.Default.RegisterFunction(new FunctionRegistration<SearchInput> {
client.Default.RegisterFunction(new FunctionRegistration<SearchInput> {
Name = "SearchInventory",
Description = "Searches the inventory",
Func = new Func<SearchInput, object?>(input => InventorySystem.SearchInventory(input))
});

inferable.Default.RegisterFunction(new FunctionRegistration<GetInventoryItemInput> {
client.Default.RegisterFunction(new FunctionRegistration<GetInventoryItemInput> {
Name = "GetInventoryItem",
Description = "Gets an inventory item",
Func = new Func<GetInventoryItemInput, object?>(input => InventorySystem.GetInventoryItem(input))
});

inferable.Default.RegisterFunction(new FunctionRegistration<EmptyInput> {
client.Default.RegisterFunction(new FunctionRegistration<EmptyInput> {
Name = "ListOrders",
Description = "Lists all orders",
Func = new Func<EmptyInput, object?>(input => InventorySystem.ListOrders())
});

inferable.Default.RegisterFunction(new FunctionRegistration<EmptyInput> {
client.Default.RegisterFunction(new FunctionRegistration<EmptyInput> {
Name = "TotalOrderValue",
Description = "Calculates the total value of all orders",
Func = new Func<EmptyInput, object?>(input => InventorySystem.TotalOrderValue())
});

inferable.Default.RegisterFunction(new FunctionRegistration<MakeOrderInput> {
client.Default.RegisterFunction(new FunctionRegistration<MakeOrderInput> {
Name = "MakeOrder",
Description = "Makes an order",
Func = new Func<MakeOrderInput, object?>(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<FunctionReference>
// {
// new FunctionReference {
// Function = "SayHello",
// Service = "default"
// }
// },
// Optional: Define a schema for the result to conform to
//ResultSchema = JsonSchema.FromType<RunOutput>();
// Optional: Subscribe an Inferable function to receive notifications when the run status changes
//OnStatusChange = new OnStatusChange<RunOutput>
//{
// 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();

2 changes: 1 addition & 1 deletion bootstrap-dotnet/bootstrap-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Inferable" Version="0.0.8" />
<PackageReference Include="Inferable" Version="0.0.13" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions sdk-dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ client.Default.RegisterFunction(new FunctionRegistration<MyInput>
}),
});

await client.Default.Start();
_ = client.Default.Start();
```

<details>
Expand All @@ -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)
Expand All @@ -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}");
```
Expand Down

0 comments on commit 2069644

Please sign in to comment.