Skip to content

Commit

Permalink
docs: Update the README with branding
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeesha committed Nov 5, 2024
1 parent 81fb264 commit 0cc5576
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bootstrap-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static async Task Main(string[] args)
var client = serviceProvider.GetRequiredService<InferableClient>();

// 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);
Expand Down
68 changes: 68 additions & 0 deletions bootstrap-dotnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<p align="center">
<img src="https://a.inferable.ai/logo-hex.png" width="200" style="border-radius: 10px" />
</p>

# 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
7 changes: 6 additions & 1 deletion bootstrap-dotnet/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
4 changes: 4 additions & 0 deletions bootstrap-go/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p align="center">
<img src="https://a.inferable.ai/logo-hex.png" width="200" style="border-radius: 10px" />
</p>

# 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.
Expand Down
4 changes: 4 additions & 0 deletions bootstrap-node/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p align="center">
<img src="https://a.inferable.ai/logo-hex.png" width="200" style="border-radius: 10px" />
</p>

# 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.
Expand Down
17 changes: 9 additions & 8 deletions bootstrap-node/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 0cc5576

Please sign in to comment.