This repository was archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
66 lines (51 loc) · 2.1 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
using DotNetEnv;
using Inferable;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<InferableClient>(sp => {
var options = new InferableOptions {
// To get a new key, run:
// npx @inferable/cli auth keys create 'My New Machine Key' --type='cluster_machine'
ApiSecret = System.Environment.GetEnvironmentVariable("INFERABLE_API_SECRET"),
BaseUrl = System.Environment.GetEnvironmentVariable("INFERABLE_API_ENDPOINT"),
};
var logger = sp.GetRequiredService<ILogger<InferableClient>>();
return new InferableClient(options, logger);
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
// Load vars from .env file
Env.Load();
}
var inferable = app.Services.GetService<InferableClient>();
if (inferable == null)
{
throw new Exception("Could not get InferableClient");
}
inferable.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> {
Name = "GetInventoryItem",
Description = "Gets an inventory item",
Func = new Func<GetInventoryItemInput, object?>(input => InventorySystem.GetInventoryItem(input))
});
inferable.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> {
Name = "TotalOrderValue",
Description = "Calculates the total value of all orders",
Func = new Func<EmptyInput, object?>(input => InventorySystem.TotalOrderValue())
});
inferable.Default.RegisterFunction(new FunctionRegistration<MakeOrderInput> {
Name = "MakeOrder",
Description = "Makes an order",
Func = new Func<MakeOrderInput, object?>(input => InventorySystem.MakeOrder(input))
});
await inferable.Default.Start();
app.Run();