triangle-utils 1.4.51 → 1.4.52
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 +38 -41
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +36 -39
package/dist/src/UtilsBedrock.js
CHANGED
|
@@ -7,50 +7,47 @@ export class UtilsBedrock {
|
|
|
7
7
|
this.text_decoder = new TextDecoder();
|
|
8
8
|
}
|
|
9
9
|
async claude_invoke(model_id, prompt, attachment_pdf, options = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.log(body.usage);
|
|
43
|
-
}
|
|
44
|
-
return body.content[0].text;
|
|
10
|
+
try {
|
|
11
|
+
const response = await this.bedrock.invokeModel({
|
|
12
|
+
modelId: model_id,
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
messages: [{
|
|
15
|
+
role: "user",
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
type: "text",
|
|
19
|
+
text: prompt
|
|
20
|
+
},
|
|
21
|
+
...(attachment_pdf !== undefined ? [{
|
|
22
|
+
type: "document",
|
|
23
|
+
source: {
|
|
24
|
+
type: "base64",
|
|
25
|
+
media_type: "application/pdf",
|
|
26
|
+
data: attachment_pdf
|
|
27
|
+
},
|
|
28
|
+
title: "Attachment",
|
|
29
|
+
citations: { "enabled": false },
|
|
30
|
+
cache_control: { "type": "ephemeral" }
|
|
31
|
+
}] : [])
|
|
32
|
+
]
|
|
33
|
+
}],
|
|
34
|
+
max_tokens: options.max_tokens || 1000,
|
|
35
|
+
temperature: 0,
|
|
36
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
const body = JSON.parse(this.text_decoder.decode(response.body));
|
|
40
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
41
|
+
console.log(body.usage);
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.log(
|
|
43
|
+
return body.content[0].text;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
console.log(error.stack);
|
|
51
48
|
}
|
|
49
|
+
console.log("Failed to get from Bedrock.");
|
|
52
50
|
}
|
|
53
|
-
console.log("Failed to get from Bedrock, quitting.");
|
|
54
51
|
return undefined;
|
|
55
52
|
}
|
|
56
53
|
async nova_invoke(model_id, prompt) {
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -19,49 +19,46 @@ export class UtilsBedrock {
|
|
|
19
19
|
print_usage? : boolean
|
|
20
20
|
} = {}
|
|
21
21
|
) : Promise<string | undefined> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
try {
|
|
23
|
+
const response = await this.bedrock.invokeModel({
|
|
24
|
+
modelId : model_id,
|
|
25
|
+
body : JSON.stringify({
|
|
26
|
+
messages : [{
|
|
27
|
+
role : "user",
|
|
28
|
+
content : [
|
|
29
|
+
{
|
|
30
|
+
type : "text",
|
|
31
|
+
text : prompt
|
|
32
|
+
},
|
|
33
|
+
...(attachment_pdf !== undefined ? [{
|
|
34
|
+
type: "document",
|
|
35
|
+
source: {
|
|
36
|
+
type: "base64",
|
|
37
|
+
media_type: "application/pdf",
|
|
38
|
+
data: attachment_pdf
|
|
33
39
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
cache_control: {"type": "ephemeral"}
|
|
44
|
-
}] : [])
|
|
45
|
-
]
|
|
46
|
-
}],
|
|
47
|
-
max_tokens: options.max_tokens || 1000,
|
|
48
|
-
temperature: 0,
|
|
49
|
-
anthropic_version: "bedrock-2023-05-31"
|
|
50
|
-
})
|
|
40
|
+
title: "Attachment",
|
|
41
|
+
citations: { "enabled": false },
|
|
42
|
+
cache_control: {"type": "ephemeral"}
|
|
43
|
+
}] : [])
|
|
44
|
+
]
|
|
45
|
+
}],
|
|
46
|
+
max_tokens: options.max_tokens || 1000,
|
|
47
|
+
temperature: 0,
|
|
48
|
+
anthropic_version: "bedrock-2023-05-31"
|
|
51
49
|
})
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return body.content[0].text
|
|
57
|
-
} catch (error) {
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
console.log(error.stack)
|
|
60
|
-
}
|
|
61
|
-
console.log("Failed to get from Bedrock.")
|
|
50
|
+
})
|
|
51
|
+
const body = JSON.parse(this.text_decoder.decode(response.body))
|
|
52
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
53
|
+
console.log(body.usage)
|
|
62
54
|
}
|
|
55
|
+
return body.content[0].text
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error instanceof Error) {
|
|
58
|
+
console.log(error.stack)
|
|
59
|
+
}
|
|
60
|
+
console.log("Failed to get from Bedrock.")
|
|
63
61
|
}
|
|
64
|
-
console.log("Failed to get from Bedrock, quitting.")
|
|
65
62
|
return undefined
|
|
66
63
|
}
|
|
67
64
|
|