Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatgptalexaUpdate create-alexa-hosted-function.md #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions instructions/create-alexa-hosted-function.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# Build An Alexa Fact Skill
<img src="https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/quiz-game/header._TTH_.png" />

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.