質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Alexa

Alexa(アレクサ)は、米アマゾンが開発したクラウドベースのAIアシスタント。Amazon EchoやEcho dotに搭載され、話かけると音楽を再生したり、天気予報やスケジュールなど様々な情報を提供します。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

0回答

753閲覧

Alexa Developer ConsoleのテストからGPT-3.5を使用したいが、「スキルがリクエストに正しく応答できませんでした」と返されてしまう

halohalolin

総合スコア46

Alexa

Alexa(アレクサ)は、米アマゾンが開発したクラウドベースのAIアシスタント。Amazon EchoやEcho dotに搭載され、話かけると音楽を再生したり、天気予報やスケジュールなど様々な情報を提供します。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2023/02/19 07:48

編集2023/02/19 07:51

現在Alexa Developer Consoleを使用して、「ai相談」と呼ばれるAlexaスキルを作成し、GPT-3.5を使用して質問に答えるようにしたいと考えています。
しかし、「ai相談」を起動して、Alexaスキルに質問すると、「スキルがリクエストに正しく応答できませんでした」という返答しか得られません。
そこで、どのように問題を解決できるかについてアドバイスをいただけないでしょうか。

実現したいこと

手持ちのAlexa機器から、「ai相談」と呼ばれるAlexaスキルを起動し、GPT-3.5を使用して質問に答えるようにしたいと考えています。
なお開発したalexa skillは一般公開しません。

前提

ChatGPTが面白いので、自分だけがPCなど上でいじっているだけではなく、家族の会話の中で気軽に呼び出したくなってきました。
そこで、手持ちのAlexa機器からGPT-3.5を呼び出す方法はないかと調べていたところ、allforbigfireさんのAlexaにGPT-3.5を接続して、回答を比べた。記事がズバリだと感じたので、その記事を参考に自作のAlexa Skill「ai相談」をnode.jsで作っています。
しかし以下のところから進まなくなりましたのでアドバイスをいただきたいです。

入力欄に、「(設定したAlexaスキルの名称)を開いて」を入力します。 (画像) こんな感じの返答が繰り返しできるはずです。 Alexa単独ではこんな会話は出来ないので面白いですね。

Alexa Developer ConsoleからCloud Watch Logsを開くのですが、それらしいエラーログも見つからないので、どこから対処すればよいのかわからず悩んでいます。

発生している問題・エラーメッセージ

テストでの挙動

私:ai相談を開いて alexa:ai相談起動したで。なんでも聞いてな。 私:簡単にできる晩御飯のおすすめを教えてください alexa:スキルがリクエストに正しく応答できませんでした

CloudWatchのログ

INIT_START Runtime Version: nodejs:12.v28 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:77abd29a376492953263fdbbd771e2b863be367d591311a62a99db79d326dc26 START RequestId: 395a1375-77ef-49b6-9171-efe58b771320 Version: 4 END RequestId: 395a1375-77ef-49b6-9171-efe58b771320 REPORT RequestId: 395a1375-77ef-49b6-9171-efe58b771320 Duration: 3.26 ms Billed Duration: 4 ms Memory Size: 512 MB Max Memory Used: 62 MB Init Duration: 208.02 ms

該当のソースコード

package.json

json

1{ 2 "name": "hello-world", 3 "version": "1.2.0", 4 "description": "alexa utility for quickly building skills", 5 "main": "index.js", 6 "scripts": { 7 "test": "echo \"Error: no test specified\" && exit 1" 8 }, 9 "author": "Amazon Alexa", 10 "license": "Apache License", 11 "dependencies": { 12 "ask-sdk-core": "^2.7.0", 13 "ask-sdk-model": "^1.19.0", 14 "aws-sdk": "^2.326.0", 15 "axios": "^0.16.2" 16 } 17}

index.js

※Authorization部分はdummy値です

javascript

