#"Undefined" Chat completion
44 messages · Page 1 of 1 (latest)
the text passed to openai is in spanish, but that shoudnt make any difference, right?
It's choices[0].content for chat completion 🙂
How does the gptResponse object look like? Have you tried printing it your console?
Yes, its the standart response with all of the parameters correct as shown in the docs but the answer is just “Undefined”
I also checked my api key, org identificator and everything of that sort
Are you sure you are parsing the response correctly in code? Cuz i dont have a "data" object in my responses.
My gptResponse.choices[0].content
VS your gptResponse.data.choices[0].text
Example response from their site
"id":"chatcmpl-abc123",
"object":"chat.completion",
"created":1677858242,
"model":"gpt-3.5-turbo-0301",
"usage":{
"prompt_tokens":13,
"completion_tokens":7,
"total_tokens":20
},
"choices":[
{
"message":{
"role":"assistant",
"content":"\n\nThis is a test!"
},
"finish_reason":"stop",
"index":0
}
]
}
Oh, didn’t even noticed that, thank you, i cant try it right now, but ill update you as soon as possible, however, it looks as if this was the error
As rocketman said, i changed it to end in .content, however, i forgot to delete the .data
cool 🙂 happy to've been of help 😄
its an easy thing to make a mistake in to be fair. most async / fetch / api calls in JS e.g. you have to get the data attribute first
hey, just took a look, and it gave me this error: TypeError: Cannot read properties of undefined (reading '0'), on line 40, the one which was just modified, ill be taking a look in the meanwhile as i just tested it 5min ago, sorry to ask for help, i know the support is quite crowded, but its the first time i try integrating openai into my code and so im still getting along with the docs.
nps
whats on line 40 ?
cuz its considered markdown in discord
oh, sorry
you'd have to use this;
```js
message.reply(${gptResponse.choices[0].content});
```
message.reply(`${gptResponse.choices[0].content`});
wuttt
message.reply(`${gptResponse.choices[0].content`});
oh its cuz i used slashes in my message 🤔 funky discord
there we go, had to add more slashes.
lol
anyhow, have you tried turning on the debugger on that line, and checking whats inside gptResponse?
i tried when it just said Undefined, however, i havent tried now, let me try your code and if that dosnt work ill debug it
also in my code i check if its successful / has a header " OK 200 " before i try reading it
sortof like a safeguard
wait, the ` symbol is impropietly placed right?, it starts outside the template linears and the other is inside, shoudnt it be as I listed originaly?
its also giving me a sintax error
just debugged it, it most likely haves to do with the discord part, as changing it to console.log(gptResponse.data.choices[0].message); gives me the correct answer
let my try a thing and maybe fix it
there we go now we have something to work on 🙂
so what was the issue? 😄
not really sure, just regenerated my discord bot key to a new one and it worked
also for future readers 😄
discord at its finest I supose
ah mkay thats , an edge case lol