Skip to content

Commit

Permalink
feat: Add run start to DotNet and Node bootstraps (#22)
Browse files Browse the repository at this point in the history
* feat(node): Add run trigger to bootstrap

* feat(dotnet): Add run trigger to bootstrap

* chore: Comment out run start

* [skip ci] Update bootstrap project archives

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
johnjcsmith and github-actions[bot] authored Oct 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d60a31d commit bbaeac2
Showing 10 changed files with 70 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create-archives.yml
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ jobs:
create-archives:
runs-on: ubuntu-latest
needs: check_changes
if: ${{ needs.check_changes.outputs.bootstrap == 'true' }}
permissions:
contents: write
Binary file modified archives/bootstrap-dotnet.zip
Binary file not shown.
Binary file modified archives/bootstrap-go.zip
Binary file not shown.
Binary file modified archives/bootstrap-node.zip
Binary file not shown.
45 changes: 37 additions & 8 deletions bootstrap-dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -24,43 +24,72 @@
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();

// Trigger a Run programmatically
// 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
@@ -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>
8 changes: 4 additions & 4 deletions bootstrap-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bootstrap-node/package.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
},
"dependencies": {
"dotenv": "^16.4.5",
"inferable": "^0.30.32",
"inferable": "^0.30.34",
"tsx": "^4.16.2",
"zod": "^3.23.8"
},
29 changes: 22 additions & 7 deletions bootstrap-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ import { z } from 'zod';
import * as demo from './demo';

// Instantiate the Inferable client.
const i = new Inferable({
const client = new Inferable({
// To get a new key, run:
// npx @inferable/cli auth keys create 'My New Machine Key' --type='cluster_machine'
apiSecret: process.env.INFERABLE_API_SECRET
})

// Register some demo functions
i.default.register({
client.default.register({
name: "searchInventory",
func: demo.searchInventory,
description: "Searches the inventory",
@@ -23,7 +23,7 @@ i.default.register({
},
});

i.default.register({
client.default.register({
name: "getInventoryItem",
func: demo.getInventoryItem,
description: "Gets an inventory item",
@@ -34,7 +34,7 @@ i.default.register({
},
});

i.default.register({
client.default.register({
name: "listOrders",
func: demo.listOrders,
description: "Lists all orders",
@@ -43,7 +43,7 @@ i.default.register({
},
});

i.default.register({
client.default.register({
name: "totalOrderValue",
func: demo.totalOrderValue,
description: "Calculates the total value of all orders",
@@ -52,7 +52,7 @@ i.default.register({
},
});

i.default.register({
client.default.register({
name: "makeOrder",
func: demo.makeOrder,
description: "Makes an order",
@@ -71,6 +71,21 @@ i.default.register({
},
});

i.default.start().then(() => {
client.default.start().then(() => {
console.log("Inferable demo service started");
})

// Trigger a Run programmatically
// https://docs.inferable.ai/pages/runs
// client.run({
// message: "Can you make an order for 2 lightsabers?",
// // Optional: Explicitly attach the functions (All functions attached by default)
// //attachedFunctions: [],
// // Optional: Specify the schema of the result
// //resultSchema: z.object({}),
// }).then(async (run) => {
// console.log("Run result", {
// result: await run.poll(),
// });
// });

8 changes: 4 additions & 4 deletions sdk-dotnet/README.md
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ client.Default.RegisterFunction(new FunctionRegistration<MyInput>
}),
});

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

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

0 comments on commit bbaeac2

Please sign in to comment.