triangle-utils 1.4.46 → 1.4.47
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 -0
- package/dist/src/UtilsBedrock.js +46 -0
- package/dist/src/f.js +1 -1
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +46 -0
- package/src/f.ts +1 -1
|
@@ -2,6 +2,7 @@ export declare class UtilsBedrock {
|
|
|
2
2
|
private readonly bedrock;
|
|
3
3
|
private readonly text_decoder;
|
|
4
4
|
constructor(region: string);
|
|
5
|
+
claude_sonnet_invoke(model_id: string, prompt: string, attachment_pdf?: string): Promise<string | undefined>;
|
|
5
6
|
nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
|
|
6
7
|
llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
7
8
|
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
|
@@ -6,6 +6,52 @@ export class UtilsBedrock {
|
|
|
6
6
|
this.bedrock = new BedrockRuntime({ region: region });
|
|
7
7
|
this.text_decoder = new TextDecoder();
|
|
8
8
|
}
|
|
9
|
+
async claude_sonnet_invoke(model_id, prompt, attachment_pdf) {
|
|
10
|
+
for (let i = 0; i < 3; i++) {
|
|
11
|
+
try {
|
|
12
|
+
const response = await this.bedrock.invokeModel({
|
|
13
|
+
modelId: model_id,
|
|
14
|
+
body: JSON.stringify({
|
|
15
|
+
messages: [{
|
|
16
|
+
role: "user",
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: prompt
|
|
21
|
+
},
|
|
22
|
+
...(attachment_pdf !== undefined ? [{
|
|
23
|
+
document: {
|
|
24
|
+
type: "document",
|
|
25
|
+
source: {
|
|
26
|
+
type: "base64",
|
|
27
|
+
media_type: "application/pdf",
|
|
28
|
+
data: attachment_pdf
|
|
29
|
+
},
|
|
30
|
+
title: "Attachment",
|
|
31
|
+
citations: { "enabled": false },
|
|
32
|
+
cache_control: { "type": "ephemeral" }
|
|
33
|
+
}
|
|
34
|
+
}] : [])
|
|
35
|
+
]
|
|
36
|
+
}],
|
|
37
|
+
max_tokens: 200,
|
|
38
|
+
temperature: 0.5,
|
|
39
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
const body = JSON.parse(this.text_decoder.decode(response.body));
|
|
43
|
+
return body.content[0].text;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
console.log(error.stack);
|
|
48
|
+
}
|
|
49
|
+
console.log("Failed to get from Bedrock.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
console.log("Failed to get from Bedrock, quitting.");
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
9
55
|
async nova_invoke(model_id, prompt) {
|
|
10
56
|
for (let i = 0; i < 3; i++) {
|
|
11
57
|
try {
|
package/dist/src/f.js
CHANGED
|
@@ -16,5 +16,5 @@ const config = {
|
|
|
16
16
|
const utils = new TriangleUtils(config);
|
|
17
17
|
// const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
|
|
18
18
|
// console.log(foods)
|
|
19
|
-
const text = await utils.bedrock.
|
|
19
|
+
const text = await utils.bedrock.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi");
|
|
20
20
|
console.log(text);
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -10,6 +10,52 @@ export class UtilsBedrock {
|
|
|
10
10
|
this.text_decoder = new TextDecoder()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
async claude_sonnet_invoke(model_id : string, prompt : string, attachment_pdf? : string) : Promise<string | undefined> {
|
|
14
|
+
for (let i = 0; i < 3; i++) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await this.bedrock.invokeModel({
|
|
17
|
+
modelId : model_id,
|
|
18
|
+
body : JSON.stringify({
|
|
19
|
+
messages : [{
|
|
20
|
+
role : "user",
|
|
21
|
+
content : [
|
|
22
|
+
{
|
|
23
|
+
type : "text",
|
|
24
|
+
text : prompt
|
|
25
|
+
},
|
|
26
|
+
...(attachment_pdf !== undefined ? [{
|
|
27
|
+
document : {
|
|
28
|
+
type: "document",
|
|
29
|
+
source: {
|
|
30
|
+
type: "base64",
|
|
31
|
+
media_type: "application/pdf",
|
|
32
|
+
data: attachment_pdf
|
|
33
|
+
},
|
|
34
|
+
title: "Attachment",
|
|
35
|
+
citations: { "enabled": false },
|
|
36
|
+
cache_control: {"type": "ephemeral"}
|
|
37
|
+
}
|
|
38
|
+
}] : [])
|
|
39
|
+
]
|
|
40
|
+
}],
|
|
41
|
+
max_tokens: 200,
|
|
42
|
+
temperature: 0.5,
|
|
43
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
const body = JSON.parse(this.text_decoder.decode(response.body))
|
|
47
|
+
return body.content[0].text
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
console.log(error.stack)
|
|
51
|
+
}
|
|
52
|
+
console.log("Failed to get from Bedrock.")
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
console.log("Failed to get from Bedrock, quitting.")
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
13
59
|
async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
|
|
14
60
|
for (let i = 0; i < 3; i++) {
|
|
15
61
|
try {
|
package/src/f.ts
CHANGED
|
@@ -27,5 +27,5 @@ const utils = new TriangleUtils(config)
|
|
|
27
27
|
// console.log(foods)
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
const text = await utils.bedrock.
|
|
30
|
+
const text = await utils.bedrock.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi")
|
|
31
31
|
console.log(text)
|