為 MCP 建立發票分析 Toolsets
首先,我們需要建立一個專門用於發票分析的 Toolsets。這個工具會接收發票圖片,並回傳結構化的 JSON 資料。
1.1 建立 Automation Tool
- 在 Asgard 中進入 Workflow 功能區
- 點擊「Create New」建立新的 Automation Tool
- 設定名稱為「發票辨識」
- 雙擊進入剛才建立的 發票辨識 Automation Tool,進入編輯頁面
- 編輯 Validate Payload 的內容:
- 新增 File Alias 項目
- File Type 選擇
Image
- Alias 填寫
invoiceImg
- 點擊儲存
- Validate Payload 的 Success 新增目標節點,選擇 LLM Completion
- 編輯 LLM Completion 的內容:
- Completion Model: 選擇你使用的 AI Model
- Prompt Template:
你是發票報帳申請助手,負責根據員工上傳上來的發票影像,將發票內容,盡可能的轉換成結構化的 JSON 表達。
- 無法從圖片上判讀出來的欄位,請填入 null。
- 請依照以下 JSON 格式回傳:
- Output Schema:
{
"type": "object",
"properties": {
"invoiceForm": {
"type": "object",
"properties": {
"expense_item": {
"type": "string",
"description": "費用項目,例如停車費"
},
"expense_description": {
"type": "string",
"description": "費用說明,例如說明為何會有這筆費用"
},
"currency": {
"type": "string",
"description": "幣別,例如 TWD"
},
"invoice_type": {
"type": "string",
"description": "憑證類別,例如電子發票、三聯式發票等"
},
"invoice_date": {
"type": "string",
"description": "發票收據日期。格式: YYYY-MM-DD"
},
"invoice_number": {
"type": "string",
"description": "統一發票號碼"
},
"original_amount_with_tax": {
"type": "number",
"description": "原幣金額 (含稅)"
},
"seller_id": {
"type": "string",
"description": "賣方統編"
},
"seller_name": {
"type": "string",
"description": "賣方名稱"
}
}
}
},
"required": [
"invoiceForm"
]
}
- MaxTokens 設定為
4096
,並儲存 LLM Completion 頁面
- Blob IDs 點選 (+) 新增一個 Blob ID 輸入欄位
- 選擇 Expression 類型並且輸入以下程式碼:
// 將前面匯入的發票檔案傳給 AI 模型做視覺分析
(() => {
return invoiceImg.blobId;
})()
- 點擊儲存
- 在 LLM Completion 的 Success 新增目標節點,選擇 Response
- 編輯 Response 的內容:
- Payload 選擇
Expression
- 輸入以下內容:
- Payload 選擇
(() => {
return invoiceForm;
})()
- 儲存 Response 頁面
1.2 設定 Toolsets
- 在 Asgard 中進入 Apps 功能區,點擊「New Toolset」建立新的 Toolset
- 基本設定:
- 名稱: 發票分析
- 描述: 發票分析
- Environment: 選擇你的環境(範例選擇 main)
- API Key: 請填你預設的密碼 Key(範例:
123ddd
)
- Tool Settings 點右邊新增 Tool
- Automation Tool 選擇上面建立的「發票辨識」
- Name 給 AI 識別的欄位,範例:
parse_invoice_from_image
- Description 給 AI 判斷功能使用方式,範例如下:
Parse invoice data from an uploaded image file and return structured json data. You can only upload one image file at a time.
- 儲存 Toolsets 頁面