triangle-utils 1.4.97 → 1.4.99
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/src/UtilsBedrock.d.ts +1 -4
- package/dist/src/UtilsBedrock.js +78 -53
- package/dist/src/UtilsS3.d.ts +4 -2
- package/dist/src/UtilsS3.js +8 -4
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +81 -61
- package/src/UtilsS3.ts +11 -5
|
@@ -9,6 +9,7 @@ export declare class UtilsBedrock {
|
|
|
9
9
|
claude_converse(model_id: string, messages: {
|
|
10
10
|
role: Role;
|
|
11
11
|
text: string;
|
|
12
|
+
pdf?: string;
|
|
12
13
|
}[], options?: {
|
|
13
14
|
system_prompt?: string;
|
|
14
15
|
max_tokens?: number;
|
|
@@ -18,10 +19,6 @@ export declare class UtilsBedrock {
|
|
|
18
19
|
web?: boolean;
|
|
19
20
|
cache_period?: "5m" | "1h";
|
|
20
21
|
}): Promise<string | undefined>;
|
|
21
|
-
claude_invoke(model_id: string, prompt: string, attachment_pdf?: string, options?: {
|
|
22
|
-
max_tokens?: number;
|
|
23
|
-
print_usage?: boolean;
|
|
24
|
-
}): Promise<string | undefined>;
|
|
25
22
|
nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
|
|
26
23
|
llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
27
24
|
gpt_converse(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
package/dist/src/UtilsBedrock.js
CHANGED
|
@@ -15,17 +15,35 @@ export class UtilsBedrock {
|
|
|
15
15
|
}
|
|
16
16
|
async claude_converse(model_id, messages, options = {}) {
|
|
17
17
|
try {
|
|
18
|
+
const message_params = [];
|
|
19
|
+
for (const message of messages) {
|
|
20
|
+
const content = [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: message.text
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
if (message.pdf !== undefined) {
|
|
27
|
+
content.push({
|
|
28
|
+
type: "document",
|
|
29
|
+
source: {
|
|
30
|
+
type: "base64",
|
|
31
|
+
media_type: "application/pdf",
|
|
32
|
+
data: message.pdf
|
|
33
|
+
},
|
|
34
|
+
title: "Attachment",
|
|
35
|
+
citations: { "enabled": false },
|
|
36
|
+
cache_control: { "type": "ephemeral" }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
message_params.push({
|
|
40
|
+
role: message.role,
|
|
41
|
+
content: content
|
|
42
|
+
});
|
|
43
|
+
}
|
|
18
44
|
const response = await this.anthropic_bedrock_mantle.messages.create({
|
|
19
45
|
model: model_id,
|
|
20
|
-
messages:
|
|
21
|
-
role: message.role,
|
|
22
|
-
content: [
|
|
23
|
-
{
|
|
24
|
-
type: "text",
|
|
25
|
-
text: message.text
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
})),
|
|
46
|
+
messages: message_params,
|
|
29
47
|
system: options.system_prompt,
|
|
30
48
|
tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
|
|
31
49
|
max_tokens: options.max_tokens || 1000,
|
|
@@ -58,50 +76,57 @@ export class UtilsBedrock {
|
|
|
58
76
|
}
|
|
59
77
|
return undefined;
|
|
60
78
|
}
|
|
61
|
-
async claude_invoke(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
79
|
+
// async claude_invoke(
|
|
80
|
+
// model_id : string,
|
|
81
|
+
// prompt : string,
|
|
82
|
+
// attachment_pdf? : string,
|
|
83
|
+
// options : {
|
|
84
|
+
// max_tokens? : number,
|
|
85
|
+
// print_usage? : boolean
|
|
86
|
+
// } = {}
|
|
87
|
+
// ) : Promise<string | undefined> {
|
|
88
|
+
// try {
|
|
89
|
+
// const response = await this.bedrock_runtime.invokeModel({
|
|
90
|
+
// modelId : model_id,
|
|
91
|
+
// body : JSON.stringify({
|
|
92
|
+
// messages : [{
|
|
93
|
+
// role : "user",
|
|
94
|
+
// content : [
|
|
95
|
+
// {
|
|
96
|
+
// type : "text",
|
|
97
|
+
// text : prompt
|
|
98
|
+
// },
|
|
99
|
+
// ...(attachment_pdf !== undefined ? [{
|
|
100
|
+
// type: "document",
|
|
101
|
+
// source: {
|
|
102
|
+
// type: "base64",
|
|
103
|
+
// media_type: "application/pdf",
|
|
104
|
+
// data: attachment_pdf
|
|
105
|
+
// },
|
|
106
|
+
// title: "Attachment",
|
|
107
|
+
// citations: { "enabled": false },
|
|
108
|
+
// cache_control: {"type": "ephemeral"}
|
|
109
|
+
// }] : [])
|
|
110
|
+
// ]
|
|
111
|
+
// }],
|
|
112
|
+
// max_tokens: options.max_tokens || 1000,
|
|
113
|
+
// temperature: 0,
|
|
114
|
+
// anthropic_version: "bedrock-2023-05-31"
|
|
115
|
+
// })
|
|
116
|
+
// })
|
|
117
|
+
// const body = JSON.parse(this.text_decoder.decode(response.body))
|
|
118
|
+
// if (options.print_usage !== undefined && options.print_usage) {
|
|
119
|
+
// console.log(body.usage)
|
|
120
|
+
// }
|
|
121
|
+
// return body.content[0].text
|
|
122
|
+
// } catch (error) {
|
|
123
|
+
// if (error instanceof Error) {
|
|
124
|
+
// console.log(error.stack)
|
|
125
|
+
// }
|
|
126
|
+
// console.log("Failed to get from Bedrock.")
|
|
127
|
+
// }
|
|
128
|
+
// return undefined
|
|
129
|
+
// }
|
|
105
130
|
async nova_invoke(model_id, prompt) {
|
|
106
131
|
for (let i = 0; i < 3; i++) {
|
|
107
132
|
try {
|
package/dist/src/UtilsS3.d.ts
CHANGED
|
@@ -52,9 +52,11 @@ export declare class UtilsS3 {
|
|
|
52
52
|
compile?: boolean;
|
|
53
53
|
}): Promise<string[]>;
|
|
54
54
|
create(s3_id: string, content: string | Buffer | Readable, options?: {
|
|
55
|
-
|
|
55
|
+
content_type_id?: string;
|
|
56
56
|
}): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
|
|
57
57
|
delete(s3_id: string): Promise<void>;
|
|
58
58
|
get_download_url(s3_id: string): Promise<string | undefined>;
|
|
59
|
-
get_upload_url(s3_id: string
|
|
59
|
+
get_upload_url(s3_id: string, options?: {
|
|
60
|
+
content_type_id?: string;
|
|
61
|
+
}): Promise<string | undefined>;
|
|
60
62
|
}
|
package/dist/src/UtilsS3.js
CHANGED
|
@@ -131,7 +131,7 @@ export class UtilsS3 {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
async create(s3_id, content, options = {}) {
|
|
134
|
-
const
|
|
134
|
+
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
|
|
135
135
|
const headers = await this.get_headers(s3_id);
|
|
136
136
|
if (headers !== undefined) {
|
|
137
137
|
return undefined;
|
|
@@ -143,7 +143,7 @@ export class UtilsS3 {
|
|
|
143
143
|
return await this.s3.putObject({
|
|
144
144
|
...s3_input,
|
|
145
145
|
Body: content,
|
|
146
|
-
ContentType:
|
|
146
|
+
ContentType: content_type_id
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
async delete(s3_id) {
|
|
@@ -166,12 +166,16 @@ export class UtilsS3 {
|
|
|
166
166
|
const url = await getSignedUrl(this.s3, command);
|
|
167
167
|
return url;
|
|
168
168
|
}
|
|
169
|
-
async get_upload_url(s3_id) {
|
|
169
|
+
async get_upload_url(s3_id, options = {}) {
|
|
170
|
+
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
|
|
170
171
|
const s3_input = get_s3_input(s3_id);
|
|
171
172
|
if (s3_input === undefined) {
|
|
172
173
|
return undefined;
|
|
173
174
|
}
|
|
174
|
-
const command = new PutObjectCommand(
|
|
175
|
+
const command = new PutObjectCommand({
|
|
176
|
+
...s3_input,
|
|
177
|
+
ContentType: content_type_id
|
|
178
|
+
});
|
|
175
179
|
const url = await getSignedUrl(this.s3, command);
|
|
176
180
|
return url;
|
|
177
181
|
}
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime"
|
|
2
2
|
import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
|
|
3
|
+
import { ContentBlockParam, MessageParam } from "@anthropic-ai/sdk/resources"
|
|
3
4
|
|
|
4
5
|
const roles = ["user", "assistant", "system"] as const
|
|
5
6
|
|
|
@@ -24,7 +25,7 @@ export class UtilsBedrock {
|
|
|
24
25
|
|
|
25
26
|
async claude_converse(
|
|
26
27
|
model_id : string,
|
|
27
|
-
messages : { role : Role, text : string }[],
|
|
28
|
+
messages : { role : Role, text : string, pdf? : string }[],
|
|
28
29
|
options : {
|
|
29
30
|
system_prompt? : string,
|
|
30
31
|
max_tokens? : number,
|
|
@@ -36,17 +37,36 @@ export class UtilsBedrock {
|
|
|
36
37
|
} = {}
|
|
37
38
|
) {
|
|
38
39
|
try {
|
|
40
|
+
const message_params : MessageParam[] = []
|
|
41
|
+
for (const message of messages) {
|
|
42
|
+
const content : ContentBlockParam[] = [
|
|
43
|
+
{
|
|
44
|
+
type : "text",
|
|
45
|
+
text : message.text
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
if (message.pdf !== undefined) {
|
|
49
|
+
content.push({
|
|
50
|
+
type: "document",
|
|
51
|
+
source: {
|
|
52
|
+
type: "base64",
|
|
53
|
+
media_type: "application/pdf",
|
|
54
|
+
data: message.pdf
|
|
55
|
+
},
|
|
56
|
+
title: "Attachment",
|
|
57
|
+
citations: { "enabled": false },
|
|
58
|
+
cache_control: {"type": "ephemeral"}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
message_params.push({
|
|
62
|
+
role : message.role,
|
|
63
|
+
content : content
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
}
|
|
39
67
|
const response = await this.anthropic_bedrock_mantle.messages.create({
|
|
40
68
|
model : model_id,
|
|
41
|
-
messages :
|
|
42
|
-
role : message.role,
|
|
43
|
-
content : [
|
|
44
|
-
{
|
|
45
|
-
type : "text",
|
|
46
|
-
text : message.text
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
})),
|
|
69
|
+
messages : message_params,
|
|
50
70
|
system : options.system_prompt,
|
|
51
71
|
tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
|
|
52
72
|
max_tokens : options.max_tokens || 1000,
|
|
@@ -80,57 +100,57 @@ export class UtilsBedrock {
|
|
|
80
100
|
return undefined
|
|
81
101
|
}
|
|
82
102
|
|
|
83
|
-
async claude_invoke(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
) : Promise<string | undefined> {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
103
|
+
// async claude_invoke(
|
|
104
|
+
// model_id : string,
|
|
105
|
+
// prompt : string,
|
|
106
|
+
// attachment_pdf? : string,
|
|
107
|
+
// options : {
|
|
108
|
+
// max_tokens? : number,
|
|
109
|
+
// print_usage? : boolean
|
|
110
|
+
// } = {}
|
|
111
|
+
// ) : Promise<string | undefined> {
|
|
112
|
+
// try {
|
|
113
|
+
// const response = await this.bedrock_runtime.invokeModel({
|
|
114
|
+
// modelId : model_id,
|
|
115
|
+
// body : JSON.stringify({
|
|
116
|
+
// messages : [{
|
|
117
|
+
// role : "user",
|
|
118
|
+
// content : [
|
|
119
|
+
// {
|
|
120
|
+
// type : "text",
|
|
121
|
+
// text : prompt
|
|
122
|
+
// },
|
|
123
|
+
// ...(attachment_pdf !== undefined ? [{
|
|
124
|
+
// type: "document",
|
|
125
|
+
// source: {
|
|
126
|
+
// type: "base64",
|
|
127
|
+
// media_type: "application/pdf",
|
|
128
|
+
// data: attachment_pdf
|
|
129
|
+
// },
|
|
130
|
+
// title: "Attachment",
|
|
131
|
+
// citations: { "enabled": false },
|
|
132
|
+
// cache_control: {"type": "ephemeral"}
|
|
133
|
+
// }] : [])
|
|
134
|
+
// ]
|
|
135
|
+
// }],
|
|
136
|
+
// max_tokens: options.max_tokens || 1000,
|
|
137
|
+
// temperature: 0,
|
|
138
|
+
// anthropic_version: "bedrock-2023-05-31"
|
|
139
|
+
// })
|
|
140
|
+
// })
|
|
141
|
+
// const body = JSON.parse(this.text_decoder.decode(response.body))
|
|
142
|
+
// if (options.print_usage !== undefined && options.print_usage) {
|
|
143
|
+
// console.log(body.usage)
|
|
144
|
+
// }
|
|
145
|
+
// return body.content[0].text
|
|
146
|
+
// } catch (error) {
|
|
147
|
+
// if (error instanceof Error) {
|
|
148
|
+
// console.log(error.stack)
|
|
149
|
+
// }
|
|
150
|
+
// console.log("Failed to get from Bedrock.")
|
|
151
|
+
// }
|
|
152
|
+
// return undefined
|
|
153
|
+
// }
|
|
134
154
|
|
|
135
155
|
async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
|
|
136
156
|
for (let i = 0; i < 3; i++) {
|
package/src/UtilsS3.ts
CHANGED
|
@@ -142,9 +142,9 @@ export class UtilsS3 {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
async create(s3_id : string, content : string | Buffer | Readable, options : {
|
|
145
|
-
|
|
145
|
+
content_type_id? : string
|
|
146
146
|
} = {}) {
|
|
147
|
-
const
|
|
147
|
+
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
|
|
148
148
|
|
|
149
149
|
const headers = await this.get_headers(s3_id)
|
|
150
150
|
if (headers !== undefined) {
|
|
@@ -157,7 +157,7 @@ export class UtilsS3 {
|
|
|
157
157
|
return await this.s3.putObject({
|
|
158
158
|
...s3_input,
|
|
159
159
|
Body : content,
|
|
160
|
-
ContentType :
|
|
160
|
+
ContentType : content_type_id
|
|
161
161
|
})
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -183,12 +183,18 @@ export class UtilsS3 {
|
|
|
183
183
|
return url
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
async get_upload_url(s3_id : string
|
|
186
|
+
async get_upload_url(s3_id : string, options : {
|
|
187
|
+
content_type_id? : string
|
|
188
|
+
} = {}) : Promise<string | undefined> {
|
|
189
|
+
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
|
|
187
190
|
const s3_input = get_s3_input(s3_id)
|
|
188
191
|
if (s3_input === undefined) {
|
|
189
192
|
return undefined
|
|
190
193
|
}
|
|
191
|
-
const command = new PutObjectCommand(
|
|
194
|
+
const command = new PutObjectCommand({
|
|
195
|
+
...s3_input,
|
|
196
|
+
ContentType : content_type_id
|
|
197
|
+
})
|
|
192
198
|
const url = await getSignedUrl(this.s3, command)
|
|
193
199
|
return url
|
|
194
200
|
}
|