#On trying to update Alexa index.js to cater for the 'gpt-3.5-turbo-0301' Api conundrum

4 messages · Page 1 of 1 (latest)

stone wedge
#

Herein is an extract from a simple Alexa skill project. The uncommented code ( ‘text-davinci-003’) works. The comments are sourced, partly, by ‘gpt-3.5-turbo’'s suggestions although the messages: [array] comes from OpenAi’s documentation. Needless to say the commented code does not work but shows my best efforts to date.

‘speakOutput’ is the puzzle but maybe that’s only part of the story.

Extracted from Alexa skill index.js
const AskOpenAIIntentHandler = {canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’
&& Alexa.getIntentName(handlerInput.requestEnvelope) === ‘AskOpenAIIntent’;
},

async handle(handlerInput) {const question =
Alexa.getSlotValue(handlerInput.requestEnvelope, ‘question’);

const response = await openai.createCompletion({
//const response = await openai.createChatCompletion({

//engine: 'textapi',
//model: 'gpt-3.5-turbo-0301',

model: 'text-davinci-003',
prompt: question,

/*
messages: [
{ role: "system", content: "You are an all round good egg" },
{ role: "assistant", content: "How else may I help" },
{ role: "user", content: question },
],
*/

temperature: 0.5,
max_tokens: 1024,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0,

/*
n: 1, 
stop: '\n',
*/

});

const speakOutput = response.data.choices[0].text +
' What more would you like to know?';

/* either
const systemMessage = response.data.choices[0].message;
const userMessage = systemMessage.context;
const speakOutput = ${userMessage} ${systemMessage.content} What more would you like to know? ;
or
const speakOutput = response.data.choices[0].message.content +
' What more would you like to know?';
neither works
*/

return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt("What else can I help you with?")
.getResponse();
}
};

Help!
🙂

neat cape
#

Hi. Have you tried omitting the engine property on line 12? And just to make sure, have you updated openai module to version 3.2.1? If either didn't help, I suggest to start catching errors with console logs. It's your best friend!

stone wedge
#

Hi Drie, thanks for taking the time to reply and I've rechecked and am using version openai@3.2.1.
**engine **was a suggestion by gpt-3.5-turbo.

Interestingly enough I have 3.5-turbo working in a Javascript app under VSCode where : const response = completion.data.choices[0].message.content; works.

I've got to admit that I don't yet know how to debug index.js inside the Alexa Developer Console.

neat cape
#

Hello! No worries! And yes, the response call using data.choices[0].message.content is the way to go, so it's a little bit tricky to find out what is wrong if we are are unable to debug through the console. As I am also unfamiliar with Alexa Dev Console, haha! Though I just double-checked the API documentation here https://platform.openai.com/docs/api-reference/engines, it says, "the Engines endpoints are deprecated. Please use their replacement, Models, instead." So I can't say if it would does anything, but everything else in your code looks fine to me.