Skip to content

Commit

Permalink
Adds support for transactions with no notes (#28)
Browse files Browse the repository at this point in the history
* add try/catch to initializeApi

* Fixed typos in the AI Prompt

* Adds support for null notes

* adds NODE_TLS_REJECT_UNAUTHORIZED=0 to README

* Fix eslint line length
  • Loading branch information
lejacobroy authored Aug 26, 2024
1 parent 21b7797 commit 0fbae43
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ services:
# - OPENAI_MODEL= # optional. required if you want to use a specific model, default is "gpt-3.5-turbo-instruct"
# - OPENAI_BASE_URL= # optional. required if you don't want to use the OpenAI API but OpenAI compatible API
# - ACTUAL_E2E_PASSWORD= # optional. required if you have E2E encryption
# - NODE_TLS_REJECT_UNAUTHORIZED=0 # optional. required if you have trouble connecting to Actual server
```

### 📝 Notes from the author
Expand Down
19 changes: 12 additions & 7 deletions src/actual-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ async function initializeApi() {
fs.mkdirSync(dataDir);
}
await actualApi.init({ dataDir, serverURL, password });
if (e2ePassword) {
await actualApi.downloadBudget(budgetId, {
password: e2ePassword,
});
} else {
await actualApi.downloadBudget(budgetId);
try {
if (e2ePassword) {
await actualApi.downloadBudget(budgetId, {
password: e2ePassword,
});
} else {
await actualApi.downloadBudget(budgetId);
}
console.log('Budget downloaded');
} catch (error) {
console.error('Failed to download budget:', error.message);
throw new Error('Budget download failed');
}
}

async function shutdownApi() {
await actualApi.shutdown();
}
Expand Down
4 changes: 2 additions & 2 deletions src/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { model } = require('./config');
const openai = new OpenAI({});

function generatePrompt(categoryGroups, transaction, payees) {
let prompt = 'Given I want to categorize the bank transactions in following categories:\n';
let prompt = 'I want to categorize the given bank transactions into the following categories:\n';
categoryGroups.forEach((categoryGroup) => {
categoryGroup.categories.forEach((category) => {
prompt += `* ${category.name} (${categoryGroup.name}) (ID: "${category.id}") \n`;
Expand All @@ -24,7 +24,7 @@ function generatePrompt(categoryGroups, transaction, payees) {
prompt += `* Payee: ${transaction.imported_payee}\n`;
}

prompt += 'ANSWER BY A CATEGORY ID.DO NOT WRITE THE WHOLE SENTENCE. Do not guess, if you don\'t know answer: "idk".';
prompt += 'ANSWER BY A CATEGORY ID. DO NOT WRITE THE WHOLE SENTENCE. Do not guess, if you don\'t know the answer, return "idk".';

return prompt;
}
Expand Down
3 changes: 2 additions & 1 deletion src/transaction-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async function processTransactions() {
(transaction) => !transaction.category
&& transaction.transfer_id === null
&& transaction.starting_balance_flag !== true
&& transaction.notes.includes(NOTES_NOT_GUESSED) === false,
&& (transaction.notes === null
|| transaction.notes.includes(NOTES_NOT_GUESSED) === false),
);

for (let i = 0; i < uncategorizedTransactions.length; i++) {
Expand Down

0 comments on commit 0fbae43

Please sign in to comment.