

Although at 112MB fully installed, including requests, numpy, and pandas, it's pretty beefy. The openai-python library makes interacting with the API a breeze. You could make it more cost-effective using AWS Step Functions to handle the OpenAI API call asyncrhonously, but I didn't worry for this project. Since it relies on an external API call, it does take a while to execute ( 1.285 seconds on average), which is very inefficient, and despite throwing Lambda Power Tuning at the problem, it's purely an external dependency issue, and can't be resolved by resources. This one sends the request to OpenAI, outputs some information for logging, and passes the information back to Lex. Lambda functions are best when kept simple. But I'm a hacky dev, building a hacky solution today.

This is an incredibly hacky way of doing it, and I'm sure there are many better ways.
#Amazon lex speech to text api code#
Neither mattered in this case, since both the created intent and the default FallbackIntent are going to be doing the same thing.Īfter enabling the Lambda code hooks for initialization, and configuring the bot to use my Lambda function, it will always behave the same, sending the message through to OpenAI, regardless of what's been said. Instead, I create a single intent (I called it campingInTents, because childish humour) with a random utterance ( pancakes I was hungry). Normally we would create multiple intents, with their respective utterances.

But we aren't using any of those features it's just a convenient way of handling the processing between text and speech with our Lambda function! Lex developers, look away now!Īfter we create our bot, we need to configure it. The name isn't a coincidence either, since it also powers Amazon Alexa. Lex (v2) is an immensely powerful service for building natural language experiences. You can use the editor to build out a workflow that meets your needs in a huge number of works, including logic, prompts, and an ability to trigger Lambda functions, making it hugely extensible! You'll need to setup a DID number (Direct In-dial number fancy word for your inbound phone number) for a country of your choice, but make sure it's available in your region on the Connect Pricing page, and that you meet any necessary regulations.īuilding your Contact Flow is the cool stuff happens. Like Quicksight and a few other services, Amazon Connect has its own control panels outside the AWS Management Console.įirst, you need to setup your Amazon Connect instance in your chosen region. Let's dive into some of those services in some more depth:Ĭonnect is a powerful service, but it can feel counter-intuitive if you've never managed a virtual contact centre before (lucky you!). Knowing the architecture is great, but it doesn't help build everything out in detail. To make debugging less nightmarish (we'll see why!), Amazon CloudWatch provides a simple way to store my basic log files, and Amazon API Gateway gives an ability to retrieve them! Since OpenAI's API costs money, I've leveraged AWS Secrets Manager to keep my API Key secure. The function itself is quite simple, although the supporting Lambda Layer was significantly larger. We aren't really using the Natural Language powers of Lex, but it has other uses for us:ĪWS Lambda handles the call to OpenAI's API. With Amazon Connect, it seamlessly leverages Amazon Transcribe to understand what is being said (speech-to-text), and Amazon Polly to provide the verbal response (text-to-speech). It's not exactly a leader in this space, but it's smooth integration with other AWS Services makes it a breeze for this scenario.Īmazon Lex, AWS's natural language conversational AI service. What's more, you can try it yourself! See the end of the article for more details.Īmazon Connect is a powerful solution that lets us set up a phone number, build contact flows, support call centre agents, and everything in-between. Today, I hacked together a cutting-edge AI chatbot that you can call from any phone, anywhere in the world. OpenAI's API allows us to leverage the power of the GPT Models in as many ways as we can imagine. For developers, it's just the tip of the iceberg. ChatGPT has sent the internet into a frenzy.
