substrate v120240418.0.12
꩜ Substrate TypeScript SDK
The Substrate TypeScript SDK is the recommended way to interact with the Substrate API from server-side TypeScript or JavaScript.
Documentation
If you're just getting started, head to guides.substrate.run.
For a detailed API reference covering the nodes available on Substrate, see substrate.run/nodes.
For an interactive reference, check out explore.substrate.run. You can call Substrate.visualize(...nodes...)
to generate an interactive visualization of any graph.
Installation
npm install substrate
Usage
import { Substrate, GenerateText, sb } from "substrate";
Initialize the Substrate client.
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
Generate a story using the GenerateText
node.
const story = new GenerateText({ prompt: "tell me a story" });
Summarize the output of the story
node using another GenerateText
node. Because story
has not yet been run, we use sb.interpolate
to work with its future output.
const summary = new GenerateText({
prompt: sb.interpolate`summarize this story in one sentence: ${story.future.text}`,
});
Run the graph chaining story
→ summary
. This is a simple example, but you can easily build arbitrarily complex branching workflows.
const response = await substrate.run(story, summary);
Get the output of the summary node by passing it to response.get
.
const summaryOut = response.get(summary);
console.log(summaryOut.text);
// Princess Lily, a kind-hearted young princess, discovers a book of spells and uses it to grant her family and kingdom happiness.
10 days ago
11 days ago
17 days ago
22 days ago
25 days ago
29 days ago
1 month ago
30 days ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
6 months ago
6 months ago
7 months ago
10 months ago
10 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
11 years ago
11 years ago
11 years ago