Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update API Schema, Codegen, Tests, and Examples #87

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions examples/basic.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/usr/bin/env node

const { Substrate, GenerateText } = require("substrate");
const { Substrate, ComputeText } = require("substrate");

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

const substrate = new Substrate({
apiKey: SUBSTRATE_API_KEY,
baseUrl: "https://api-staging.substrate.run",
});
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateText({
const a = new ComputeText({
prompt: "ask me a short trivia question in one sentence",
});
const b = new GenerateText({ prompt: a.future.text });
const b = new ComputeText({ prompt: a.future.text });

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

Expand Down
11 changes: 4 additions & 7 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/usr/bin/env node

import { Substrate, GenerateText } from "substrate";
import { Substrate, ComputeText } from "substrate";

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

const substrate = new Substrate({
apiKey: SUBSTRATE_API_KEY,
baseUrl: "https://api-staging.substrate.run",
});
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateText({
const a = new ComputeText({
prompt: "ask me a short trivia question in one sentence",
});
const b = new GenerateText({ prompt: a.future.text });
const b = new ComputeText({ prompt: a.future.text });

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

Expand Down
6 changes: 3 additions & 3 deletions examples/basic.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateText, sb } from "substrate";
import { Substrate, ComputeText, sb } from "substrate";

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

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

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

Expand Down
9 changes: 3 additions & 6 deletions examples/image-generation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateText, GenerateImage } from "substrate";
import { Substrate, ComputeText, GenerateImage } from "substrate";

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

const substrate = new Substrate({
apiKey: SUBSTRATE_API_KEY,
baseUrl: "https://api-staging.substrate.run",
});
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const scene = new GenerateText({
const scene = new ComputeText({
prompt:
"describe a highly detailed forest scene with something suprising happening in one sentence, be concise, like hemmingway would write it.",
});
Expand Down
10 changes: 5 additions & 5 deletions examples/implicit-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateText } from "substrate";
import { Substrate, ComputeText } from "substrate";

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

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

const a = new GenerateText(
const a = new ComputeText(
{ prompt: "tell me about windmills", max_tokens: 10 },
{ id: "a" },
);
const b = new GenerateText(
const b = new ComputeText(
{ prompt: a.future.text, max_tokens: 10 },
{ id: "b" },
);
const c = new GenerateText(
const c = new ComputeText(
{ prompt: b.future.text, max_tokens: 10 },
{ id: "c" },
);
const d = new GenerateText(
const d = new ComputeText(
{ prompt: c.future.text, max_tokens: 10 },
{ id: "d" },
);
Expand Down
9 changes: 3 additions & 6 deletions examples/jina.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateText, JinaV2 } from "substrate";
import { Substrate, ComputeText, JinaV2 } from "substrate";

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

const substrate = new Substrate({
apiKey: SUBSTRATE_API_KEY,
baseUrl: "https://api-staging.substrate.run",
});
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateText({ prompt: "hi" });
const a = new ComputeText({ prompt: "hi" });

const input: JinaV2.Input = {
items: [
Expand Down
11 changes: 4 additions & 7 deletions examples/jq.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateText, sb, GenerateJSON } from "substrate";
import { Substrate, ComputeText, sb, ComputeJSON } from "substrate";

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

const substrate = new Substrate({
apiKey: SUBSTRATE_API_KEY,
baseUrl: "https://api.substrate.run",
});
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateJSON({
const a = new ComputeJSON({
prompt: "Give me an African capital city and its approximate population.",
json_schema: {
type: "object",
Expand All @@ -23,7 +20,7 @@ async function main() {
},
});

const b = new GenerateText({
const b = new ComputeText({
prompt: sb.concat(
"give me the leader of the country: ",
sb.jq<"string">(a.future.json_object, ".country"),
Expand Down
6 changes: 3 additions & 3 deletions examples/json.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env -S npx ts-node --transpileOnly

import { Substrate, GenerateJSON, GenerateText, sb } from "substrate";
import { Substrate, ComputeJSON, ComputeText, sb } from "substrate";

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

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

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

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

Expand Down
Loading
Loading