Skip to content

refactor: update node example to use new module #185

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
Mar 26, 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
10 changes: 0 additions & 10 deletions examples/nodejs-imagegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ git clone https://github.com/gptscript-ai/gptscript.git

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

Python:

*note: You can use a virtual environment to install the python dependencies, just make sure it is activated before running the server.*

```bash
pip install -r requirements.txt
```

this will install the python dependencies for the image generation tool.

Node:

```bash
Expand Down
67 changes: 0 additions & 67 deletions examples/nodejs-imagegen/cli.py

This file was deleted.

8 changes: 4 additions & 4 deletions examples/nodejs-imagegen/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs-imagegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@gptscript-ai/gptscript": "^0.1.2",
"@gptscript-ai/gptscript": "^0.2.0",
"express": "^4.18.3",
"express-ws": "^5.0.2",
"nodemon": "^3.1.0",
Expand Down
3 changes: 0 additions & 3 deletions examples/nodejs-imagegen/requirements.txt

This file was deleted.

23 changes: 16 additions & 7 deletions examples/nodejs-imagegen/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ app.get('/', (req, res) => {
app.post('/generate-logo', async (req, res) => {
const description = req.body.description;
const artists = getArtistsData();
const prompt = `
tools: ./tool.gpt
const instructions = `
For each of the three amazing and capable artists described here
${JSON.stringify(artists)}
make sure to include the artistName field in the response.
Expand All @@ -51,8 +50,14 @@ app.post('/generate-logo', async (req, res) => {
}]
}
`;
const tool = new gptscript.Tool({
tools: ['github.com/gptscript-ai/image-generation'],
jsonResponse: true,
instructions: instructions,
})

try {
const output = await gptscript.exec(prompt);
const output = await gptscript.exec(tool);
const cleanedResp = output.trim().replace(/^```json.*/, '').replace(/```/g, '');
res.json(JSON.parse(cleanedResp));
} catch (error) {
Expand All @@ -63,9 +68,7 @@ app.post('/generate-logo', async (req, res) => {

// Route to request new artists
app.post('/new-artists', async (req, res) => {
const prompt = `
tools: sys.write

const instructions = `
Create three short graphic artist descriptions and their muses.
These should be descriptive and explain their point of view.
Also come up with a made up name, they each should be from different
Expand All @@ -80,8 +83,14 @@ the response format should be json and MUST NOT have other content or formatting
}]
}
`;
const tool = new gptscript.Tool({
tools: ['sys.write'],
jsonResponse: true,
instructions: instructions,
});

try {
const output = await gptscript.exec(prompt);
const output = await gptscript.exec(tool);
const cleanedResp = output.trim().replace(/^```json.*/, '').replace(/```/g, '');
newArtistsData = JSON.parse(cleanedResp);
res.json(newArtistsData);
Expand Down
8 changes: 0 additions & 8 deletions examples/nodejs-imagegen/tool.gpt

This file was deleted.