Is there a problem with alexa integration with chatgpt openIA lately?

My code was working fine but now when i tried to call chatgpt Alexa keeps reprompting the intent and do not send request to openIA.

I tested the API_Key in with postman and it´s working good. Below follow the code I used to make integration in alexa developer console.

When a person call the intent it shows an image in alexa echo show and says an welcome message then user says the prompt question it sends to chatgpt limited by the systemrole rules and return with the answer.

But as I said it now keeps reprompting the welcome message.

// Handler para o ChatGPTIntent
const ChatGPTIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'ChatGPTIntent';
    },
      handle(handlerInput) {
        // Mensagem de boas-vindas que a Alexa irá falar
        const speakOutput = '<voice name="Ricardo"> Oi, eu sou o IÁ-glô, assistente virtual do suporte. O que você gostaria de saber?</voice>';

        // Definição do documento APL para a tela inicial
        const document = {
            "type": "APL",
            "version": "2024.1",
            "license": "Copyright 2024 Amazon.com, Inc. ou suas afiliadas. Todos os direitos reservados.nSPDX-License-Identifier: LicenseRef-.amazon.com.-AmznSL-1.0nLicenciado sob a Licença de Software da Amazon  http://aws.amazon.com/asl/",
            "theme": "dark",
            "import": [
                {
                    "name": "alexa-layouts",
                    "version": "1.7.0"
                }
            ],
            "mainTemplate": {
                "parameters": [
                    "backgroundImageExampleData"
                ],
                "items": [
                    {
                        "type": "Container",
                        "width": "100%",
                        "height": "100%",
                        "items": [
                            {
                                "type": "AlexaBackground",
                                "backgroundImageSource": "https://i.imgur.com/Pd42cgt.png"
                            }
                        ]
                    }
                ]
            }
        };


        // Datasources vazias (sem dados adicionais)
        const datasources = {};

        // Retorna a resposta da Alexa, incluindo o documento APL
        return handlerInput.responseBuilder
            .speak (speakOutput)
            .reprompt(speakOutput)
            .addDirective({
                type: 'Alexa.Presentation.APL.RenderDocument',
                token: 'documentToken',
                document: document,
                datasources: datasources
            })
            .getResponse();
    }
};

const IntegrarChatGPTIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'IntegrarChatGPTIntent';
    },
    async handle(handlerInput) {
        const userQuery = handlerInput.requestEnvelope.request.intent.slots.query.value; // Recebe a pergunta do usuário
        console.log(`Recebendo consulta do usuário: ${userQuery}`);

        const systemRole = "Você é um especialista do helpdesk e deve responder perguntas sobre o Media Composer. Finalize dizendo que, caso a pessoa precise, ela pode abrir um chamado no Globo Service para o suporte parceria.";

        try {
            const response = await axios.post('https://api.openai.com/v1/chat/completions', {
                model: 'gpt-3.5-turbo',
                messages: [
                    { role: 'system', content: systemRole },
                    { role: 'user', content: userQuery }
                ],
                max_tokens: 250
            }, {
                headers: {
                    'Authorization': `Bearer ${API_KEY}`
                }
            });
            
            const gptResponse = response.data.choices[0].message.content.trim();
            console.log(`Resposta do GPT: ${gptResponse}`);
            const speakOutput = `<voice name="Ricardo">${gptResponse}</voice>`;
            return handlerInput.responseBuilder
                .speak(speakOutput)
                .reprompt('')
                .getResponse();
        } catch (error) {
            console.error(`Erro ao chamar o ChatGPT: ${error}`);

            return handlerInput.responseBuilder
                .speak('Desculpe, ocorreu um erro ao obter a resposta. Por favor, tente novamente mais tarde.')
                .reprompt('')
                .getResponse();
        }
    }
};

New contributor

Lucas Oliveira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật