diff --git a/bootstrap-dotnet/Program.cs b/bootstrap-dotnet/Program.cs index 520f282d..20931734 100644 --- a/bootstrap-dotnet/Program.cs +++ b/bootstrap-dotnet/Program.cs @@ -36,7 +36,7 @@ static async Task Main(string[] args) var client = serviceProvider.GetRequiredService(); // Check command line arguments - if (args.Length > 0 && args[0].ToLower() == "hn") + if (args.Length > 0 && args[0].ToLower() == "run") { Console.WriteLine("Running HN extraction..."); await RunHNExtraction.RunAsync(client); diff --git a/bootstrap-dotnet/README.md b/bootstrap-dotnet/README.md new file mode 100644 index 00000000..50409540 --- /dev/null +++ b/bootstrap-dotnet/README.md @@ -0,0 +1,68 @@ +

+ +

+ +# Inferable .NET Bootstrap + +This is a .NET bootstrap application that demonstrates how to integrate and use our SDK. It serves as a reference implementation and starting point for .NET developers. + +## The Application + +The application is a simple .NET application that extracts the top posts from Hacker News and summarizes the comments for each post. It demonstrates how to: + +- Register C# functions with Inferable +- Trigger a Run programmatically to orchestrate the functions +- Control the control flow of the Run using native C# async/await primitives + +```mermaid +sequenceDiagram + participant extract + participant summarizePost + participant generatePage + + extract->>extract: Get top 3 HN posts + extract->>summarizePost: Posts data + summarizePost->>summarizePost: Get & analyze comments + summarizePost->>generatePage: Summaries data + generatePage->>generatePage: Generate HTML +``` + +## How to Run + +1. Start the local worker machine: + +```bash +dotnet run +``` + +2. Trigger the HN extraction: + +```bash +dotnet run run +``` + +## How it works + +1. The worker machine uses the Inferable .NET SDK to register functions with Inferable. These functions are registered in the `Register.cs` file: + +- `GetUrlContent`: Fetches the content of a URL and strips HTML tags +- `ScoreHNPost`: Scores a Hacker News post based on upvotes and comment count +- `GeneratePage`: Generates an HTML page from markdown + +2. The `Run.cs` script defines three main operations that are orchestrated by Inferable: + +- `extract`: Extracts and scores the top 10 HN posts, selecting the top 3 +- `summarizePost`: Summarizes the comments for each selected post +- `generatePage`: Generates an HTML page containing the summaries + +3. The application flow: + +- The extract operation fetches the top posts from Hacker News and scores them using internal scoring logic +- For each selected post, a separate summarization run analyzes the comments +- Finally, the generate operation creates an HTML page containing all the summaries + +4. The application uses C# primitives for control flow: + +- Async/await for non-blocking operations +- Strong typing with C# records and classes +- Reflection for inferring the function signatures and result schema diff --git a/bootstrap-dotnet/Run.cs b/bootstrap-dotnet/Run.cs index 231e3766..268ef2b1 100644 --- a/bootstrap-dotnet/Run.cs +++ b/bootstrap-dotnet/Run.cs @@ -53,7 +53,12 @@ private static void OpenInferableInBrowser() try { var clusterId = Environment.GetEnvironmentVariable("INFERABLE_CLUSTER_ID"); - var url = $"https://app.inferable.ai/clusters/{clusterId}/runs"; + var url = $"https://app.inferable.ai/clusters"; + + if (!string.IsNullOrEmpty(clusterId)) + { + url += $"/{clusterId}/runs"; + } if (OperatingSystem.IsWindows()) { diff --git a/bootstrap-go/README.md b/bootstrap-go/README.md index 661ba300..19df2ff3 100644 --- a/bootstrap-go/README.md +++ b/bootstrap-go/README.md @@ -1,3 +1,7 @@ +

+ +

+ # Inferable Go Bootstrap This is a Go bootstrap application that demonstrates how to integrate and use our SDK. It serves as a reference implementation and starting point for Go developers. diff --git a/bootstrap-node/README.md b/bootstrap-node/README.md index 03133481..f429b9c1 100644 --- a/bootstrap-node/README.md +++ b/bootstrap-node/README.md @@ -1,3 +1,7 @@ +

+ +

+ # Inferable Node.js Bootstrap This is a Node.js bootstrap application that demonstrates how to integrate and use our SDK. It serves as a reference implementation and starting point for Node.js developers. diff --git a/bootstrap-node/src/run.ts b/bootstrap-node/src/run.ts index 6a6a8ee5..f1004f17 100644 --- a/bootstrap-node/src/run.ts +++ b/bootstrap-node/src/run.ts @@ -85,15 +85,16 @@ const generatePage = async ({ data }: { data: object }) => }) .then((r) => r.poll()); +const url = process.env.INFERABLE_CLUSTER_ID + ? `https://app.inferable.ai/clusters/${process.env.INFERABLE_CLUSTER_ID}/runs` + : "https://app.inferable.ai/clusters"; + // open the page in the browser -exec( - `open https://app.inferable.ai/clusters/${process.env.INFERABLE_CLUSTER_ID}/runs`, - (error) => { - if (error) { - console.error("Failed to open browser:", error); - } - }, -); +exec(`open ${url}`, (error) => { + if (error) { + console.error("Failed to open browser:", error); + } +}); extract() .then(({ result }) => {