-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
### Core Kit Invoke | ||
|
||
The core kit `invoke` function allows us to call boards within another board. This is a powerful tool as it allows us to chain multiple boards together to create entire pipelines of logic. | ||
|
||
## Example | ||
|
||
In this example we are calling the `hello-world` board inside our wrapper board. The wrapper board will then concatenate the output from the `hello-world` board with an input from the wrapper board and return the concacatenated string. | ||
|
||
## Use Cases | ||
|
||
Chaining boards together is a powerful tool as we could use multiple LMM pipelines together. For example we could have a board which calls an API to get some data, in this case let's say this API fetches articles from a website. A wrapper board could then take these articles and perform summarization, another wrapper board could then take this summarization and perform sentiment analysis. The possibilities are endless. This allows us to build boards independently of each other and build large pipelines of logic. | ||
|
||
for more complicated examples see the following boards: | ||
|
||
[Hacker News Algolia Simplified Search](https://github.com/ExaDev/breadboard/blob/develop/packages/breadboard-web/src/boards/hacker-news-simplified-algolia-search.ts) | ||
[Hacker News Algolia Simplified Story Search](https://github.com/ExaDev/breadboard/blob/develop/packages/breadboard-web/src/boards/hacker-news-simplified-algolia-story-search.ts) | ||
[Hacker News Algolia Simplified Comment Search](https://github.com/ExaDev/breadboard/blob/develop/packages/breadboard-web/src/boards/hacker-news-simplified-algolia-search.ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#! /usr/bin/env npx -y tsx | ||
|
||
import { board } from "@google-labs/breadboard"; | ||
|
||
const graph = await board<{ message: string; }>(({ message }, { output }) => { | ||
const renamedOutput = message.as("output").to(output()); | ||
return renamedOutput; | ||
}).serialize() | ||
|
||
export default graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#! /usr/bin/env npx -y tsx | ||
|
||
import Core, { core } from "@google-labs/core-kit"; | ||
import graph from "./hello-world.js" | ||
import { BoardRunner, GraphDescriptor, asRuntimeKit, base, code } from "@google-labs/breadboard"; | ||
|
||
const concat = code<{string1: string, string2: string}>((inputs) => { | ||
const {string1, string2} = inputs | ||
|
||
const concatResult = string1.concat(string2) | ||
return {result: concatResult} | ||
}); | ||
|
||
// Invokes our Hello World board and returns the "Hello World" as the output | ||
const invocation = core.invoke({ | ||
$metadata: { title: "Invoke Hello World Board" }, | ||
$board: graph, | ||
message: "Hello World" | ||
}); | ||
|
||
const output = base.output(); | ||
// Takes the output from the Hello World Board and concatenates it with a string | ||
const {result} = concat({string1: invocation.output.isString(), string2: " from the wrapper!"}) | ||
|
||
// Returns concat result as board output | ||
result.to(output) | ||
|
||
const serialised = await output.serialize({ | ||
title: "Core Kit Invoke Example", | ||
}); | ||
|
||
const runner = await BoardRunner.fromGraphDescriptor(serialised as GraphDescriptor); | ||
for await (const stop of runner.run({kits: [asRuntimeKit(Core)] })) { | ||
if (stop.type === "output") { | ||
console.log(JSON.stringify(stop.outputs, null, 2)); | ||
} | ||
} |