triangle-utils 1.4.98 → 1.4.100
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 +13 -0
- package/dist/src/UtilsBedrock.js +57 -51
- package/dist/src/UtilsS3.d.ts +4 -2
- package/dist/src/UtilsS3.js +8 -4
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +69 -51
- package/src/UtilsS3.ts +11 -5
|
@@ -19,6 +19,19 @@ export declare class UtilsBedrock {
|
|
|
19
19
|
web?: boolean;
|
|
20
20
|
cache_period?: "5m" | "1h";
|
|
21
21
|
}): Promise<string | undefined>;
|
|
22
|
+
claude_invoke(model_id: string, messages: {
|
|
23
|
+
role: Role;
|
|
24
|
+
text: string;
|
|
25
|
+
pdf?: string;
|
|
26
|
+
}[], options?: {
|
|
27
|
+
system_prompt?: string;
|
|
28
|
+
max_tokens?: number;
|
|
29
|
+
print_usage?: boolean;
|
|
30
|
+
print_content?: boolean;
|
|
31
|
+
json_format?: Record<string, any>;
|
|
32
|
+
web?: boolean;
|
|
33
|
+
cache_period?: "5m" | "1h";
|
|
34
|
+
}): Promise<string | undefined>;
|
|
22
35
|
nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
|
|
23
36
|
llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
24
37
|
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
|
@@ -76,57 +76,63 @@ export class UtilsBedrock {
|
|
|
76
76
|
}
|
|
77
77
|
return undefined;
|
|
78
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
|
-
|
|
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
|
-
|
|
79
|
+
async claude_invoke(model_id, messages, options = {}) {
|
|
80
|
+
try {
|
|
81
|
+
const message_params = [];
|
|
82
|
+
for (const message of messages) {
|
|
83
|
+
const content = [
|
|
84
|
+
{
|
|
85
|
+
type: "text",
|
|
86
|
+
text: message.text
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
if (message.pdf !== undefined) {
|
|
90
|
+
content.push({
|
|
91
|
+
type: "document",
|
|
92
|
+
source: {
|
|
93
|
+
type: "base64",
|
|
94
|
+
media_type: "application/pdf",
|
|
95
|
+
data: message.pdf
|
|
96
|
+
},
|
|
97
|
+
title: "Attachment",
|
|
98
|
+
citations: { "enabled": false },
|
|
99
|
+
cache_control: { "type": "ephemeral" }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
message_params.push({
|
|
103
|
+
role: message.role,
|
|
104
|
+
content: content
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const response = await this.bedrock_runtime.invokeModel({
|
|
108
|
+
modelId: model_id,
|
|
109
|
+
body: JSON.stringify({
|
|
110
|
+
messages: message_params,
|
|
111
|
+
system: options.system_prompt,
|
|
112
|
+
tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
|
|
113
|
+
max_tokens: options.max_tokens || 1000,
|
|
114
|
+
temperature: 0,
|
|
115
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
const body = JSON.parse(this.text_decoder.decode(response.body));
|
|
119
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
120
|
+
console.log(body.usage);
|
|
121
|
+
}
|
|
122
|
+
if (options.print_content !== undefined && options.print_content) {
|
|
123
|
+
console.log(body.content);
|
|
124
|
+
}
|
|
125
|
+
const text = body.content.filter((content) => content.type === "text")[0].text;
|
|
126
|
+
return text;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof Error) {
|
|
130
|
+
console.log(error.stack);
|
|
131
|
+
}
|
|
132
|
+
console.log("Failed to get from Bedrock.");
|
|
133
|
+
}
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
130
136
|
async nova_invoke(model_id, prompt) {
|
|
131
137
|
for (let i = 0; i < 3; i++) {
|
|
132
138
|
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
|
@@ -100,57 +100,75 @@ export class UtilsBedrock {
|
|
|
100
100
|
return undefined
|
|
101
101
|
}
|
|
102
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
103
|
+
async claude_invoke(
|
|
104
|
+
model_id : string,
|
|
105
|
+
messages : { role : Role, text : string, pdf? : string }[],
|
|
106
|
+
options : {
|
|
107
|
+
system_prompt? : string,
|
|
108
|
+
max_tokens? : number,
|
|
109
|
+
print_usage? : boolean,
|
|
110
|
+
print_content? : boolean,
|
|
111
|
+
json_format? : Record<string, any>,
|
|
112
|
+
web? : boolean,
|
|
113
|
+
cache_period? : "5m" | "1h"
|
|
114
|
+
} = {}
|
|
115
|
+
) : Promise<string | undefined> {
|
|
116
|
+
try {
|
|
117
|
+
const message_params : MessageParam[] = []
|
|
118
|
+
for (const message of messages) {
|
|
119
|
+
const content : ContentBlockParam[] = [
|
|
120
|
+
{
|
|
121
|
+
type : "text",
|
|
122
|
+
text : message.text
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
if (message.pdf !== undefined) {
|
|
126
|
+
content.push({
|
|
127
|
+
type: "document",
|
|
128
|
+
source: {
|
|
129
|
+
type: "base64",
|
|
130
|
+
media_type: "application/pdf",
|
|
131
|
+
data: message.pdf
|
|
132
|
+
},
|
|
133
|
+
title: "Attachment",
|
|
134
|
+
citations: { "enabled": false },
|
|
135
|
+
cache_control: {"type": "ephemeral"}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
message_params.push({
|
|
139
|
+
role : message.role,
|
|
140
|
+
content : content
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
const response = await this.bedrock_runtime.invokeModel({
|
|
145
|
+
modelId : model_id,
|
|
146
|
+
body : JSON.stringify({
|
|
147
|
+
messages : message_params,
|
|
148
|
+
system : options.system_prompt,
|
|
149
|
+
tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
|
|
150
|
+
max_tokens: options.max_tokens || 1000,
|
|
151
|
+
temperature: 0,
|
|
152
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
const body = JSON.parse(this.text_decoder.decode(response.body))
|
|
156
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
157
|
+
console.log(body.usage)
|
|
158
|
+
}
|
|
159
|
+
if (options.print_content !== undefined && options.print_content) {
|
|
160
|
+
console.log(body.content)
|
|
161
|
+
}
|
|
162
|
+
const text = body.content.filter((content : any) => content.type === "text")[0].text
|
|
163
|
+
return text
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error instanceof Error) {
|
|
166
|
+
console.log(error.stack)
|
|
167
|
+
}
|
|
168
|
+
console.log("Failed to get from Bedrock.")
|
|
169
|
+
}
|
|
170
|
+
return undefined
|
|
171
|
+
}
|
|
154
172
|
|
|
155
173
|
async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
|
|
156
174
|
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
|
}
|