From 1fc82e0398f2266835cd9150cda0c81bf639af50 Mon Sep 17 00:00:00 2001 From: Eduar-wr Date: Mon, 16 Sep 2024 05:46:00 -0600 Subject: [PATCH] Update create-alexa-hosted-function.md ask-sdk-core==1.11.0 boto3==1.9.216 requests>=2.20.0 openai --- instructions/create-alexa-hosted-function.md | 50 ++++++++++++-------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/instructions/create-alexa-hosted-function.md b/instructions/create-alexa-hosted-function.md index d107739..19e7380 100644 --- a/instructions/create-alexa-hosted-function.md +++ b/instructions/create-alexa-hosted-function.md @@ -1,19 +1,31 @@ -# Build An Alexa Fact Skill - - -Build an engaging facts skill about any topic. Alexa will select a fact at random and share it with the user when the skill is invoked. - -## Deploying Skill Code - -In the [first step of this guide](./setup-vui-alexa-hosted.md), we built the Voice User Interface (VUI) for our Alexa skill. -On this page, we will be exploring the Alexa-Hosted code editor, and deploying our code to enable testing. - - * *For details on what the Alexa-Hosted skills service provides, open [this page](https://developer.amazon.com/docs/hosted-skills/build-a-skill-end-to-end-using-an-alexa-hosted-skill.html) in a new tab.* - - -Within your skill in the developer console, click on the **Code** tab at the top of the page. You should see folders and files within the left panel, you can change your code, select the **Save** button, then select **Deploy**. This will deploy your code into a Lambda function that is automatically managed for you by the Alexa-Hosted service. - - -At the bottom left corner of the page, notice the link to **Logs: Amazon CloudWatch**. CloudWatch is the logging service you can use to help debug your skill. We will go into more depth on how to use CloudWatch in the next step. - -[![Next](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/buttons/button_next_testing._TTH_.png)](./test-using-simulator.md) +import openai +import logging +import json +from ask_sdk_core.skill_builder import SkillBuilder +from ask_sdk_core.dispatch_components import AbstractRequestHandler +from ask_sdk_core.handler_input import HandlerInput +from ask_sdk_model import Response + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) + +api_key = "YOUR_API_KEY" + +class GptQueryHandler(AbstractRequestHandler): + def can_handle(self, handler_input): + return handler_input.request_envelope.request.intent.name == "GptQueryIntent" + + def handle(self, handler_input): + query = handler_input.request_envelope.request.intent.slots["query"].value + response = openai.Completion.create( + engine="text-davinci-003", + prompt=query, + max_tokens=50 + ) + speech_text = response.choices[0].text.strip() + return handler_input.response_builder.speak(speech_text).response + +sb = SkillBuilder() +sb.add_request_handler(GptQueryHandler()) +lambda_handler = sb.lambda_handler() +Código generado por IA. Revisar y usar cuidadosamente. Más información sobre preguntas frecuentes.