-
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.
* Integrate `Box` and `If` nodes from OpenAPI spec (updated internal field to avoid collision) * Add `Box` and `If` examples * Bump version * Fix formatting
- Loading branch information
1 parent
34b80f1
commit 71df9b8
Showing
15 changed files
with
1,048 additions
and
426 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
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,38 @@ | ||
#!/usr/bin/env -S npx ts-node --transpileOnly | ||
|
||
import { Substrate, ComputeText, Box, sb } from "substrate"; | ||
|
||
async function main() { | ||
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"]; | ||
|
||
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY }); | ||
|
||
const languages = ["swedish", "ukranian", "thai", "turkish"] as const; | ||
|
||
const texts: Record<string, ComputeText> = languages.reduce( | ||
(nodes, language) => { | ||
return { | ||
...nodes, | ||
[language]: new ComputeText({ | ||
prompt: sb.interpolate`count to 10 in ${language}`, | ||
max_tokens: 50, | ||
}), | ||
}; | ||
}, | ||
{}, | ||
); | ||
|
||
const box = new Box({ | ||
value: languages.reduce((obj, language) => { | ||
return { | ||
...obj, | ||
[language]: texts[language]!.future.text, | ||
}; | ||
}, {}), | ||
}); | ||
|
||
const res = await substrate.run(box); | ||
|
||
console.log({ box: res.get(box) }); | ||
} | ||
main(); |
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,63 @@ | ||
#!/usr/bin/env -S npx ts-node --transpileOnly | ||
|
||
import { Substrate, ComputeJSON, Box, If, sb } from "substrate"; | ||
|
||
async function main() { | ||
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"]; | ||
|
||
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY }); | ||
|
||
const planets = ["Jupiter", "Mars"]; | ||
|
||
const sizes = planets.map((planet) => { | ||
return new ComputeJSON({ | ||
prompt: sb.interpolate`How big is ${planet}?`, | ||
json_schema: { | ||
type: "object", | ||
properties: { | ||
planetName: { | ||
type: "string", | ||
description: "The name of the planet", | ||
enum: planets, | ||
}, | ||
radius: { | ||
type: "string", | ||
description: "The radius of the planet in kilometers", | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
const [jupiter, mars] = sizes as [ComputeJSON, ComputeJSON]; | ||
const radius = (p: ComputeJSON) => | ||
p.future.json_object.get("radius") as unknown as number; | ||
|
||
const comparison = new ComputeJSON({ | ||
prompt: sb.interpolate`Is ${radius(jupiter)} > ${radius(mars)}?`, | ||
json_schema: { | ||
type: "object", | ||
properties: { | ||
isGreaterThan: { | ||
type: "boolean", | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const result = new If({ | ||
condition: comparison.future.json_object.get("isGreaterThan") as any, | ||
value_if_true: jupiter.future.json_object, | ||
value_if_false: mars.future.json_object, | ||
}); | ||
|
||
const output = new Box({ | ||
value: sb.interpolate`The bigger planet is ${result.future.result.get( | ||
"planetName", | ||
)}!`, | ||
}); | ||
|
||
const res = await substrate.run(output); | ||
console.log(res.get(output)); | ||
} | ||
main(); |
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
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,22 @@ | ||
#!/usr/bin/env -S npx ts-node --transpileOnly | ||
|
||
import { Substrate, Box, sb } from "substrate"; | ||
|
||
async function main() { | ||
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"]; | ||
|
||
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY }); | ||
|
||
const node = new Box({ | ||
value: { | ||
a: "b", | ||
c: { | ||
d: [1, 2, 3], | ||
}, | ||
}, | ||
}); | ||
const res = await substrate.run(node); | ||
console.log(res.apiResponse.status); | ||
console.log(JSON.stringify(res.json)); | ||
} | ||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
20240617.20240620 | ||
20240617.20240621 |
Oops, something went wrong.