The world of AI-powered applications is rapidly evolving, making it easier than ever for developers to bring their creative ideas to life. In this article, we'll explore how to build a short story generator using AWS Bedrock and the Amplify AI Kit. This project showcases the power and simplicity of these tools, allowing you to create custom stories with specific genres, tones, and styles in just a few hours.
Inspired by the recent AWS pre:Invent announcements and the release of the Amplify AI Kit, I decided to dive into the world of AI app development. Following the AWS documentation for a recipe assistant, I quickly realized the potential for creating a more personalized application. My goal was to build a story-telling app that could generate unique narratives based on user-defined inputs like genre, tone, and style.
The initial setup was surprisingly fast. Within approximately 40 minutes, a basic proof-of-concept (POC) was up and running, complete with authentication, a user interface, and the ability to generate cooking recipes using AI inference. This rapid progress highlighted the efficiency of the Amplify AI Kit.
The next step involved customizing the app to generate short stories. This involved adding UI elements that would allow the user to select:
To tailor the app to story generation, the Amplify data resources were modified. Specifically, the arguments, returns, and system prompt were adjusted. Here’s a snippet of the updated schema:
const schema = a.schema({
generateShortStory: a.generation({
aiModel: a.ai.model('Claude 3.5 Sonnet'),
systemPrompt: "You are a story-teller that generates short, engaging stories based on user-provided themes or genres. Each story should have a clear structure: an introduction to set the stage, a middle to develop the plot, a twist to surprise the reader, and a satisfying ending. The characters should be fictional, with at least one relatable protagonist. Adapt the tone and style based on user input. Ensure the story is concise and self-contained.",
})
.arguments({
genre: a.string(),
tone: a.string(),
style: a.string(),
})
.returns(
a.customType({
numberOfParagraphs: a.integer(),
story: a.string(),
})
)
.authorization((allow) => allow.authenticated()),
});
With the Amplify sandbox environment active (npx ampx sandbox
), these changes were automatically compiled and deployed to the cloud resources. This streamlined process allowed for quick iterations and adjustments to the app's functionality.
After a few UI tweaks, the short story generator was complete. Users could select their desired genre, tone, and style, and the app would generate a unique story based on those parameters.
The AI model can be easily changed, and experimenting with different Claude models is simple
The story generator app is powered by a robust serverless infrastructure provided by AWS. This architecture ensures scalability and efficiency. The Amplify AI Kit leverages several AWS services to handle different aspects of the application.
However, the architecture for this specific POC is simpler:
AWS AppSync directly communicates with Amazon Bedrock, using mapping templates to format the response. This streamlined approach eliminates the need for DynamoDB and Lambda functions in this particular implementation.
Interested in exploring the code behind this project? The full code repository for this POC can be found on Github.
This project demonstrates the incredible potential of AWS Amplify and Bedrock for building AI-powered applications. In just a few hours, it was possible to go from an idea to a fully functional proof-of-concept. Moreover, the app is backed by a scalable and efficient serverless infrastructure, making it ready to handle real-world usage.
The ease with which one can now experiment with AI-powered projects is truly exciting. The possibilities are endless, and I look forward to further exploring and enhancing this short story generator. Who knows, maybe it will even be launched as a full-fledged application!
If you're looking for expert guidance in building serverless solutions, consider reaching out to Serverless Guru for AWS Development and Consulting services.