Skip to content

Commit 21772e2

Browse files
committed
chore: prep for v0.6.1 release
1 parent e4d59f3 commit 21772e2

11 files changed

+191
-3
lines changed

examples/example-file-stream.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
const testGptPath = `/Users/thedadams/code/gptscript-examples/envvar.gpt`;
5+
const opts = {
6+
disableCache: true
7+
}
8+
9+
try {
10+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL, process.env.GPTSCRIPT_BIN)
11+
const run = await client.run(testGptPath, opts);
12+
run.on(gptscript.RunEventType.Event, data => {
13+
console.log(`event: ${JSON.stringify(data)}`)
14+
});
15+
16+
console.log(await run.text())
17+
} catch (e) {
18+
console.log(e)
19+
console.error(JSON.stringify(e));
20+
}
21+
})();

examples/example-models.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
const response = await client.listModels();
7+
console.log(response);
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
})();

examples/example-parse-file.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
const response = await client.parse("/Users/thedadams/code/gptscript-examples/envvar.gpt");
7+
console.log(JSON.stringify(response));
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
})();

examples/example-parse.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
const response = await client.parseTool("hello world");
7+
console.log(JSON.stringify(response));
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
})();

examples/example-tool-chat-stream.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
import * as readline from "readline";
3+
import {stdin as input, stdout as output} from 'node:process';
4+
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
7+
const rl = readline.createInterface({input, output});
8+
9+
const t = {
10+
chat: true,
11+
tools: ["sys.chat.finish"],
12+
instructions: "Say hello and start a chat session.",
13+
};
14+
15+
let r = client.evaluate(t, {
16+
disableCache: true,
17+
});
18+
19+
(async () => {
20+
r.on(gptscript.RunEventType.Event, (data) => {
21+
console.log(JSON.stringify(data))
22+
})
23+
console.log(await r.text());
24+
const recursiveAsyncReadLine = function () {
25+
rl.question(`>> `, async function (answer) {
26+
if (answer === "") //we need some base case, for recursion
27+
return rl.close(); //closing RL and returning from function.
28+
try {
29+
r = r.nextChat(answer);
30+
} catch (e) {
31+
console.error(e);
32+
}
33+
console.log(await r.text());
34+
console.log(r.state);
35+
if (r.state === gptscript.RunState.Finished) {
36+
console.log("The conversation is finished. Goodbye!");
37+
return rl.close();
38+
}
39+
recursiveAsyncReadLine(); //Calling this function again to ask new question
40+
});
41+
};
42+
43+
recursiveAsyncReadLine();
44+
})()
45+
46+
rl.on("close", function () {
47+
console.log("\nBYE BYE !!!");
48+
process.exit(0);
49+
});

examples/example-tool-stream.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
7+
const t = {
8+
instructions: "who was the president of the united states in 1928?"
9+
}
10+
11+
const r = client.evaluate(t, {
12+
disableCache: true
13+
})
14+
15+
r.on(gptscript.RunEventType.Event, data => {
16+
console.log(`event: ${JSON.stringify(data)}`);
17+
});
18+
19+
console.log(await r.text())
20+
} catch (e) {
21+
console.error(e)
22+
}
23+
})()

examples/example-tools.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
const response = await client.listTools();
7+
console.log(response)
8+
} catch (error) {
9+
console.error(error)
10+
}
11+
})()

examples/example-version.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as gptscript from "../dist/gptscript.js";
2+
3+
(async () => {
4+
try {
5+
const client = new gptscript.Client(process.env.GPTSCRIPT_URL)
6+
const response = await client.version();
7+
console.log(response);
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
})();

examples/sangeetha.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as gptscript from '../dist/gptscript.js';
2+
3+
const opts = {
4+
disableCache: true
5+
};
6+
7+
const client = new gptscript.Client()
8+
const t = {
9+
chat: true,
10+
tools: ["sys.chat.finish", "github.com/gptscript-ai/search/duckduckgo", "sys.http.html2text?"],
11+
instructions: "You are a chat bot. Don't finish the conversation until I say 'bye'.Search using duckduckgo. If the search tool fails to return any information stop execution of the script with message 'Sorry! Search dis not retrun any results' .Feel free to get the contents of the returned URLs in order to get more information. Provide as much detail as you can.Search for who won superbowl 2024"
12+
};
13+
14+
streamExecFileWithEvents()
15+
16+
async function streamExecFileWithEvents() {
17+
let i = 0;
18+
const chats = ["where was this game played?", "when and where was this game played last year?", "who was the winner of this game", "bye"];
19+
let run = client.evaluate(t, opts);
20+
try {
21+
// Wait for the initial run to complete.
22+
console.log(await run.text())
23+
24+
while (run.state === gptscript.RunState.Continue) {
25+
// ...Get the next input from the user somehow...
26+
27+
run = run.nextChat(chats[i++])
28+
29+
// Get the output from gptscript
30+
const output = await run.text()
31+
console.log(output)
32+
}
33+
} catch (e) {
34+
console.log("ERROR")
35+
console.error(e);
36+
}
37+
38+
// The state here should either be RunState.Finished (on success) or RunState.Error (on error).
39+
console.log(run.state)
40+
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gptscript-ai/gptscript",
3-
"version": "v0.6.0",
3+
"version": "v0.6.1",
44
"description": "Run gptscript in node.js",
55
"source": "src/gptscript.ts",
66
"main": "dist/gptscript.js",

0 commit comments

Comments
 (0)