substarte 120240617.1.9

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Substrate
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Substrate TypeScript SDK
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/substrate.svg)](https://npmjs.org/package/substrate)
4
+
5
+ Substrate is a **powerful SDK** for building with AI, with [batteries included](https://substrate.run/nodes): language models, image generation, built-in vector storage, sandboxed code execution, and more. To use Substrate, you simply connect tasks, and then run the workflow. With this simple approach, we can create AI systems (from RAG, to agents, to multi-modal generative experiences) by simply describing the computation, with **zero additional abstractions**.
6
+
7
+ Substrate is also a **workflow execution** and **inference** engine, optimized for running compound AI workloads. Wiring together multiple inference APIs is inherently slow – whether you do it yourself, or use a framework like LangChain. Substrate lets you ditch the framework, write less code, and run compound AI fast.
8
+
9
+ ## Documentation
10
+
11
+ If you're just getting started, head to [docs.substrate.run](https://docs.substrate.run/).
12
+
13
+ For a detailed API reference covering the nodes available on Substrate, see [substrate.run/nodes](https://www.substrate.run/nodes).
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ npm install substrate
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { Substrate, ComputeText, sb } from "substrate";
25
+ ```
26
+
27
+ Initialize the Substrate client.
28
+
29
+ ```typescript
30
+ const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
31
+ ```
32
+
33
+ Generate a story using the [`ComputeText`](https://www.substrate.run/nodes#ComputeText) node.
34
+
35
+ ```typescript
36
+ const story = new ComputeText({ prompt: "tell me a story" });
37
+ ```
38
+
39
+ Summarize the output of the `story` node using another `ComputeText` node. Because `story` has not yet been run, we use `sb.interpolate` to work with its future output.
40
+
41
+ ```typescript
42
+ const summary = new ComputeText({
43
+ prompt: sb.interpolate`summarize this story in one sentence: ${story.future.text}`,
44
+ });
45
+ ```
46
+
47
+ Run the graph chaining `story` → `summary` by passing the terminal node to `substrate.run`.
48
+
49
+ ```typescript
50
+ const response = await substrate.run(summary);
51
+ ```
52
+
53
+ Get the output of the summary node by passing it to `response.get`.
54
+
55
+ ```typescript
56
+ const summaryOut = response.get(summary);
57
+ console.log(summaryOut.text);
58
+ // Princess Lily, a kind-hearted young princess, discovers a book of spells and uses it to grant her family and kingdom happiness.
59
+ ```
60
+
61
+ ## Examples
62
+
63
+ We're always creating new JS examples on [val.town](https://www.val.town/u/substrate/folders/Examples?folderId=61e21628-4209-11ef-bf47-de64eea55b61).
64
+
65
+ Many examples are also included in the `examples` directory.