triangle-utils 1.4.45 → 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.
@@ -2,6 +2,8 @@ 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>;
6
+ nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
5
7
  llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
6
8
  gpt_converse(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
7
9
  titan_invoke(text: string): Promise<number[] | undefined>;
@@ -6,6 +6,77 @@ 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
+ }
55
+ async nova_invoke(model_id, prompt) {
56
+ for (let i = 0; i < 3; i++) {
57
+ try {
58
+ const response = await this.bedrock.invokeModel({
59
+ modelId: model_id,
60
+ body: JSON.stringify({
61
+ messages: [{
62
+ role: "user",
63
+ content: [{ text: prompt }]
64
+ }]
65
+ })
66
+ });
67
+ const body = JSON.parse(this.text_decoder.decode(response.body));
68
+ return body.output.message.content[0].text;
69
+ }
70
+ catch (error) {
71
+ if (error instanceof Error) {
72
+ console.log(error.stack);
73
+ }
74
+ console.log("Failed to get from Bedrock.");
75
+ }
76
+ }
77
+ console.log("Failed to get from Bedrock, quitting.");
78
+ return undefined;
79
+ }
9
80
  async llama_invoke(model_id, prompt, temperature = 0.5, max_gen_len = 512, top_p = 0.9) {
10
81
  for (let i = 0; i < 3; i++) {
11
82
  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 federal_donations = await utils.dynamodb.query("elections.federal_donations:donor_address_state_id-committee_id.federal_donation_id", { donor_address_state_id: "UT", committee_id: "C00401224" }, { compile: false, reverse: true });
20
- console.log(federal_donations);
19
+ const text = await utils.bedrock.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi");
20
+ console.log(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.45",
3
+ "version": "1.4.47",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -10,6 +10,77 @@ 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
+
59
+ async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
60
+ for (let i = 0; i < 3; i++) {
61
+ try {
62
+ const response = await this.bedrock.invokeModel({
63
+ modelId : model_id,
64
+ body : JSON.stringify({
65
+ messages : [{
66
+ role : "user",
67
+ content : [{ text : prompt }]
68
+ }]
69
+ })
70
+ })
71
+ const body = JSON.parse(this.text_decoder.decode(response.body))
72
+ return body.output.message.content[0].text
73
+ } catch (error) {
74
+ if (error instanceof Error) {
75
+ console.log(error.stack)
76
+ }
77
+ console.log("Failed to get from Bedrock.")
78
+ }
79
+ }
80
+ console.log("Failed to get from Bedrock, quitting.")
81
+ return undefined
82
+ }
83
+
13
84
  async llama_invoke(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
14
85
  for (let i = 0; i < 3; i++) {
15
86
  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 federal_donations = await utils.dynamodb.query("elections.federal_donations:donor_address_state_id-committee_id.federal_donation_id", { donor_address_state_id : "UT", committee_id : "C00401224" }, { compile : false, reverse : true })
31
- console.log(federal_donations)
30
+ const text = await utils.bedrock.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi")
31
+ console.log(text)