Building a Financial Literacy Assistant using Lyzr SDK

akshay007

Akshay Keerthi

Posted on August 20, 2024

Building a Financial Literacy Assistant using Lyzr SDK

In today’s digital world, financial literacy is more important than ever. Whether you’re managing your own budget or helping others navigate their finances, having the right tools to simplify complex financial concepts can make all the difference. That’s where our Financial Literacy Assistant comes in.

Image description

This blog post will guide you through building a simple yet powerful Financial Literacy Assistant using Streamlit and Lyzr Automata. By the end of this tutorial, you’ll have a fully functional app that leverages the power of AI to help users understand personal finance better.

Prerequisites

Before diving into the code, ensure you have the following:

-Python installed on your machine.
-An OpenAI API key.
-Basic knowledge of Python and Streamlit.
-An understanding of how Lyzr Automata works (if not, check out their documentation).

Setting Up the Project

First, let’s start by importing the necessary libraries and setting up the environment:

import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os
Enter fullscreen mode Exit fullscreen mode

Here, we import Streamlit for creating the app's interface, OpenAIModel from Lyzr Automata to interact with GPT, and other essential modules for building the task pipeline.

Next, set up your OpenAI API key:

# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
This ensures that your API key is securely stored and accessible when making API requests.

Implementing the AI Model

Next, we configure the OpenAI model, which will generate responses based on user input:

open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
Enter fullscreen mode Exit fullscreen mode

We create a function called generation() that utilizes Lyzr Automata to generate responses:

def generation(input):
    generator_agent = Agent(
        role="Expert FINANCIAL ADVISOR",
        prompt_persona=f"Your task is to EXPLAIN and EDUCATE users on PERSONAL FINANCE topics or questions. You MUST make the response as UNDERSTANDABLE and INFORMATIVE as possible, directly addressing the questions the user asks.")

    prompt = f"""
    You are an Expert FINANCIAL ADVISOR. Your task is to EXPLAIN and EDUCATE users on PERSONAL FINANCE topics or questions. You MUST make the response as UNDERSTANDABLE and INFORMATIVE as possible, directly addressing the questions the user asks.
    [prompts here]
    """
generator_agent_task = Task(
        name="Generation",
        model=open_ai_text_completion_model,
        agent=generator_agent,
        instructions=prompt,
        default_input=input,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
    ).execute()
    return generator_agent_task
Enter fullscreen mode Exit fullscreen mode

This function sets up an agent with a specific role (Expert Financial Advisor) and instructions on how to generate the response.

Finally, we add a button that triggers the AI to generate a response when clicked:

if st.button("Assist!"):
    solution = generation(input)
    st.markdown(solution)
Enter fullscreen mode Exit fullscreen mode

With just a few lines of code, we’ve created a Financial Literacy Assistant that can help users better understand and manage their finances. By leveraging the power of AI through Lyzr Automata and Streamlit, we’ve built an accessible and user-friendly tool that can make financial literacy more attainable for everyone.

App link: https://financeassistant-lyzr.streamlit.app/

Source Code: https://github.com/isakshay007/financial_advisor

For any inquiries or support, feel free to contact Lyzr. You can learn more about Lyzr and their offerings through the following links:

Website: Lyzr.ai
Book a Demo: Book a Demo
Discord: Join our Discord community
Slack: Join our Slack channel

💖 💪 🙅 🚩
akshay007
Akshay Keerthi

Posted on August 20, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related