Skip to content

Commit 7b5fb3a

Browse files
committed
refactor: update node example to use new module
The new module had breaking changes to accept Tool types. These updates modify the codebase to make use of the updates. This now makes use of the packaging in gptscript. Signed-off-by: Bill Maxwell <[email protected]>
1 parent eb5e264 commit 7b5fb3a

File tree

7 files changed

+21
-100
lines changed

7 files changed

+21
-100
lines changed

examples/nodejs-imagegen/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ git clone https://github.com/gptscript-ai/gptscript.git
2121

2222
1. Navigate to the 'examples/nodejs-imagegen' directory and install dependencies.
2323

24-
Python:
25-
26-
*note: You can use a virtual environment to install the python dependencies, just make sure it is activated before running the server.*
27-
28-
```bash
29-
pip install -r requirements.txt
30-
```
31-
32-
this will install the python dependencies for the image generation tool.
33-
3424
Node:
3525

3626
```bash

examples/nodejs-imagegen/cli.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

examples/nodejs-imagegen/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs-imagegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14-
"@gptscript-ai/gptscript": "^0.1.2",
14+
"@gptscript-ai/gptscript": "^0.2.0",
1515
"express": "^4.18.3",
1616
"express-ws": "^5.0.2",
1717
"nodemon": "^3.1.0",

examples/nodejs-imagegen/requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/nodejs-imagegen/server.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ app.get('/', (req, res) => {
3232
app.post('/generate-logo', async (req, res) => {
3333
const description = req.body.description;
3434
const artists = getArtistsData();
35-
const prompt = `
36-
tools: ./tool.gpt
35+
const instructions = `
3736
For each of the three amazing and capable artists described here
3837
${JSON.stringify(artists)}
3938
make sure to include the artistName field in the response.
@@ -51,8 +50,14 @@ app.post('/generate-logo', async (req, res) => {
5150
}]
5251
}
5352
`;
53+
const tool = new gptscript.Tool({
54+
tools: ['github.com/gptscript-ai/image-generation'],
55+
jsonResponse: true,
56+
instructions: instructions,
57+
})
58+
5459
try {
55-
const output = await gptscript.exec(prompt);
60+
const output = await gptscript.exec(tool);
5661
const cleanedResp = output.trim().replace(/^```json.*/, '').replace(/```/g, '');
5762
res.json(JSON.parse(cleanedResp));
5863
} catch (error) {
@@ -63,9 +68,7 @@ app.post('/generate-logo', async (req, res) => {
6368

6469
// Route to request new artists
6570
app.post('/new-artists', async (req, res) => {
66-
const prompt = `
67-
tools: sys.write
68-
71+
const instructions = `
6972
Create three short graphic artist descriptions and their muses.
7073
These should be descriptive and explain their point of view.
7174
Also come up with a made up name, they each should be from different
@@ -80,8 +83,14 @@ the response format should be json and MUST NOT have other content or formatting
8083
}]
8184
}
8285
`;
86+
const tool = new gptscript.Tool({
87+
tools: ['sys.write'],
88+
jsonResponse: true,
89+
instructions: instructions,
90+
});
91+
8392
try {
84-
const output = await gptscript.exec(prompt);
93+
const output = await gptscript.exec(tool);
8594
const cleanedResp = output.trim().replace(/^```json.*/, '').replace(/```/g, '');
8695
newArtistsData = JSON.parse(cleanedResp);
8796
res.json(newArtistsData);

examples/nodejs-imagegen/tool.gpt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)