mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
create transactions from AI receipt image recognition results
This commit is contained in:
@@ -33,6 +33,9 @@ import {
|
||||
import {
|
||||
type ExportTransactionDataRequest
|
||||
} from '@/models/data_management.ts';
|
||||
import type {
|
||||
RecognizedReceiptImageResponse
|
||||
} from '@/models/large_language_model.ts';
|
||||
|
||||
import {
|
||||
getUserTransactionDraft,
|
||||
@@ -1157,6 +1160,31 @@ export const useTransactionsStore = defineStore('transactions', () => {
|
||||
});
|
||||
}
|
||||
|
||||
function recognizeReceiptImage({ imageFile }: { imageFile: File }): Promise<RecognizedReceiptImageResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.recognizeReceiptImage({ imageFile }).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
reject({ message: 'Unable to recognize image' });
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to recognize image', error);
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
reject({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
reject({ message: 'Unable to recognize image' });
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function parseImportDsvFile({ fileType, fileEncoding, importFile }: { fileType: string, fileEncoding?: string, importFile: File }): Promise<string[][]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.parseImportDsvFile({ fileType, fileEncoding, importFile }).then(response => {
|
||||
@@ -1370,6 +1398,7 @@ export const useTransactionsStore = defineStore('transactions', () => {
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
deleteTransaction,
|
||||
recognizeReceiptImage,
|
||||
parseImportDsvFile,
|
||||
parseImportTransaction,
|
||||
importTransactions,
|
||||
|
||||
Reference in New Issue
Block a user