Skip to content

Commit

Permalink
Create blog post for how I use Khoj as my personal AI accountant
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjum committed Oct 5, 2024
1 parent 5b1fa7f commit 1333c48
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
Binary file added public/ai_accountant_abstract.webp
Binary file not shown.
46 changes: 46 additions & 0 deletions src/components/ClickableChatCard.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
import { Icon } from 'astro-icon/components'
---

<div class="rounded-lg m-1 shadow-md border border-green-400 text-sm">
<pre class="text-wrap"><slot/></pre>
<button class="p-2 rounded-lg border border-gray-400" id="copy-button">
<span id="copy-success" class="hidden"></span>
<Icon name="ph:copy" id="copy-icon" />
</button>
</div>

<script>
document.addEventListener("DOMContentLoaded", () => {
const copyButton = document.querySelector("#copy-button");
const codeBlock = document.querySelector("pre");
const copyIcon = document.querySelector("#copy-icon");

copyButton?.addEventListener("click", () => {
navigator.clipboard.writeText(codeBlock?.textContent || '');
console.debug("Copied to clipboard: ", codeBlock?.textContent);
copyIcon?.classList.add("text-green-400");
setTimeout(() => {
copyIcon?.classList.remove("text-green-400");
}, 1000);
});
});
</script>
<style>
div:hover {
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
}

a {
text-decoration: none;
color: black;
}

/* If the system is in dark mode, use the light mode color */
@media (prefers-color-scheme: dark) {
a {
color: white;
}
}
</style>

90 changes: 90 additions & 0 deletions src/content/posts/khoj-ai-personal-accountant.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Khoj - My Personal AI Accountant"
author: debanjum
description: Learn how I use Khoj and plain text accounting to keep my account synced and maintain an up-to-date view into all my finances.
tldr: "This post shares my personal workflow to do plain-text accounting using the Khoj app and API. I hope it inspires folks to create advanced, tailored AI workflows and share them to help everyone learn how to use these tools better."
heroImage: /ai_accountant_abstract.webp
pubDate: 2024-10-04
keywords: ["ai accountant", "plaintext accounting", "workflows"]
---
import ClickableChatCard from '../../components/ClickableChatCard.astro';

## Overview
I've been maintaining my personal finances using [Beancount](https://github.com/beancount/beancount?tab=readme-ov-file#beancount-double-entry-accounting-from-text-files), a [plain text accounting](https://plaintextaccounting.org/) tool, for the last decade.
These days [Khoj](https://app.khoj.dev) helps me keep my accounts synced and maintain an up-to-date view into all my finances.

## Bank Statement to Beancount
I ask Khoj to convert all my transactions from a bank statement PDF into Beancount format. This makes it easy to keep my ledger synced with reality.

Khoj intelligently extracts the transactions from the PDF statement, categorizes expenses into appropriate accounts and formats the information into Beancount format.

The flexibility offered by using AI instead of traditional programming is the best thing about this approach.
The AI based approach can be easily adapted to work with other Bank accounts, other output formats, handle changes to the PDF statement.
You can "program" your AI accountant with just natural language.

### Process
1. Download monthly account statements from my bank(s) as PDF
2. Start a new conversation with Khoj and add a bank statement to the conversation
3. Ask Khoj to summarize the bank statement with the following message. You should update this query to fit your ledger and bank statement format.
<ClickableChatCard>
{`
/summarize Extract Transaction Date, Merchant Name and Amount from all transactions in my shared credit card statement. Convert it to a Beancount format. Always assume account extracted from is CreditCard1 shown below. Choose Expense account from "Expenses:Food:Dining", "Expenses:Food:Groceries", "Expenses:Transport:Cab", "Expenses:Hardware" and "Expenses:Miscellaneous". Use the miscellaneous account if do not know which expense category to use.
Example: \`04/01, UBER *TRIP HELP.UBER.COM, 4.20\` extracted from PDF to Beancount format:
\`\`\`
2024-04-01 * "Uber" "Cab ride" #generated
Expenses:Transport:Cab
Liabilities:CreditCard:CreditCard1 -4.20 USD
\`\`\`
Give the transactions in a single beancount codeblock
`}
</ClickableChatCard>

4. Do a quick scan to compare Khoj extracted transactions to the transactions in the PDF statement.
5. Copy the extracted transactions, paste it into my Beancount ledger and edit any transactions if required

## Transaction SMS to Beancount
*Warning: This setup is for **advanced users only**. It requires an Android phone with [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm&hl=en&gl=US), [Termux](https://wiki.termux.com/wiki/Installing_from_F-Droid) and [Termux:Tasker](https://wiki.termux.com/wiki/Termux:Tasker) setup. A Khoj API key and ability to write single file Python (that interacts with [Khoj via API](https://app.khoj.dev/redoc)).*

Khoj automatically adds all my [UPI](https://en.wikipedia.org/wiki/Unified_Payments_Interface) transactions into my ledger. Using the information in the UPI transaction text message:
- Khoj converts INR to USD based on today's exchange rate
- Categorizes the transaction to the most appropriate expense account based on the payee information in the message
- Compiles the above information into a transaction in the Beancount format

### Implementation
1. Setup a Tasker profile to trigger on every transaction SMS from your UPI provider. Have it call a simple Python script via Termux.
2. The Python script interacts with Khoj over the [Cloud API](https://app.khoj.dev/redoc) to do the following:
1. Ask Khoj to convert INR to USD. Khoj looks up today's exchange rate online for this.
2. Ask Khoj to categorize the new transaction into the provided Expense accounts. E.g *Expenses:Food:Dining*
3. Append the Khoj generated transaction to my local Ledger file

*Note: I use [Syncthing](https://syncthing.net/) to keep my Ledger synced across my devices*

## Automations
You can create [automations](https://docs.khoj.dev/features/automations) with Khoj to help get reminders, notifications for your finances. For example:
- Ask Khoj to remind you to share your bank statements and sync your ledger
- Ask Khoj to remind you to do taxes before tax day
- Ask Khoj to notify you if the stock market drops by >5% in a single day

## Future Improvements
Khoj is getting new capabilities. Here are some future improvements I'm looking forward to that will make my workflows even more seamless:

- **Create Your Personal Accountant Agent**

Next week, Khoj agents will have gained new capabilities. You'll be able to:
- Create private agents. E.g Personal Financial Advisor.
- Tune agent personality for personal use-cases. E.g Chase to Ledger accountant.
- Give them access to specific documents. E.g ledger, bank statements.
- Restrict tool they can access. E.g no online search.

- **Ability to Reply to Khoj Automation Emails**

It'd be super convenient if you could reply and attach your Bank statements to Khoj's email reminding you to sync your ledger. This would make it even easier to keep your ledger synced.

## Conclusion
Access to advanced AI agents means everyone can 'program' using natural language. But we're all still discovering the best way to use these powerful tools.

My setup will not apply to most folks. And that is the point. The stuff Khoj helps me with is unique to me. This post is meant to inspire you to create tailored workflows with Khoj that fit your unique setups like a glove.

Share your workflows so we can all learn how to better use these tools in our various endeavors.

0 comments on commit 1333c48

Please sign in to comment.