AWS Logo
Menu
The InvestmentGenie Generative AI App

The InvestmentGenie Generative AI App

Generative AI financial planning app.

Published Aug 12, 2024
This project automates financial planning and investment services using generative AI. This project also demonstrates the significant impact of well-crafted prompts on AI-generated content, highlighting the importance of prompt engineering in maximizing the potential of generative AI systems.

1. What is the InvestmentGenie App 🤷?

The InvestmentGenie app is a wealth management service that uses generative AI to create investment portfolios. It makes use of the asset allocation strategy, which is the process of dividing an investment portfolio among different asset categories, like stocks and bonds.
In this post, we focus on how to create a generative AI app that offers tailored personalized investment recommendations based on the lifestyle and preferences of users.
This project is intended for educational purposes only and not for production use.

2. Prompt Engineering 🏗️

Prompt engineering is a crucial skill in working with generative AI models. It involves crafting effective inputs (prompts) to guide AI models in producing desired outputs.
Prompt engineering techniques include zero-shot prompting, few-shot prompting, chain-of-thought prompting, and ReAct (reasoning and acting). This app makes use of the few-shot prompting technique, which provides a few examples of the task before asking the model to perform it.

3. Solution Overview 🛠️

The following figure shows the architecture of the InvestmentGenie app.
InvestmentGenie Architecture
InvestmentGenie Architecture
Users are able to configure the following input parameters on the app:
  • Name
  • Age
  • Risk appetite
  • Retirement age
  • Amount to invest
  • Marital status
  • Number of kids
The personalized recommendations offered by the app includes sections such as:
  • Personal details
  • Recommendation summary
  • Investment recommendation details (allocation, allocation amount, reason for recommendation)
  • Allocation charts
  • Additional notes
  • Learning resources.
This app utilizes the following patterns:
  • Packages: For a hierarchical structuring of the module namespace.
  • Application factory: An application factory in Flask is a design pattern useful in scaling Flask projects. It helps in creating and configuring Flask projects flexibly and efficiently, making it easier to develop, test, and maintain as it grows and evolves.
  • Blueprints: Blueprints are a way to organize Flask applications into reusable and maintainable units.
  • Templates: Templates are files that contain static data as well as placeholders for dynamic data. A template is rendered with specific data to produce a final document. This app makes use of the Jinja template engine.

3.1 Model Selection

A selection of models was reviewed, with consideration for use cases, model attributes, maximum tokens, cost, accuracy, performance, and supported languages. Based on this, Anthropic Claude-3 Sonnet was selected as best suited for this use case, as it strikes a balance between intelligence and speed, and it optimizes on speed and cost.

3.2 Prerequisites

You first need to set up an AWS account and configure your AWS Identity and Access Management (IAM) permissions correctly. You then need to request Anthropic Claude 3 Sonnet model access on Amazon Bedrock. You can find the code samples in the GitHub repository.

Python virtual environment setup

Establish a Python venv module virtual environment in the project directory and then proceed to install all necessary dependencies. By using a project-specific virtual environment, you ensure that all dependencies are installed exclusively within that environment, rather than system-wide.
Windows PowerShell
macOS
You should see a parenthesized (venv) in front of the prompt after running the command, which indicates that you’ve successfully activated the virtual environment.

Add dependencies

Once you have activated your virtual environment, proceed with installing Flask.

Install requirements

Configure AWS CLI options

Next, configure AWS CLI options. If this command is run with no arguments, you will be prompted for configuration values such as your AWS Access Key Id and your AWS Secret Access Key.

Run the Flask project

Windows PowerShell
macOS

Quit the app

Press CTRL+C or ^C on the terminal.

Exit the Python virtual environment

3.3 Building the application

Application factory (/InvestmentGeniePackage/``init``.py)

Application Factory is a function that is responsible for creating the application object and its configuration.

Blueprints (/InvestmentGeniePackage/pages.py)

Blueprints are modular components in Flask that encapsulate a collection of related views. They can be easily imported in the init file, providing a convenient way to organize and structure the application's routes and functionality.

Page not found (/InvestmentGeniePackage/errors.py)

Base template (/InvestmentGeniePackage/templates/base.html)

The base template is designed to establish a uniform structure for your project while allowing flexibility in certain content areas through Jinja's block functionality.

Child templates (/InvestmentGeniePackage/templates/pages)

Template inheritance allows you to build a base “skeleton” template that contains all the common elements of your site and defines blocks that child templates can override.

4. Conclusion 🌅

This guide walks you through how to build an investment advisor powered by generative AI. It explores prompt engineering techniques leveraging the capabilities of Anthropic's Claude 3 Sonnet Large Language Model.
 

Comments