triangle-utils 1.4.101 → 1.4.103
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 +3 -0
- package/dist/src/UtilsBedrock.js +82 -30
- package/dist/src/f.js +5 -3
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +82 -30
- package/src/f.ts +8 -4
|
@@ -35,5 +35,8 @@ export declare class UtilsBedrock {
|
|
|
35
35
|
llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
36
36
|
gpt_converse(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
37
37
|
titan_invoke(text: string): Promise<number[] | undefined>;
|
|
38
|
+
cohere_invoke(model_id: string, text: string, options?: {
|
|
39
|
+
input_type_id?: string;
|
|
40
|
+
}): Promise<number[] | undefined>;
|
|
38
41
|
}
|
|
39
42
|
export {};
|
package/dist/src/UtilsBedrock.js
CHANGED
|
@@ -78,39 +78,60 @@ export class UtilsBedrock {
|
|
|
78
78
|
}
|
|
79
79
|
async claude_invoke(model_id, messages, options = {}) {
|
|
80
80
|
try {
|
|
81
|
-
const message_params = []
|
|
82
|
-
for (const message of messages) {
|
|
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
|
-
if (options.print) {
|
|
108
|
-
|
|
109
|
-
}
|
|
81
|
+
// const message_params : MessageParam[] = []
|
|
82
|
+
// for (const message of messages) {
|
|
83
|
+
// const content : ContentBlockParam[] = [
|
|
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
|
+
// if (options.print) {
|
|
108
|
+
// console.log("Constructed messages.")
|
|
109
|
+
// }
|
|
110
110
|
const request = {
|
|
111
111
|
modelId: model_id,
|
|
112
112
|
body: JSON.stringify({
|
|
113
|
-
messages:
|
|
113
|
+
messages: messages.map(message => ({
|
|
114
|
+
role: message.role,
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
type: "text",
|
|
118
|
+
text: message.text
|
|
119
|
+
},
|
|
120
|
+
...(message.pdf !== undefined ? [
|
|
121
|
+
{
|
|
122
|
+
type: "document",
|
|
123
|
+
source: {
|
|
124
|
+
type: "base64",
|
|
125
|
+
media_type: "application/pdf",
|
|
126
|
+
data: message.pdf
|
|
127
|
+
},
|
|
128
|
+
title: "Attachment",
|
|
129
|
+
citations: { "enabled": false },
|
|
130
|
+
cache_control: { "type": "ephemeral" }
|
|
131
|
+
}
|
|
132
|
+
] : [])
|
|
133
|
+
]
|
|
134
|
+
})),
|
|
114
135
|
system: options.system_prompt,
|
|
115
136
|
tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
|
|
116
137
|
max_tokens: options.max_tokens || 1000,
|
|
@@ -251,4 +272,35 @@ export class UtilsBedrock {
|
|
|
251
272
|
console.log("Failed to get from Bedrock, quitting.");
|
|
252
273
|
return undefined;
|
|
253
274
|
}
|
|
275
|
+
async cohere_invoke(model_id, text, options = {}) {
|
|
276
|
+
try {
|
|
277
|
+
const output = await this.bedrock_runtime.invokeModel({
|
|
278
|
+
modelId: model_id,
|
|
279
|
+
body: JSON.stringify({
|
|
280
|
+
input_type: options.input_type_id || "search_document",
|
|
281
|
+
inputs: [
|
|
282
|
+
{
|
|
283
|
+
content: [
|
|
284
|
+
{ type: "text", text: text }
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
output_dimension: 1024,
|
|
289
|
+
truncate: "RIGHT",
|
|
290
|
+
max_tokens: 128000
|
|
291
|
+
}),
|
|
292
|
+
contentType: "application/json"
|
|
293
|
+
});
|
|
294
|
+
const response = JSON.parse(this.text_decoder.decode(output.body));
|
|
295
|
+
const coordinates = response.embeddings.float[0];
|
|
296
|
+
if (coordinates !== undefined && Array.isArray(coordinates) && coordinates.every((i) => typeof i === "number")) {
|
|
297
|
+
return coordinates;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
console.log(error.stack);
|
|
302
|
+
console.log("Failed to get from Bedrock.");
|
|
303
|
+
}
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
254
306
|
}
|
package/dist/src/f.js
CHANGED
|
@@ -15,9 +15,9 @@ const config = {
|
|
|
15
15
|
};
|
|
16
16
|
console.log(config);
|
|
17
17
|
const utils = new TriangleUtils(config);
|
|
18
|
-
const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/"
|
|
19
|
-
const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile: true })
|
|
20
|
-
console.log(raw_s3_ids)
|
|
18
|
+
// const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/"
|
|
19
|
+
// const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile : true })
|
|
20
|
+
// console.log(raw_s3_ids)
|
|
21
21
|
// const text = await utils.xai.grok_simple_query("grok-4.3", "Find the X username corresponding to the candidate of the committee \"Darializa for Congress\"", {
|
|
22
22
|
// print_usage : true,
|
|
23
23
|
// json_format : {
|
|
@@ -232,3 +232,5 @@ console.log(raw_s3_ids);
|
|
|
232
232
|
// }
|
|
233
233
|
// )
|
|
234
234
|
// console.log(response)
|
|
235
|
+
const coordinates = await utils.bedrock.cohere_invoke("global.cohere.embed-v4:0", "yerrp");
|
|
236
|
+
console.log(coordinates);
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -113,40 +113,61 @@ export class UtilsBedrock {
|
|
|
113
113
|
} = {}
|
|
114
114
|
) : Promise<string | undefined> {
|
|
115
115
|
try {
|
|
116
|
-
const message_params : MessageParam[] = []
|
|
117
|
-
for (const message of messages) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
// const message_params : MessageParam[] = []
|
|
117
|
+
// for (const message of messages) {
|
|
118
|
+
// const content : ContentBlockParam[] = [
|
|
119
|
+
// {
|
|
120
|
+
// type : "text",
|
|
121
|
+
// text : message.text
|
|
122
|
+
// }
|
|
123
|
+
// ]
|
|
124
|
+
// if (message.pdf !== undefined) {
|
|
125
|
+
// content.push({
|
|
126
|
+
// type: "document",
|
|
127
|
+
// source: {
|
|
128
|
+
// type: "base64",
|
|
129
|
+
// media_type: "application/pdf",
|
|
130
|
+
// data: message.pdf
|
|
131
|
+
// },
|
|
132
|
+
// title: "Attachment",
|
|
133
|
+
// citations: { "enabled": false },
|
|
134
|
+
// cache_control: {"type": "ephemeral"}
|
|
135
|
+
// })
|
|
136
|
+
// }
|
|
137
|
+
// message_params.push({
|
|
138
|
+
// role : message.role,
|
|
139
|
+
// content : content
|
|
140
|
+
// })
|
|
141
141
|
|
|
142
|
-
}
|
|
143
|
-
if (options.print) {
|
|
144
|
-
|
|
145
|
-
}
|
|
142
|
+
// }
|
|
143
|
+
// if (options.print) {
|
|
144
|
+
// console.log("Constructed messages.")
|
|
145
|
+
// }
|
|
146
146
|
const request = {
|
|
147
147
|
modelId : model_id,
|
|
148
148
|
body : JSON.stringify({
|
|
149
|
-
messages :
|
|
149
|
+
messages : messages.map(message => ({
|
|
150
|
+
role : message.role,
|
|
151
|
+
content : [
|
|
152
|
+
{
|
|
153
|
+
type : "text",
|
|
154
|
+
text : message.text
|
|
155
|
+
},
|
|
156
|
+
...(message.pdf !== undefined ? [
|
|
157
|
+
{
|
|
158
|
+
type: "document",
|
|
159
|
+
source: {
|
|
160
|
+
type: "base64",
|
|
161
|
+
media_type: "application/pdf",
|
|
162
|
+
data: message.pdf
|
|
163
|
+
},
|
|
164
|
+
title: "Attachment",
|
|
165
|
+
citations: { "enabled" : false },
|
|
166
|
+
cache_control: {"type": "ephemeral"}
|
|
167
|
+
}
|
|
168
|
+
] : [])
|
|
169
|
+
]
|
|
170
|
+
})),
|
|
150
171
|
system : options.system_prompt,
|
|
151
172
|
tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
|
|
152
173
|
max_tokens: options.max_tokens || 1000,
|
|
@@ -287,4 +308,35 @@ export class UtilsBedrock {
|
|
|
287
308
|
return undefined
|
|
288
309
|
}
|
|
289
310
|
|
|
311
|
+
async cohere_invoke(model_id : string, text : string, options : { input_type_id? : string } = {}) : Promise<number[] | undefined> {
|
|
312
|
+
try {
|
|
313
|
+
const output = await this.bedrock_runtime.invokeModel({
|
|
314
|
+
modelId : model_id,
|
|
315
|
+
body : JSON.stringify({
|
|
316
|
+
input_type: options.input_type_id || "search_document",
|
|
317
|
+
inputs: [
|
|
318
|
+
{
|
|
319
|
+
content: [
|
|
320
|
+
{ type : "text", text : text }
|
|
321
|
+
]
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
output_dimension: 1024,
|
|
325
|
+
truncate: "RIGHT",
|
|
326
|
+
max_tokens: 128000
|
|
327
|
+
}),
|
|
328
|
+
contentType : "application/json"
|
|
329
|
+
})
|
|
330
|
+
const response = JSON.parse(this.text_decoder.decode(output.body))
|
|
331
|
+
const coordinates = response.embeddings.float[0]
|
|
332
|
+
if (coordinates !== undefined && Array.isArray(coordinates) && coordinates.every((i : any) => typeof i === "number")) {
|
|
333
|
+
return coordinates
|
|
334
|
+
}
|
|
335
|
+
} catch (error : any) {
|
|
336
|
+
console.log(error.stack)
|
|
337
|
+
console.log("Failed to get from Bedrock.")
|
|
338
|
+
}
|
|
339
|
+
return undefined
|
|
340
|
+
}
|
|
341
|
+
|
|
290
342
|
}
|
package/src/f.ts
CHANGED
|
@@ -24,10 +24,10 @@ console.log(config)
|
|
|
24
24
|
|
|
25
25
|
const utils = new TriangleUtils(config)
|
|
26
26
|
|
|
27
|
-
const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/"
|
|
28
|
-
const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile : true })
|
|
27
|
+
// const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/"
|
|
28
|
+
// const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile : true })
|
|
29
29
|
|
|
30
|
-
console.log(raw_s3_ids)
|
|
30
|
+
// console.log(raw_s3_ids)
|
|
31
31
|
|
|
32
32
|
// const text = await utils.xai.grok_simple_query("grok-4.3", "Find the X username corresponding to the candidate of the committee \"Darializa for Congress\"", {
|
|
33
33
|
// print_usage : true,
|
|
@@ -268,4 +268,8 @@ console.log(raw_s3_ids)
|
|
|
268
268
|
// print_usage : true
|
|
269
269
|
// }
|
|
270
270
|
// )
|
|
271
|
-
// console.log(response)
|
|
271
|
+
// console.log(response)
|
|
272
|
+
|
|
273
|
+
const coordinates = await utils.bedrock.cohere_invoke("global.cohere.embed-v4:0", "yerrp")
|
|
274
|
+
|
|
275
|
+
console.log(coordinates)
|