You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running a Node.js Express server that executes a GPTScript file (story.gpt) using @gptscript-ai/gptscript. However, when I make a request, I get the following error:
Error occurred during GPTScript execution: Error: prompt occurred when prompt was not allowed: Message: Please provide your OpenAI API key:
Fields: key
Sensitive: true
Despite setting process.env.GPTSCRIPT_API_KEY, GPTScript still asks for an OpenAI API key.
tools: sys.write, sys.read, sys.download, sys.find
tools: github.com/gptscript-ai/browser
args: url: Articles link
args: dir: directory to save the created files
1. Browse to the ${url} and read the page's contents.
2. Create a TL;DR text version for an Instagram reel or YouTube short. No emojis and no more than 100 words.
3. Split the created text into 3 parts and save the texts to "${dir}/story-${INDEX}.txt".
3️⃣ index.js (Relevant Code Snippet)
importexpressfrom"express";importuniqidfrom"uniqid";importfsfrom"fs";importcorsfrom"cors";import{GPTScript}from"@gptscript-ai/gptscript";constg=newGPTScript({key: process.env.GPTSCRIPT_API_KEY});constapp=express();app.use(cors());app.get("/create-story",async(req,res)=>{consturl=req.query.url;if(!url)returnres.status(400).json({error: "url is required"});constdir=`./stories/${uniqid()}`;fs.mkdirSync(dir,{recursive: true});constopts={input: `--url ${url} --dir ${dir}`,disableCache: true,};try{construn=awaitg.run("./story.gpt",opts);if(!run)returnres.status(500).json({error: "error running GPTScript"});constresult=awaitrun.text();if(!result)returnres.status(500).json({error: "no result"});returnres.json(result);}catch(e){console.error("Error running GPTScript:",e);returnres.status(500).json({error: "error occurred"});}});app.listen(8080,()=>console.log("Listening on port 8080"));
Error Output
Received request with URL: https://www.astronomy.com/picture-of-the-day/photo/hide-and-seek/
Generated directory path: ./stories/16ym8g0m8aalonh
Directory created successfully
Running GPTScript with options: {
input: '--url https://www.astronomy.com/picture-of-the-day/photo/hide-and-seek/ --dir ./stories/16ym8g0m8aalonh',
disableCache: true
}
Error occurred during GPTScript execution: Error: prompt occurred when prompt was not allowed:
Message: Please provide your OpenAI API key:
Fields: key
Sensitive: true
at IncomingMessage.<anonymous> (file:///D:/VsCode/webDev%202.0/Shortify/server/node_modules/@gptscript-ai/gptscript/dist/gptscript.js:482:28)
at IncomingMessage.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
What I've Tried:
Checked if the API key is set properly:
Logged process.env.GPTSCRIPT_API_KEY to check if it exists.
Description:
I am running a Node.js Express server that executes a GPTScript file (
story.gpt
) using@gptscript-ai/gptscript
. However, when I make a request, I get the following error:Despite setting
process.env.GPTSCRIPT_API_KEY
, GPTScript still asks for an OpenAI API key.Code & Setup
1️⃣ package.json
2️⃣ story.gpt
3️⃣ index.js (Relevant Code Snippet)
Error Output
What I've Tried:
Checked if the API key is set properly:
process.env.GPTSCRIPT_API_KEY
to check if it exists..env
file containsGPTSCRIPT_API_KEY=your_api_key_here
..env
.Tried passing the key directly in code:
.env
instead.Checked if
dotenv
is needed:dotenv
and required it at the top:Checked execution environment:
console.log(process.env.GPTSCRIPT_API_KEY)
before initializingGPTScript
returns undefined.Environment Details:
22.14.4
0.9.5
Expected Behavior:
GPTScript should recognize
process.env.GPTSCRIPT_API_KEY
and executestory.gpt
without prompting for an API key.Actual Behavior:
Despite setting the API key in
.env
, GPTScript still prompts for it, causing execution to fail.The text was updated successfully, but these errors were encountered: