#'Cannot read properties of undefined' after updating to GPT Turbo

7 messages · Page 1 of 1 (latest)

frozen kelp
#

I get the following error:

const bot = response.data.choices[0].text.trim();
^
TypeError: Cannot read properties of undefined (reading 'trim')

I suppose my code is outdated as it was based on req.session.prompt which has since been remove and its functionality implemented into the new response function.

Any advice on how to fix this would be great.

unkempt escarp
#

Try..message instead of .text

bright nova
#

when you get an undefined value it's usually because you're trying to access or use a variable before it's populated.

In this case it looks like it's trying to set the bot value to be some value from the local data store but it's not there.

#

I'm guessing you really meant to trim something from some response and somehow you're accidentally had it looking for the trim value in the data store.

calm warren
stoic slate
#

Hi. I assume you're trying to trim the result of response.data.choises[0].message. Try adding .content after .message and then do trim so it should look like this response.data.choices[0].message.content.trim().

To explain what the issue is, response.data.choises[0].message returns a data object block instead of a string, therefore you were unable to trim or modify it with any string modifier. If you try console.log(response.data.choises[0].message) it will return with something like this:

{
  role: 'assistant',
  content: ...
}

Not just the content itself.