1/* * 2 * This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2). 3 * Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management, 4 * session persistence, api calls, and more. 5 * */ 6const Alexa = require('ask-sdk-core'); 7 8const axios = require('axios'); 9const title = 'ai相談'; 10 11const LaunchRequestHandler = { 12 canHandle(handlerInput) { 13 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; 14 }, 15 handle(handlerInput) { 16 const speakOutput = 'ai相談や。なんでも聞いて。'; 17 18 return handlerInput.responseBuilder 19 .speak(speakOutput) 20 .withSimpleCard( 21 title, 22 speakOutput) 23 .reprompt(speakOutput) 24 .getResponse(); 25 } 26}; 27 28 29const HelloWorldIntentHandler = { 30 canHandle(handlerInput) { 31 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' 32 && Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent'; 33 }, 34 async handle(handlerInput) { 35 const speechText = handlerInput.requestEnvelope.request.intent.slots.message.value; 36 const speechText_add_conditions = '以下条件で答えよ(条件)・京都弁喋る若い女性として答る・文字数最大600文字程・小学生にもわかりやすく・重要キーワードを残さない(質問)'+speechText; 37 console.log('speechText:'+speechText); 38 39// ここでChatGPTに繋げる 40 const response = await getChatGptResponse(speechText); 41 console.log('response:'+response); 42 43 return handlerInput.responseBuilder 44 .speak(response) 45 .withSimpleCard( 46 title, 47 response) 48 .reprompt(response) 49 .getResponse(); 50 } 51}; 52 53async function getChatGptResponse(input) { 54 const endpoint = 'https://api.openai.com/v1/completions'; 55 const headers = { 56 'Content-Type': 'application/json', 57 'Authorization': `Bearer dummy`, 58 }; 59 const data = { 60 prompt: input, 61 max_tokens: 2000, 62 model: "text-davinci-003" 63 }; 64 65 try { 66 const response = await axios.post(endpoint, data, { headers }); 67 return response.data.choices[0].text; 68 } catch (err) { 69 console.error(err); 70 return null; 71 } 72} 73 74const HelpIntentHandler = { 75 canHandle(handlerInput) { 76 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' 77 && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent'; 78 }, 79 handle(handlerInput) { 80 const speakOutput = 'You can say hello to me! How can I help?'; 81 82 return handlerInput.responseBuilder 83 .speak(speakOutput) 84 .reprompt(speakOutput) 85 .getResponse(); 86 } 87}; 88 89const CancelAndStopIntentHandler = { 90 canHandle(handlerInput) { 91 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' 92 && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent' 93 || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent'); 94 }, 95 handle(handlerInput) { 96 const speakOutput = 'Goodbye!'; 97 98 return handlerInput.responseBuilder 99 .speak(speakOutput) 100 .getResponse(); 101 } 102}; 103/* * 104 * FallbackIntent triggers when a customer says something that doesn’t map to any intents in your skill 105 * It must also be defined in the language model (if the locale supports it) 106 * This handler can be safely added but will be ingnored in locales that do not support it yet 107 * */ 108const FallbackIntentHandler = { 109 canHandle(handlerInput) { 110 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' 111 && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.FallbackIntent'; 112 }, 113 handle(handlerInput) { 114 const speakOutput = 'Sorry, I don\'t know about that. Please try again.'; 115 116 return handlerInput.responseBuilder 117 .speak(speakOutput) 118 .reprompt(speakOutput) 119 .getResponse(); 120 } 121}; 122/* * 123 * SessionEndedRequest notifies that a session was ended. This handler will be triggered when a currently open 124 * session is closed for one of the following reasons: 1) The user says "exit" or "quit". 2) The user does not 125 * respond or says something that does not match an intent defined in your voice model. 3) An error occurs 126 * */ 127const SessionEndedRequestHandler = { 128 canHandle(handlerInput) { 129 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest'; 130 }, 131 handle(handlerInput) { 132 console.log(`~~~~ Session ended: ${JSON.stringify(handlerInput.requestEnvelope)}`); 133 // Any cleanup logic goes here. 134 return handlerInput.responseBuilder.getResponse(); // notice we send an empty response 135 } 136}; 137/* * 138 * The intent reflector is used for interaction model testing and debugging. 139 * It will simply repeat the intent the user said. You can create custom handlers for your intents 140 * by defining them above, then also adding them to the request handler chain below 141 * */ 142const IntentReflectorHandler = { 143 canHandle(handlerInput) { 144 return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'; 145 }, 146 handle(handlerInput) { 147 const intentName = Alexa.getIntentName(handlerInput.requestEnvelope); 148 const speakOutput = `You just triggered ${intentName}`; 149 150 return handlerInput.responseBuilder 151 .speak(speakOutput) 152 //.reprompt('add a reprompt if you want to keep the session open for the user to respond') 153 .getResponse(); 154 } 155}; 156/** 157 * Generic error handling to capture any syntax or routing errors. If you receive an error 158 * stating the request handler chain is not found, you have not implemented a handler for 159 * the intent being invoked or included it in the skill builder below 160 * */ 161const ErrorHandler = { 162 canHandle() { 163 return true; 164 }, 165 handle(handlerInput, error) { 166 const speakOutput = 'Sorry, I had trouble doing what you asked. Please try again.'; 167 console.log(`~~~~ Error handled: ${JSON.stringify(error)}`); 168 169 return handlerInput.responseBuilder 170 .speak(speakOutput) 171 .reprompt(speakOutput) 172 .getResponse(); 173 } 174}; 175 176/** 177 * This handler acts as the entry point for your skill, routing all request and response 178 * payloads to the handlers above. Make sure any new handlers or interceptors you've 179 * defined are included below. The order matters - they're processed top to bottom 180 * */ 181exports.handler = Alexa.SkillBuilders.custom() 182 .addRequestHandlers( 183 LaunchRequestHandler, 184 HelloWorldIntentHandler, 185 HelpIntentHandler, 186 CancelAndStopIntentHandler, 187 FallbackIntentHandler, 188 SessionEndedRequestHandler, 189 IntentReflectorHandler) 190 .addErrorHandlers( 191 ErrorHandler) 192 .withCustomUserAgent('sample/hello-world/v1.2') 193 .lambda();

試したこと

ちょっとキャラ付けをして喋ってほしいなと思って、const speechText_add_conditions を追加したのがまずかったのかと思い、ここをallforbigfireさんのオリジナルに戻したりもしたのですが、改善しませんでした。
なお、APIキー自身は以下のcurl文で動作し、使えるのを確認しています。

curl https://api.openai.com/v1/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer dummy' \ -d '{ "model": "text-davinci-003", "max_tokens": 3500, "prompt": "以下条件で答えよ(条件)・京都弁喋る若いしっかり者の女性で返答・文字数最大600文字程・小学生にもわかりやすく・重要キーワードを残さない・末尾にしらんけど(質問)簡単にできる晩御飯のおすすめを教えてください" }'

以上よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問