Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Lark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BiTableSchema,
BiTableView,
CopiedFile,
DocumentAIModel,
DocumentModel,
DriveFileModel,
TableFormView,
Expand Down Expand Up @@ -51,6 +52,7 @@ export class LarkApp implements LarkAppOption {
driveFileStore: DriveFileModel;
wikiNodeStore: WikiNodeModel;
documentStore: DocumentModel;
documentAIStore: DocumentAIModel;

constructor(option: LarkAppServerOption | LarkAppClientOption) {
Object.assign(this, option);
Expand All @@ -74,6 +76,9 @@ export class LarkApp implements LarkAppOption {
this.documentStore = new (class extends DocumentModel {
client = client;
})('');
this.documentAIStore = new (class extends DocumentAIModel {
client = client;
})();
}

private boot() {
Expand Down
60 changes: 60 additions & 0 deletions src/module/DocumentAI/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { makeFormData } from 'koajax';
import { BaseModel, RESTClient, toggle } from 'mobx-restful';

import { LarkData } from '../../type';
import { TaxiInvoice, TrainInvoice, VatInvoice, VehicleInvoice } from './type';

export * from './type';

export abstract class DocumentAIModel extends BaseModel {
baseURI = 'document_ai/v1';
abstract client: RESTClient;

/**
* @see {@link https://open.feishu.cn/document/ai/document_ai-v1/vat_invoice/recognize}
*/
@toggle('uploading')
async recognizeVatInvoice(file: File) {
const { body } = await this.client.post<LarkData<{ vat_invoices: VatInvoice[] }>>(
`${this.baseURI}/vat_invoice/recognize`,
makeFormData({ file })
);
return body!.data!.vat_invoices;
}

/**
* @see {@link https://open.feishu.cn/document/ai/document_ai-v1/taxi_invoice/recognize}
*/
@toggle('uploading')
async recognizeTaxiInvoice(file: File) {
const { body } = await this.client.post<LarkData<{ taxi_invoices: TaxiInvoice[] }>>(
`${this.baseURI}/taxi_invoice/recognize`,
makeFormData({ file })
);
return body!.data!.taxi_invoices;
}

/**
* @see {@link https://open.feishu.cn/document/ai/document_ai-v1/train_invoice/recognize}
*/
@toggle('uploading')
async recognizeTrainInvoice(file: File) {
const { body } = await this.client.post<LarkData<{ train_invoices: TrainInvoice[] }>>(
`${this.baseURI}/train_invoice/recognize`,
makeFormData({ file })
);
return body!.data!.train_invoices;
}

/**
* @see {@link https://open.feishu.cn/document/ai/document_ai-v1/vehicle_invoice/recognize}
*/
@toggle('uploading')
async recognizeVehicleInvoice(file: File) {
const { body } = await this.client.post<LarkData<{ vehicle_invoices: VehicleInvoice[] }>>(
`${this.baseURI}/vehicle_invoice/recognize`,
makeFormData({ file })
);
return body!.data!.vehicle_invoices;
}
}
17 changes: 17 additions & 0 deletions src/module/DocumentAI/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface InvoiceEntity {
type: string;
value: string;
score: number;
}

export interface Invoice {
entities: InvoiceEntity[];
}

export type VatInvoice = Invoice;

export type TaxiInvoice = Invoice;

export type TrainInvoice = Invoice;

export type VehicleInvoice = Invoice;
1 change: 1 addition & 0 deletions src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './SpreadSheet';
export * from './BITable';
export * from './Drive';
export * from './Wiki';
export * from './DocumentAI';