Documind是一種高級文檔處理工具,利用AI從PDF中提取結構化數據。它旨在處理PDF轉換,提取相關信息以及由可自定義模式指定的格式結果。
該倉庫建在Zerox -https://github.com/getomni-ai/zerox上。 Zerox的MIT許可證包含在Core文件夾中,並且在根許可證文件中也提到了。
Documind託管版本的演示很快將供您嘗試!託管版本提供了完全管理的API的無縫體驗,因此您可以跳過設置並立即提取數據。
要完全訪問託管服務,請請求訪問權限,我們將為您設置。
在使用documind之前,請確保安裝以下軟件依賴關係:
documind依靠Ghostscript來處理某些PDF操作。在繼續之前,請在系統上安裝這兩個:
# On macOS
brew install ghostscript graphicsmagick
# On Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y ghostscript graphicsmagick
確保系統上安裝了Node.js(V18+)和NPM。
您可以通過NPM安裝documind :
npm install documind
documind需要一個.env文件來存儲像OpenAI API密鑰一樣的敏感信息。
在您的項目目錄中創建.env文件,並添加以下內容:
OPENAI_API_KEY=your_openai_api_key首先,導入documind並定義您的架構。模式概述了每個文檔中應尋找的信息documind 。這是一個快速開始的設置。
模式是每個對象定義的對像數組:
"string" , "number" , "array" , "object" )。銀行對帳單的示例模式:
const schema = [
{
name : "accountNumber" ,
type : "string" ,
description : "The account number of the bank statement."
} ,
{
name : "openingBalance" ,
type : "number" ,
description : "The opening balance of the account."
} ,
{
name : "transactions" ,
type : "array" ,
description : "List of transactions in the account." ,
children : [
{
name : "date" ,
type : "string" ,
description : "Transaction date."
} ,
{
name : "creditAmount" ,
type : "number" ,
description : "Credit Amount of the transaction."
} ,
{
name : "debitAmount" ,
type : "number" ,
description : "Debit Amount of the transaction."
} ,
{
name : "description" ,
type : "string" ,
description : "Transaction description."
}
]
} ,
{
name : "closingBalance" ,
type : "number" ,
description : "The closing balance of the account."
}
] ;documind使用documind通過傳遞文件URL和架構來處理PDF。
import { extract } from 'documind' ;
const runExtraction = async ( ) => {
const result = await extract ( {
file : 'https://bank_statement.pdf' ,
schema
} ) ;
console . log ( "Extracted Data:" , result ) ;
} ;
runExtraction ( ) ;這是提取結果的外觀的示例:
{
"success" : true ,
"pages" : 1 ,
"data" : {
"accountNumber" : " 100002345 " ,
"openingBalance" : 3200 ,
"transactions" : [
{
"date" : " 2021-05-12 " ,
"creditAmount" : null ,
"debitAmount" : 100 ,
"description" : " transfer to Tom "
},
{
"date" : " 2021-05-12 " ,
"creditAmount" : 50 ,
"debitAmount" : null ,
"description" : " For lunch the other day "
},
{
"date" : " 2021-05-13 " ,
"creditAmount" : 20 ,
"debitAmount" : null ,
"description" : " Refund for voucher "
},
{
"date" : " 2021-05-13 " ,
"creditAmount" : null ,
"debitAmount" : 750 ,
"description" : " May's rent "
}
],
"closingBalance" : 2420
},
"fileName" : " bank_statement.pdf "
}
Documind帶有內置模板,用於從發票,銀行語句等流行文檔類型中提取數據。這些模板使得在不定義自己的模式的情況下開始更容易入門。
列表可用模板
您可以使用templates.list函數列出所有可用模板。
import { templates } from 'documind' ;
const templates = templates . list ( ) ;
console . log ( templates ) ; // Logs all available template names使用模板
要使用模板,只需將其名稱與要從中提取數據提取的文件一起傳遞給extract功能。這是一個例子:
import { extract } from 'documind' ;
const runExtraction = async ( ) => {
const result = await extract ( {
file : 'https://bank_statement.pdf' ,
template : 'bank_statement'
} ) ;
console . log ( "Extracted Data:" , result ) ;
} ;
runExtraction ( ) ;閱讀模板文檔,以獲取有關模板以及如何貢獻您的模板的更多詳細信息。
歡迎捐款!請提交帶有任何改進或功能的拉請請求。
該項目已根據AGPL v3.0許可獲得許可。