Skip to content

feat: add client for easier configuration #30

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

Merged
merged 1 commit into from
May 8, 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
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ npm exec -c "gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'

you will see "Hello, World!" in the output of the command.

## Client

There are currently a couple "global" options, and the client helps to manage those. A client without any options is
likely what you want. However, here are the current global options:

- `gptscriptURL`: The URL (including `http(s)://) of an "SDK server" to use instead of the fork/exec model.
- `gptscriptBin`: The path to a `gptscript` binary to use instead of the bundled one.

## Options

These are optional options that can be passed to the various `exec` functions.
Expand All @@ -52,7 +60,8 @@ Lists all the available built-in tools.
const gptscript = require('@gptscript-ai/gptscript');

async function listTools() {
const tools = await gptscript.listTools();
const client = new gptscript.Client();
const tools = await client.listTools();
console.log(tools);
}
```
Expand All @@ -69,7 +78,8 @@ const gptscript = require('@gptscript-ai/gptscript');
async function listModels() {
let models = [];
try {
models = await gptscript.listModels();
const client = new gptscript.Client();
models = await client.listModels();
} catch (error) {
console.error(error);
}
Expand All @@ -87,7 +97,8 @@ const gptscript = require('@gptscript-ai/gptscript');

async function version() {
try {
console.log(await gptscript.version());
const client = new gptscript.Client();
console.log(await client.version());
} catch (error) {
console.error(error);
}
Expand All @@ -107,7 +118,8 @@ const t = {
};

try {
const run = gptscript.evaluate(t);
const client = new gptscript.Client();
const run = client.evaluate(t);
console.log(await run.text());
} catch (error) {
console.error(error);
Expand All @@ -128,7 +140,8 @@ const opts = {

async function execFile() {
try {
const run = gptscript.run('./hello.gpt', opts);
const client = new gptscript.Client();
const run = client.run('./hello.gpt', opts);
console.log(await run.text());
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -165,10 +178,11 @@ const opts = {

async function streamExecFileWithEvents() {
try {
const run = gptscript.run('./test.gpt', opts);
const client = new gptscript.Client();
const run = client.run('./test.gpt', opts);

run.on(gptscript.RunEventType.Event, data => {
console.log(`event: ${data}`);
console.log(`event: ${JSON.stringify(data)}`);
});

await run.text();
Expand Down Expand Up @@ -203,7 +217,8 @@ const t = {
};

async function streamExecFileWithEvents() {
let run = gptscript.evaluate(t, opts);
const client = new gptscript.Client();
let run = client.evaluate(t, opts);
try {
// Wait for the initial run to complete.
await run.text();
Expand Down
30 changes: 15 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import commonjs from 'rollup-plugin-commonjs';
import typescript from '@rollup/plugin-typescript';

export default [{
input: 'dist/gptscript.js',
output: {
name: "GPTScript",
file: "dist/gptscript.browser.js",
format: 'iife',
sourcemap: true,
},
external: [
'net','http','path','child_process','sse.js',
],
plugins: [
typescript(),
commonjs(),
resolve(),
],
input: 'dist/gptscript.js',
output: {
name: "GPTScript",
file: "dist/gptscript.browser.js",
format: 'iife',
sourcemap: true,
},
external: [
'net', 'http', 'path', 'child_process', 'sse.js',
],
plugins: [
typescript(),
commonjs(),
resolve({preferBuiltins: true}),
],
}];
Loading