Closed lenniecottrell closed 1 year ago
hey! let me try this and get back to you
This code works
const dotenv = require("dotenv");
dotenv.config();
const promptable = require("promptable");
const apiKey = process.env.OPENAI_API_KEY || "missing";
const provider = new promptable.OpenAI(apiKey);
const text = "Write a haiku about sunflowers";
const getResponse = async (prompt) => {
try {
const response = await provider.generate(prompt);
console.log(response);
} catch (error) {
console.error(error);
}
};
getResponse(text);
Assuming
node index.js
outputs something like this
colin@MacBook-Pro test % node index.js
Golden petals sway
In a summer's gentle breeze
A field of sunflowers
Closing for now, feel free to open it again if you think there is something wrong!
Another example that works
dotenv.config();
const promptable = require("promptable");
const apiKey = process.env.OPENAI_API_KEY || "missing";
const provider = new promptable.OpenAI(apiKey);
const getResponse = async () => {
const writePoemPrompt = new promptable.Prompt(
"Write a poem about {{topic}}:".trim(),
["topic"]
);
const text = writePoemPrompt.format({
topic: "hi",
});
const response = await provider.generate(text);
console.log(response);
};
getResponse();
Thanks for the response, your sample code worked for me in a vanilla JS file - I have some typescript stuff to work out it seems...
I'm pretty sure this code is correct syntactically, but the promise never resolves and the console prints
Promise { <pending> }
I've also tried to change the bottom to
I've also tried the exact example from the Quickstart and it still just prints
Promise { <pending> }