(Day 226) Your Personal Finance Assistant

Ivan Ivanov · August 14, 2024

Hello :) Today is Day 226!

A quick summary of today:

  • finishing and documenting the personal finance assistant project

The full information and code is on my github, and below I will give some info about today’s improvements.

I added a prepare_data.py script

For reproducability, I prepared a script that takes the raw dataset, preprocesses it, indexes, creates description - all files needed for the UI to work, and outputs it to the folder where they can be directly read by the app.

Added a Makefile for easy setup

Usage: make [option]

Options:
  help                 Show this help message
  install              Install dependencies
  data                 Prepare data for the app (will overwrite any existing data)
  start                Start app
  del-audio            Delete any generated audio files

The last option is because the google TTS creates 3 mp3 files (for the welcome msg, user audio input and AI output), so for easy cleanup - all are deleted.

Switched to a different streamlit mic recorder

I was using another 3rd party mic input module, but it did not look very well in the UI and it did not work sometimes.

Old:

image

It had all these buttons and while recording, a big audio box appears.

The new one

image

A simple button that even changes text from - Start Audio to Stop Audio (and I can edit it). Bottom line - it provides better user experience.

Added prompt validity check

If the user inputs something that does not seem logical, or related to transactions, or even ‘…a u h’ (random letters) or if the transcribed audio is random letters because of some noise, the input first goes through gpt4o-mini to check whether:

  • it is related to transactions
  • related to the chat history
  • not random letters

Maybe there is a better way to do it, but at the moment the code is:

def check_valid_prompt(user_text_query: str, chat_history: List[Dict[str, str]]) -> str:
    """
    Check if the user query is valid and related to finance transactions.
    """
    check_prompt = f"You are a personal finance assistant. Here is the conversation history so far: {chat_history}\n\nDoes the below user query look correct and related to finance transactions and the chat history? Answer with 'Yes' or 'No':\n\n{user_text_query}"
    gpt4omini = gpt_client()
    response = gpt4omini.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": check_prompt}]
    )
    llm_check_response = response.choices[0].message.content
    return llm_check_response

Added project info

  • Used Dataset - Kaggle
  • Database - SQLite
  • LLM - OpenAI’s GPT
  • Audio Transcription Model - openai/whisper-small from HuggingFace
  • RAG pipeline - LlamaIndex
  • Monitoring/Tracing - Azire Pheonix
  • User Interface - Streamlit

UI example usage:

image

Monitoring example:

image

Created a project diagram:

image

Recorder a short demo

Unfortunately, the demo is best seen in the repo itself.

That is all for today!

See you tomorrow :)