triangle-utils 1.4.173 → 1.4.175
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.js +30 -27
- package/package.json +2 -3
- package/src/UtilsBedrock.ts +29 -26
package/dist/src/UtilsBedrock.js
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 { TriangleUtils } from "./index.js";
|
|
3
4
|
const message_roles = ["user", "assistant", "system"];
|
|
4
5
|
export function is_message_role(message_role) {
|
|
5
6
|
return message_roles.includes(message_role);
|
|
@@ -252,34 +253,36 @@ export class UtilsBedrock {
|
|
|
252
253
|
return undefined;
|
|
253
254
|
}
|
|
254
255
|
async cohere_invoke(model_id, text, options = {}) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
256
|
+
for (let i = 0; i < 3; i++) {
|
|
257
|
+
try {
|
|
258
|
+
const output = await this.bedrock_runtime.invokeModel({
|
|
259
|
+
modelId: model_id,
|
|
260
|
+
body: JSON.stringify({
|
|
261
|
+
input_type: options.input_type_id || "search_document",
|
|
262
|
+
inputs: [
|
|
263
|
+
{
|
|
264
|
+
content: [
|
|
265
|
+
{ type: "text", text: text }
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
output_dimension: 1024,
|
|
270
|
+
truncate: "RIGHT",
|
|
271
|
+
max_tokens: 128000
|
|
272
|
+
}),
|
|
273
|
+
contentType: "application/json"
|
|
274
|
+
});
|
|
275
|
+
const response = JSON.parse(this.text_decoder.decode(output.body));
|
|
276
|
+
const coordinates = response.embeddings.float[0];
|
|
277
|
+
if (coordinates !== undefined && Array.isArray(coordinates) && coordinates.every((i) => typeof i === "number")) {
|
|
278
|
+
return coordinates;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
console.log(error.message);
|
|
283
|
+
await TriangleUtils.wait(5000);
|
|
277
284
|
}
|
|
278
285
|
}
|
|
279
|
-
|
|
280
|
-
console.log(error.stack);
|
|
281
|
-
console.log("Failed to get from Bedrock.");
|
|
282
|
-
}
|
|
283
|
-
return undefined;
|
|
286
|
+
throw new Error("Failed to Cohere");
|
|
284
287
|
}
|
|
285
288
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.175",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"googleapis": "^170.0.0",
|
|
37
37
|
"jsdom": "^29.0.1",
|
|
38
38
|
"pg": "^8.23.0",
|
|
39
|
-
"scrapingbee": "^1.8.2"
|
|
40
|
-
"triangle-types": "^1.0.259"
|
|
39
|
+
"scrapingbee": "^1.8.2"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@eslint/js": "^9.39.2",
|
package/src/UtilsBedrock.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BedrockRuntime, InvokeModelCommandInput } from "@aws-sdk/client-bedrock-runtime"
|
|
2
2
|
import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
|
|
3
3
|
import { ContentBlockParam, MessageCreateParams, MessageParam, OutputConfig } from "@anthropic-ai/sdk/resources"
|
|
4
|
+
import { TriangleUtils } from "."
|
|
4
5
|
|
|
5
6
|
const message_roles = ["user", "assistant", "system"] as const
|
|
6
7
|
|
|
@@ -284,34 +285,36 @@ export class UtilsBedrock {
|
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
async cohere_invoke(model_id : string, text : string, options : { input_type_id? : string } = {}) : Promise<number[] | undefined> {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
288
|
+
for (let i = 0; i < 3; i++) {
|
|
289
|
+
try {
|
|
290
|
+
const output = await this.bedrock_runtime.invokeModel({
|
|
291
|
+
modelId : model_id,
|
|
292
|
+
body : JSON.stringify({
|
|
293
|
+
input_type: options.input_type_id || "search_document",
|
|
294
|
+
inputs: [
|
|
295
|
+
{
|
|
296
|
+
content: [
|
|
297
|
+
{ type : "text", text : text }
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
output_dimension: 1024,
|
|
302
|
+
truncate: "RIGHT",
|
|
303
|
+
max_tokens: 128000
|
|
304
|
+
}),
|
|
305
|
+
contentType : "application/json"
|
|
306
|
+
})
|
|
307
|
+
const response = JSON.parse(this.text_decoder.decode(output.body))
|
|
308
|
+
const coordinates = response.embeddings.float[0]
|
|
309
|
+
if (coordinates !== undefined && Array.isArray(coordinates) && coordinates.every((i : any) => typeof i === "number")) {
|
|
310
|
+
return coordinates
|
|
311
|
+
}
|
|
312
|
+
} catch (error : any) {
|
|
313
|
+
console.log(error.message)
|
|
314
|
+
await TriangleUtils.wait(5000)
|
|
309
315
|
}
|
|
310
|
-
} catch (error : any) {
|
|
311
|
-
console.log(error.stack)
|
|
312
|
-
console.log("Failed to get from Bedrock.")
|
|
313
316
|
}
|
|
314
|
-
|
|
317
|
+
throw new Error("Failed to Cohere")
|
|
315
318
|
}
|
|
316
319
|
|
|
317
320
|
}
|