Twilio to OpenAI

Hey y’all, I’m new to this and a very recreational Dev so please bear with me!

BIG PICTURE FIRST: I want to use OpenAI to use my website data to answer people’s text questions.

I’m trying to link Twilio SMS to OpenAi so inbound texts are responded to based on content from my website. I have it working GREAT in the OpenAI sandbox. I copy over a few blog posts of text, then a few Q: and A: examples, and whater question I type seems to come out correctly. It’s MAGIC!

Then, to get it to Twilio I’m generating the code in OpenAI, opening the OpenAi module in Pipedream and coping this code:

const { Configuration, OpenAIApi } = require(“openai”);

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion(“text-davinci-002”, {
prompt: “In 2020, Andrew was elected to serve Brandon and East Hillsborough County in the Florida House of Representatives. As a Veteran and small business owner, Andrew has worked to bridge the divide in our community and Nation by focusing on results for our community instead of scoring partisan points.”, steps.trigger.event.Body
temperature: 0.7,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,

I bolded the steps.trigger.event.Body because I figure it needs to be there in order to pass the text message question I’m receiving from Twilio over to OpenAI, but I may be doing this part completely wrong

Then this happens…

Unexpected token (8:23)
SyntaxError: Unexpected token (8:23)
at _class.pp$4.raise (/var/task/node_modules/acorn/dist/acorn.js:2927:15)
at _class.pp.unexpected (/var/task/node_modules/acorn/dist/acorn.js:698:10)
at _class.pp.semicolon (/var/task/node_modules/acorn/dist/acorn.js:675:66)
at _class.pp$1.parseVarStatement (/var/task/node_modules/acorn/dist/acorn.js:1102:10)
at _class.pp$1.parseStatement (/var/task/node_modules/acorn/dist/acorn.js:851:19)
at _class.parseStatement (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:65:118)
at _class.pp$1.parseTopLevel (/var/task/node_modules/acorn/dist/acorn.js:755:23)
at _class.parse (/var/task/node_modules/acorn/dist/acorn.js:555:17)
at Function.parse (/var/task/node_modules/acorn/dist/acorn.js:578:37)
at Object.parse (/var/task/node_modules/acorn-node/index.js:30:28)

Ok internet, how dumb am I being? Can y’all help me out?

Hi @AndrewLearned

First off, welcome to the Pipedream community. Happy to have you!

So happy to see that you’re getting started so quickly building with Pipedream.

The error message you shared (Unexpected token) indicates that you have a syntax error in your code - which is just a fancy way of saying that your code isn’t valid. A comma could be missing, or a colon, or a missing open or close parentheses somewhere.

I recommend getting familiar with the Javascript basics so these errors become easier to work with: