prime-sdk 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.module.js +11 -0
- package/dist/app.module.js.map +1 -1
- package/dist/external/aws/bedrock/bedrock.provider.d.ts +12 -0
- package/dist/external/aws/bedrock/bedrock.provider.js +31 -0
- package/dist/external/aws/bedrock/bedrock.provider.js.map +1 -0
- package/dist/external/aws/bedrock/bedrock.service.d.ts +8 -0
- package/dist/external/aws/bedrock/bedrock.service.js +38 -0
- package/dist/external/aws/bedrock/bedrock.service.js.map +1 -0
- package/dist/external/aws/textract/textract.provider.d.ts +12 -0
- package/dist/external/aws/textract/textract.provider.js +31 -0
- package/dist/external/aws/textract/textract.provider.js.map +1 -0
- package/dist/external/aws/textract/textract.service.d.ts +14 -0
- package/dist/external/aws/textract/textract.service.js +135 -0
- package/dist/external/aws/textract/textract.service.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/documents/documents.d.ts +18 -0
- package/dist/lib/documents/documents.js +57 -0
- package/dist/lib/documents/documents.js.map +1 -0
- package/dist/lib/documents/documents.module.d.ts +10 -0
- package/dist/lib/documents/documents.module.js +30 -0
- package/dist/lib/documents/documents.module.js.map +1 -0
- package/dist/lib/documents/interfaces/documents.interface.d.ts +18 -0
- package/dist/lib/documents/interfaces/documents.interface.js +6 -0
- package/dist/lib/documents/interfaces/documents.interface.js.map +1 -0
- package/dist/lib/documents/types/bedrock.type.d.ts +7 -0
- package/dist/lib/documents/types/bedrock.type.js +3 -0
- package/dist/lib/documents/types/bedrock.type.js.map +1 -0
- package/dist/lib/documents/types/textract.type.d.ts +72 -0
- package/dist/lib/documents/types/textract.type.js +3 -0
- package/dist/lib/documents/types/textract.type.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/src/app.module.ts +11 -0
- package/src/external/aws/bedrock/bedrock.provider.ts +39 -0
- package/src/external/aws/bedrock/bedrock.service.ts +29 -0
- package/src/external/aws/textract/textract.provider.ts +39 -0
- package/src/external/aws/textract/textract.service.ts +167 -0
- package/src/index.ts +10 -0
- package/src/lib/documents/documents.module.ts +26 -0
- package/src/lib/documents/documents.ts +83 -0
- package/src/lib/documents/interfaces/documents.interface.ts +51 -0
- package/src/lib/documents/types/bedrock.type.ts +6 -0
- package/src/lib/documents/types/textract.type.ts +78 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prime-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "swiss army knife",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,10 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@aws-sdk/client-kms": "^3.606.0",
|
|
26
|
+
"@aws-sdk/client-bedrock-runtime": "^3.620.0",
|
|
26
27
|
"@aws-sdk/client-s3": "^3.572.0",
|
|
27
28
|
"@aws-sdk/client-ses": "^3.572.0",
|
|
28
29
|
"@aws-sdk/client-sns": "^3.572.0",
|
|
29
30
|
"@aws-sdk/client-sqs": "^3.569.0",
|
|
31
|
+
"@aws-sdk/client-textract": "^3.620.0",
|
|
30
32
|
"@aws-sdk/s3-request-presigner": "^3.572.0",
|
|
31
33
|
"@nestjs/common": "^11.1.5",
|
|
32
34
|
"@nestjs/config": "^4.0.2",
|
package/src/app.module.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { CacheModule } from './lib/cache/cache.module';
|
|
|
9
9
|
import { TypeRedis } from './external/redis/types/ioredis.types';
|
|
10
10
|
import { ICache } from './lib/cache/interfaces/cache.interface';
|
|
11
11
|
import { Cache } from './lib/cache/cache';
|
|
12
|
+
import { DocumentsModule } from './lib/documents/documents.module';
|
|
12
13
|
|
|
13
14
|
//Example
|
|
14
15
|
@Module({
|
|
@@ -53,6 +54,16 @@ import { Cache } from './lib/cache/cache';
|
|
|
53
54
|
endpoint: 'http://localhost:4566/',
|
|
54
55
|
region: 'us-east-1',
|
|
55
56
|
}),
|
|
57
|
+
DocumentsModule.forRoot({
|
|
58
|
+
bedrock: {
|
|
59
|
+
region: 'us-east-1',
|
|
60
|
+
endpoint: 'http://localhost:4566/',
|
|
61
|
+
credentials: {
|
|
62
|
+
accessKeyId: '',
|
|
63
|
+
secretAccessKey: '',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
56
67
|
CacheModule.forRoot({
|
|
57
68
|
type: TypeRedis.SIMPLE,
|
|
58
69
|
connection: {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime';
|
|
2
|
+
import { DynamicModule } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
export type BedrockSetup = {
|
|
5
|
+
region: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
credentials: {
|
|
8
|
+
accessKeyId: string;
|
|
9
|
+
secretAccessKey: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const BedrockProvider = (params: BedrockSetup) => {
|
|
14
|
+
return {
|
|
15
|
+
provide: 'CONNECTION_BEDROCK_RUNTIME',
|
|
16
|
+
useFactory: () => {
|
|
17
|
+
return new BedrockRuntimeClient({
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: params.credentials.accessKeyId,
|
|
20
|
+
secretAccessKey: params.credentials.secretAccessKey,
|
|
21
|
+
},
|
|
22
|
+
...(params.endpoint && { endpoint: params.endpoint }),
|
|
23
|
+
region: params.region,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class BedrockModule {
|
|
30
|
+
static forRoot(params: BedrockSetup): DynamicModule {
|
|
31
|
+
const provider = BedrockProvider(params);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
module: BedrockModule,
|
|
35
|
+
providers: [provider],
|
|
36
|
+
exports: [provider],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
BedrockRuntimeClient,
|
|
4
|
+
InvokeModelCommand,
|
|
5
|
+
InvokeModelCommandOutput,
|
|
6
|
+
} from '@aws-sdk/client-bedrock-runtime';
|
|
7
|
+
import { IBedrock } from '../../../lib/documents/interfaces/documents.interface';
|
|
8
|
+
import { InvokeModelPayload } from '../../../lib/documents/types/bedrock.type';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class Bedrock implements IBedrock {
|
|
12
|
+
constructor(
|
|
13
|
+
@Inject('CONNECTION_BEDROCK_RUNTIME')
|
|
14
|
+
private readonly client: BedrockRuntimeClient,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
async invokeModel(
|
|
18
|
+
payload: InvokeModelPayload,
|
|
19
|
+
): Promise<InvokeModelCommandOutput> {
|
|
20
|
+
const command = new InvokeModelCommand({
|
|
21
|
+
body: payload.body,
|
|
22
|
+
modelId: payload.modelId,
|
|
23
|
+
contentType: payload.contentType || 'application/json',
|
|
24
|
+
accept: payload.accept || 'application/json',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return await this.client.send(command);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TextractClient } from '@aws-sdk/client-textract';
|
|
2
|
+
import { DynamicModule } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
export type TextractSetup = {
|
|
5
|
+
region: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
credentials: {
|
|
8
|
+
accessKeyId: string;
|
|
9
|
+
secretAccessKey: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const TextractProvider = (params: TextractSetup) => {
|
|
14
|
+
return {
|
|
15
|
+
provide: 'CONNECTION_TEXTRACT',
|
|
16
|
+
useFactory: () => {
|
|
17
|
+
return new TextractClient({
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: params.credentials.accessKeyId,
|
|
20
|
+
secretAccessKey: params.credentials.secretAccessKey,
|
|
21
|
+
},
|
|
22
|
+
...(params.endpoint && { endpoint: params.endpoint }),
|
|
23
|
+
region: params.region,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class TextractModule {
|
|
30
|
+
static forRoot(params: TextractSetup): DynamicModule {
|
|
31
|
+
const provider = TextractProvider(params);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
module: TextractModule,
|
|
35
|
+
providers: [provider],
|
|
36
|
+
exports: [provider],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
AnalyzeDocumentCommand,
|
|
4
|
+
AnalyzeDocumentCommandOutput,
|
|
5
|
+
DetectDocumentTextCommand,
|
|
6
|
+
DetectDocumentTextCommandOutput,
|
|
7
|
+
StartDocumentAnalysisCommand,
|
|
8
|
+
StartDocumentAnalysisCommandOutput,
|
|
9
|
+
GetDocumentAnalysisCommand,
|
|
10
|
+
GetDocumentAnalysisCommandOutput,
|
|
11
|
+
StartDocumentTextDetectionCommand,
|
|
12
|
+
StartDocumentTextDetectionCommandOutput,
|
|
13
|
+
GetDocumentTextDetectionCommand,
|
|
14
|
+
GetDocumentTextDetectionCommandOutput,
|
|
15
|
+
Document,
|
|
16
|
+
TextractClient,
|
|
17
|
+
} from '@aws-sdk/client-textract';
|
|
18
|
+
import { ITextract } from '../../../lib/documents/interfaces/documents.interface';
|
|
19
|
+
import {
|
|
20
|
+
AnalyzeDocumentInput,
|
|
21
|
+
DetectDocumentTextBytesInput,
|
|
22
|
+
DetectDocumentTextS3Input,
|
|
23
|
+
StartDocumentAnalysisInput,
|
|
24
|
+
GetDocumentAnalysisInput,
|
|
25
|
+
StartDocumentTextDetectionInput,
|
|
26
|
+
GetDocumentTextDetectionInput,
|
|
27
|
+
} from '../../../lib/documents/types/textract.type';
|
|
28
|
+
|
|
29
|
+
@Injectable()
|
|
30
|
+
export class Textract implements ITextract {
|
|
31
|
+
constructor(
|
|
32
|
+
@Inject('CONNECTION_TEXTRACT') private readonly client: TextractClient,
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
async detectDocumentTextBytes(
|
|
36
|
+
input: DetectDocumentTextBytesInput,
|
|
37
|
+
): Promise<DetectDocumentTextCommandOutput> {
|
|
38
|
+
const document: Document = { Bytes: input.bytes };
|
|
39
|
+
const command = new DetectDocumentTextCommand({ Document: document });
|
|
40
|
+
return await this.client.send(command);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async detectDocumentTextS3(
|
|
44
|
+
input: DetectDocumentTextS3Input,
|
|
45
|
+
): Promise<DetectDocumentTextCommandOutput> {
|
|
46
|
+
const document: Document = {
|
|
47
|
+
S3Object: { Bucket: input.bucket, Name: input.name },
|
|
48
|
+
};
|
|
49
|
+
const command = new DetectDocumentTextCommand({ Document: document });
|
|
50
|
+
return await this.client.send(command);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async analyzeDocument(
|
|
54
|
+
input: AnalyzeDocumentInput,
|
|
55
|
+
): Promise<AnalyzeDocumentCommandOutput> {
|
|
56
|
+
const document: Document = input.bytes
|
|
57
|
+
? { Bytes: input.bytes }
|
|
58
|
+
: { S3Object: { Bucket: input.bucket, Name: input.name } };
|
|
59
|
+
|
|
60
|
+
const command = new AnalyzeDocumentCommand({
|
|
61
|
+
Document: document,
|
|
62
|
+
FeatureTypes: input.featureTypes,
|
|
63
|
+
...(input.queriesConfig && { QueriesConfig: input.queriesConfig }),
|
|
64
|
+
...(input.adaptersConfig && { AdaptersConfig: input.adaptersConfig }),
|
|
65
|
+
...(input.humanLoopConfig && { HumanLoopConfig: input.humanLoopConfig }),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return await this.client.send(command);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async startDocumentAnalysis(
|
|
72
|
+
input: StartDocumentAnalysisInput,
|
|
73
|
+
): Promise<StartDocumentAnalysisCommandOutput> {
|
|
74
|
+
const command = new StartDocumentAnalysisCommand({
|
|
75
|
+
DocumentLocation: {
|
|
76
|
+
S3Object: {
|
|
77
|
+
Bucket: input.bucket,
|
|
78
|
+
Name: input.name,
|
|
79
|
+
...(input.version && { Version: input.version }),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
FeatureTypes: input.featureTypes,
|
|
83
|
+
...(input.queriesConfig && { QueriesConfig: input.queriesConfig }),
|
|
84
|
+
...(input.adaptersConfig && { AdaptersConfig: input.adaptersConfig }),
|
|
85
|
+
...(input.clientRequestToken && {
|
|
86
|
+
ClientRequestToken: input.clientRequestToken,
|
|
87
|
+
}),
|
|
88
|
+
...(input.jobTag && { JobTag: input.jobTag }),
|
|
89
|
+
...(input.notificationChannel && {
|
|
90
|
+
NotificationChannel: {
|
|
91
|
+
SNSTopicArn: input.notificationChannel.snsTopicArn,
|
|
92
|
+
RoleArn: input.notificationChannel.roleArn,
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
...(input.outputConfig && {
|
|
96
|
+
OutputConfig: {
|
|
97
|
+
S3Bucket: input.outputConfig.s3Bucket,
|
|
98
|
+
...(input.outputConfig.s3Prefix && {
|
|
99
|
+
S3Prefix: input.outputConfig.s3Prefix,
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
...(input.kmsKeyId && { KMSKeyId: input.kmsKeyId }),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return await this.client.send(command);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async getDocumentAnalysis(
|
|
110
|
+
input: GetDocumentAnalysisInput,
|
|
111
|
+
): Promise<GetDocumentAnalysisCommandOutput> {
|
|
112
|
+
const command = new GetDocumentAnalysisCommand({
|
|
113
|
+
JobId: input.jobId,
|
|
114
|
+
...(input.maxResults && { MaxResults: input.maxResults }),
|
|
115
|
+
...(input.nextToken && { NextToken: input.nextToken }),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return await this.client.send(command);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async startDocumentTextDetection(
|
|
122
|
+
input: StartDocumentTextDetectionInput,
|
|
123
|
+
): Promise<StartDocumentTextDetectionCommandOutput> {
|
|
124
|
+
const command = new StartDocumentTextDetectionCommand({
|
|
125
|
+
DocumentLocation: {
|
|
126
|
+
S3Object: {
|
|
127
|
+
Bucket: input.bucket,
|
|
128
|
+
Name: input.name,
|
|
129
|
+
...(input.version && { Version: input.version }),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
...(input.clientRequestToken && {
|
|
133
|
+
ClientRequestToken: input.clientRequestToken,
|
|
134
|
+
}),
|
|
135
|
+
...(input.jobTag && { JobTag: input.jobTag }),
|
|
136
|
+
...(input.notificationChannel && {
|
|
137
|
+
NotificationChannel: {
|
|
138
|
+
SNSTopicArn: input.notificationChannel.snsTopicArn,
|
|
139
|
+
RoleArn: input.notificationChannel.roleArn,
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
...(input.outputConfig && {
|
|
143
|
+
OutputConfig: {
|
|
144
|
+
S3Bucket: input.outputConfig.s3Bucket,
|
|
145
|
+
...(input.outputConfig.s3Prefix && {
|
|
146
|
+
S3Prefix: input.outputConfig.s3Prefix,
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
...(input.kmsKeyId && { KMSKeyId: input.kmsKeyId }),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return await this.client.send(command);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async getDocumentTextDetection(
|
|
157
|
+
input: GetDocumentTextDetectionInput,
|
|
158
|
+
): Promise<GetDocumentTextDetectionCommandOutput> {
|
|
159
|
+
const command = new GetDocumentTextDetectionCommand({
|
|
160
|
+
JobId: input.jobId,
|
|
161
|
+
...(input.maxResults && { MaxResults: input.maxResults }),
|
|
162
|
+
...(input.nextToken && { NextToken: input.nextToken }),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return await this.client.send(command);
|
|
166
|
+
}
|
|
167
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,12 @@ import { ICrypto } from './lib/crypto/interfaces/crypto.interface';
|
|
|
21
21
|
import { CacheModule } from './lib/cache/cache.module';
|
|
22
22
|
import { Cache } from './lib/cache/cache';
|
|
23
23
|
import { ICache } from './lib/cache/interfaces/cache.interface';
|
|
24
|
+
import { DocumentsModule } from './lib/documents/documents.module';
|
|
25
|
+
import { Documents } from './lib/documents/documents';
|
|
26
|
+
import {
|
|
27
|
+
IBedrock,
|
|
28
|
+
ITextract,
|
|
29
|
+
} from './lib/documents/interfaces/documents.interface';
|
|
24
30
|
import {
|
|
25
31
|
SimpleRedisSetup,
|
|
26
32
|
ClusterRedisSetup,
|
|
@@ -47,6 +53,10 @@ export {
|
|
|
47
53
|
CacheModule,
|
|
48
54
|
Cache,
|
|
49
55
|
ICache,
|
|
56
|
+
DocumentsModule,
|
|
57
|
+
Documents,
|
|
58
|
+
IBedrock,
|
|
59
|
+
ITextract,
|
|
50
60
|
SimpleRedisSetup,
|
|
51
61
|
ClusterRedisSetup,
|
|
52
62
|
TypeRedis,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
BedrockModule as BedrockProviderModule,
|
|
4
|
+
BedrockSetup,
|
|
5
|
+
} from '../../external/aws/bedrock/bedrock.provider';
|
|
6
|
+
import { Bedrock as BedrockService } from '../../external/aws/bedrock/bedrock.service';
|
|
7
|
+
import { TextractSetup } from '../../external/aws/textract/textract.provider';
|
|
8
|
+
import { Documents } from './documents';
|
|
9
|
+
import { IBedrock } from './interfaces/documents.interface';
|
|
10
|
+
|
|
11
|
+
export type DocumentsSetup = {
|
|
12
|
+
bedrock: BedrockSetup;
|
|
13
|
+
textract?: TextractSetup;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
@Module({})
|
|
17
|
+
export class DocumentsModule {
|
|
18
|
+
static forRoot(params: DocumentsSetup): DynamicModule {
|
|
19
|
+
return {
|
|
20
|
+
module: DocumentsModule,
|
|
21
|
+
imports: [BedrockProviderModule.forRoot(params.bedrock)],
|
|
22
|
+
providers: [Documents, { provide: IBedrock, useClass: BedrockService }],
|
|
23
|
+
exports: [Documents, { provide: IBedrock, useClass: BedrockService }],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Inject, Injectable, Optional } from '@nestjs/common';
|
|
2
|
+
import { IBedrock, ITextract } from './interfaces/documents.interface';
|
|
3
|
+
import { InvokeModelCommandOutput } from '@aws-sdk/client-bedrock-runtime';
|
|
4
|
+
import {
|
|
5
|
+
AnalyzeDocumentCommandOutput,
|
|
6
|
+
DetectDocumentTextCommandOutput,
|
|
7
|
+
StartDocumentAnalysisCommandOutput,
|
|
8
|
+
GetDocumentAnalysisCommandOutput,
|
|
9
|
+
StartDocumentTextDetectionCommandOutput,
|
|
10
|
+
GetDocumentTextDetectionCommandOutput,
|
|
11
|
+
} from '@aws-sdk/client-textract';
|
|
12
|
+
import { InvokeModelPayload } from './types/bedrock.type';
|
|
13
|
+
import {
|
|
14
|
+
AnalyzeDocumentInput,
|
|
15
|
+
DetectDocumentTextBytesInput,
|
|
16
|
+
DetectDocumentTextS3Input,
|
|
17
|
+
StartDocumentAnalysisInput,
|
|
18
|
+
GetDocumentAnalysisInput,
|
|
19
|
+
StartDocumentTextDetectionInput,
|
|
20
|
+
GetDocumentTextDetectionInput,
|
|
21
|
+
} from './types/textract.type';
|
|
22
|
+
|
|
23
|
+
@Injectable()
|
|
24
|
+
export class Documents {
|
|
25
|
+
constructor(
|
|
26
|
+
@Optional()
|
|
27
|
+
@Inject(IBedrock)
|
|
28
|
+
private readonly bedrock: IBedrock,
|
|
29
|
+
@Optional()
|
|
30
|
+
@Inject(ITextract)
|
|
31
|
+
private readonly textract: ITextract,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
// bedrock
|
|
35
|
+
async invokeBedrockModel(
|
|
36
|
+
payload: InvokeModelPayload,
|
|
37
|
+
): Promise<InvokeModelCommandOutput> {
|
|
38
|
+
return await this.bedrock.invokeModel(payload);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// textract
|
|
42
|
+
async detectDocumentTextBytes(
|
|
43
|
+
input: DetectDocumentTextBytesInput,
|
|
44
|
+
): Promise<DetectDocumentTextCommandOutput> {
|
|
45
|
+
return await this.textract.detectDocumentTextBytes(input);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async detectDocumentTextS3(
|
|
49
|
+
input: DetectDocumentTextS3Input,
|
|
50
|
+
): Promise<DetectDocumentTextCommandOutput> {
|
|
51
|
+
return await this.textract.detectDocumentTextS3(input);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async analyzeDocument(
|
|
55
|
+
input: AnalyzeDocumentInput,
|
|
56
|
+
): Promise<AnalyzeDocumentCommandOutput> {
|
|
57
|
+
return await this.textract.analyzeDocument(input);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async startDocumentAnalysis(
|
|
61
|
+
input: StartDocumentAnalysisInput,
|
|
62
|
+
): Promise<StartDocumentAnalysisCommandOutput> {
|
|
63
|
+
return await this.textract.startDocumentAnalysis(input);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getDocumentAnalysis(
|
|
67
|
+
input: GetDocumentAnalysisInput,
|
|
68
|
+
): Promise<GetDocumentAnalysisCommandOutput> {
|
|
69
|
+
return await this.textract.getDocumentAnalysis(input);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async startDocumentTextDetection(
|
|
73
|
+
input: StartDocumentTextDetectionInput,
|
|
74
|
+
): Promise<StartDocumentTextDetectionCommandOutput> {
|
|
75
|
+
return await this.textract.startDocumentTextDetection(input);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getDocumentTextDetection(
|
|
79
|
+
input: GetDocumentTextDetectionInput,
|
|
80
|
+
): Promise<GetDocumentTextDetectionCommandOutput> {
|
|
81
|
+
return await this.textract.getDocumentTextDetection(input);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { InvokeModelCommandOutput } from '@aws-sdk/client-bedrock-runtime';
|
|
2
|
+
import {
|
|
3
|
+
AnalyzeDocumentCommandOutput,
|
|
4
|
+
DetectDocumentTextCommandOutput,
|
|
5
|
+
StartDocumentAnalysisCommandOutput,
|
|
6
|
+
GetDocumentAnalysisCommandOutput,
|
|
7
|
+
StartDocumentTextDetectionCommandOutput,
|
|
8
|
+
GetDocumentTextDetectionCommandOutput,
|
|
9
|
+
} from '@aws-sdk/client-textract';
|
|
10
|
+
import { InvokeModelPayload } from '../types/bedrock.type';
|
|
11
|
+
import {
|
|
12
|
+
AnalyzeDocumentInput,
|
|
13
|
+
DetectDocumentTextBytesInput,
|
|
14
|
+
DetectDocumentTextS3Input,
|
|
15
|
+
StartDocumentAnalysisInput,
|
|
16
|
+
GetDocumentAnalysisInput,
|
|
17
|
+
StartDocumentTextDetectionInput,
|
|
18
|
+
GetDocumentTextDetectionInput,
|
|
19
|
+
} from '../types/textract.type';
|
|
20
|
+
|
|
21
|
+
export interface IBedrock {
|
|
22
|
+
invokeModel(payload: InvokeModelPayload): Promise<InvokeModelCommandOutput>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const IBedrock = Symbol('IBedrock');
|
|
26
|
+
|
|
27
|
+
export interface ITextract {
|
|
28
|
+
detectDocumentTextBytes(
|
|
29
|
+
input: DetectDocumentTextBytesInput,
|
|
30
|
+
): Promise<DetectDocumentTextCommandOutput>;
|
|
31
|
+
detectDocumentTextS3(
|
|
32
|
+
input: DetectDocumentTextS3Input,
|
|
33
|
+
): Promise<DetectDocumentTextCommandOutput>;
|
|
34
|
+
analyzeDocument(
|
|
35
|
+
input: AnalyzeDocumentInput,
|
|
36
|
+
): Promise<AnalyzeDocumentCommandOutput>;
|
|
37
|
+
startDocumentAnalysis(
|
|
38
|
+
input: StartDocumentAnalysisInput,
|
|
39
|
+
): Promise<StartDocumentAnalysisCommandOutput>;
|
|
40
|
+
getDocumentAnalysis(
|
|
41
|
+
input: GetDocumentAnalysisInput,
|
|
42
|
+
): Promise<GetDocumentAnalysisCommandOutput>;
|
|
43
|
+
startDocumentTextDetection(
|
|
44
|
+
input: StartDocumentTextDetectionInput,
|
|
45
|
+
): Promise<StartDocumentTextDetectionCommandOutput>;
|
|
46
|
+
getDocumentTextDetection(
|
|
47
|
+
input: GetDocumentTextDetectionInput,
|
|
48
|
+
): Promise<GetDocumentTextDetectionCommandOutput>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const ITextract = Symbol('ITextract');
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FeatureType,
|
|
3
|
+
QueriesConfig,
|
|
4
|
+
AdaptersConfig,
|
|
5
|
+
HumanLoopConfig,
|
|
6
|
+
} from '@aws-sdk/client-textract';
|
|
7
|
+
|
|
8
|
+
export type DetectDocumentTextBytesInput = {
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type DetectDocumentTextS3Input = {
|
|
13
|
+
bucket: string;
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type AnalyzeDocumentInput =
|
|
18
|
+
| ({ bytes: Uint8Array; bucket?: never; name?: never } & {
|
|
19
|
+
featureTypes: FeatureType[];
|
|
20
|
+
queriesConfig?: QueriesConfig;
|
|
21
|
+
adaptersConfig?: AdaptersConfig;
|
|
22
|
+
humanLoopConfig?: HumanLoopConfig;
|
|
23
|
+
})
|
|
24
|
+
| ({ bytes?: never; bucket: string; name: string } & {
|
|
25
|
+
featureTypes: FeatureType[];
|
|
26
|
+
queriesConfig?: QueriesConfig;
|
|
27
|
+
adaptersConfig?: AdaptersConfig;
|
|
28
|
+
humanLoopConfig?: HumanLoopConfig;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type StartDocumentAnalysisInput = {
|
|
32
|
+
bucket: string;
|
|
33
|
+
name: string;
|
|
34
|
+
version?: string;
|
|
35
|
+
featureTypes: FeatureType[];
|
|
36
|
+
queriesConfig?: QueriesConfig;
|
|
37
|
+
adaptersConfig?: AdaptersConfig;
|
|
38
|
+
clientRequestToken?: string;
|
|
39
|
+
jobTag?: string;
|
|
40
|
+
notificationChannel?: {
|
|
41
|
+
snsTopicArn: string;
|
|
42
|
+
roleArn: string;
|
|
43
|
+
};
|
|
44
|
+
outputConfig?: {
|
|
45
|
+
s3Bucket: string;
|
|
46
|
+
s3Prefix?: string;
|
|
47
|
+
};
|
|
48
|
+
kmsKeyId?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type GetDocumentAnalysisInput = {
|
|
52
|
+
jobId: string;
|
|
53
|
+
maxResults?: number;
|
|
54
|
+
nextToken?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type StartDocumentTextDetectionInput = {
|
|
58
|
+
bucket: string;
|
|
59
|
+
name: string;
|
|
60
|
+
version?: string;
|
|
61
|
+
clientRequestToken?: string;
|
|
62
|
+
jobTag?: string;
|
|
63
|
+
notificationChannel?: {
|
|
64
|
+
snsTopicArn: string;
|
|
65
|
+
roleArn: string;
|
|
66
|
+
};
|
|
67
|
+
outputConfig?: {
|
|
68
|
+
s3Bucket: string;
|
|
69
|
+
s3Prefix?: string;
|
|
70
|
+
};
|
|
71
|
+
kmsKeyId?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type GetDocumentTextDetectionInput = {
|
|
75
|
+
jobId: string;
|
|
76
|
+
maxResults?: number;
|
|
77
|
+
nextToken?: string;
|
|
78
|
+
};
|