Skip to content

Commit 9466a48

Browse files
Update API Schema, Codegen, Tests, and Examples (#87)
* Update schema, tests * Update basic examples, `GenerateText` -> `ComputeText` * Update node name in vector-stores example * Remove run-python example (not available in TS-SDK anymore) * Update node names in kitchen-sink example * Update nodes in streaming examples * Update examples, ensure they are all running
1 parent 8a1ac87 commit 9466a48

24 files changed

+735
-1008
lines changed

examples/basic.cjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#!/usr/bin/env node
22

3-
const { Substrate, GenerateText } = require("substrate");
3+
const { Substrate, ComputeText } = require("substrate");
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

8-
const substrate = new Substrate({
9-
apiKey: SUBSTRATE_API_KEY,
10-
baseUrl: "https://api-staging.substrate.run",
11-
});
8+
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
129

13-
const a = new GenerateText({
10+
const a = new ComputeText({
1411
prompt: "ask me a short trivia question in one sentence",
1512
});
16-
const b = new GenerateText({ prompt: a.future.text });
13+
const b = new ComputeText({ prompt: a.future.text });
1714

1815
const res = await substrate.run(a, b);
1916

examples/basic.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#!/usr/bin/env node
22

3-
import { Substrate, GenerateText } from "substrate";
3+
import { Substrate, ComputeText } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

8-
const substrate = new Substrate({
9-
apiKey: SUBSTRATE_API_KEY,
10-
baseUrl: "https://api-staging.substrate.run",
11-
});
8+
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
129

13-
const a = new GenerateText({
10+
const a = new ComputeText({
1411
prompt: "ask me a short trivia question in one sentence",
1512
});
16-
const b = new GenerateText({ prompt: a.future.text });
13+
const b = new ComputeText({ prompt: a.future.text });
1714

1815
const res = await substrate.run(a, b);
1916

examples/basic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateText, sb } from "substrate";
3+
import { Substrate, ComputeText, sb } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

88
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
99

10-
const story = new GenerateText({ prompt: "tell me a story" });
11-
const summary = new GenerateText({
10+
const story = new ComputeText({ prompt: "tell me a story" });
11+
const summary = new ComputeText({
1212
prompt: sb.interpolate`summarize this story in one sentence: ${story.future.text}`,
1313
});
1414

examples/image-generation.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateText, GenerateImage } from "substrate";
3+
import { Substrate, ComputeText, GenerateImage } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

8-
const substrate = new Substrate({
9-
apiKey: SUBSTRATE_API_KEY,
10-
baseUrl: "https://api-staging.substrate.run",
11-
});
8+
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
129

13-
const scene = new GenerateText({
10+
const scene = new ComputeText({
1411
prompt:
1512
"describe a highly detailed forest scene with something suprising happening in one sentence, be concise, like hemmingway would write it.",
1613
});

examples/implicit-nodes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateText } from "substrate";
3+
import { Substrate, ComputeText } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

88
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
99

10-
const a = new GenerateText(
10+
const a = new ComputeText(
1111
{ prompt: "tell me about windmills", max_tokens: 10 },
1212
{ id: "a" },
1313
);
14-
const b = new GenerateText(
14+
const b = new ComputeText(
1515
{ prompt: a.future.text, max_tokens: 10 },
1616
{ id: "b" },
1717
);
18-
const c = new GenerateText(
18+
const c = new ComputeText(
1919
{ prompt: b.future.text, max_tokens: 10 },
2020
{ id: "c" },
2121
);
22-
const d = new GenerateText(
22+
const d = new ComputeText(
2323
{ prompt: c.future.text, max_tokens: 10 },
2424
{ id: "d" },
2525
);

examples/jina.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateText, JinaV2 } from "substrate";
3+
import { Substrate, ComputeText, JinaV2 } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

8-
const substrate = new Substrate({
9-
apiKey: SUBSTRATE_API_KEY,
10-
baseUrl: "https://api-staging.substrate.run",
11-
});
8+
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
129

13-
const a = new GenerateText({ prompt: "hi" });
10+
const a = new ComputeText({ prompt: "hi" });
1411

1512
const input: JinaV2.Input = {
1613
items: [

examples/jq.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateText, sb, GenerateJSON } from "substrate";
3+
import { Substrate, ComputeText, sb, ComputeJSON } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

8-
const substrate = new Substrate({
9-
apiKey: SUBSTRATE_API_KEY,
10-
baseUrl: "https://api.substrate.run",
11-
});
8+
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
129

13-
const a = new GenerateJSON({
10+
const a = new ComputeJSON({
1411
prompt: "Give me an African capital city and its approximate population.",
1512
json_schema: {
1613
type: "object",
@@ -23,7 +20,7 @@ async function main() {
2320
},
2421
});
2522

26-
const b = new GenerateText({
23+
const b = new ComputeText({
2724
prompt: sb.concat(
2825
"give me the leader of the country: ",
2926
sb.jq<"string">(a.future.json_object, ".country"),

examples/json.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, GenerateJSON, GenerateText, sb } from "substrate";
3+
import { Substrate, ComputeJSON, ComputeText, sb } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
77

88
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
99

10-
const author = new GenerateJSON({
10+
const author = new ComputeJSON({
1111
prompt: "Who wrote Don Quixote?",
1212
json_schema: {
1313
type: "object",
@@ -29,7 +29,7 @@ async function main() {
2929
const name = author.future.json_object.get("name");
3030
const bio = author.future.json_object.get("bio");
3131

32-
const report = new GenerateText({
32+
const report = new ComputeText({
3333
prompt: sb.interpolate`Write a short summary about ${name} and make sure to use the following bio: ${bio}`,
3434
});
3535

0 commit comments

Comments
 (0)