triangle-utils 1.4.50 → 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.
@@ -2,8 +2,9 @@ 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, options?: {
5
+ claude_invoke(model_id: string, prompt: string, attachment_pdf?: string, options?: {
6
6
  max_tokens?: number;
7
+ print_usage?: boolean;
7
8
  }): Promise<string | undefined>;
8
9
  nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
9
10
  llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
@@ -6,48 +6,48 @@ 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, options = {}) {
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
- type: "document",
24
- source: {
25
- type: "base64",
26
- media_type: "application/pdf",
27
- data: attachment_pdf
28
- },
29
- title: "Attachment",
30
- citations: { "enabled": false },
31
- cache_control: { "type": "ephemeral" }
32
- }] : [])
33
- ]
34
- }],
35
- max_tokens: options.max_tokens || 1000,
36
- temperature: 0,
37
- anthropic_version: "bedrock-2023-05-31"
38
- })
39
- });
40
- const body = JSON.parse(this.text_decoder.decode(response.body));
41
- return body.content[0].text;
9
+ async claude_invoke(model_id, prompt, attachment_pdf, options = {}) {
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);
42
42
  }
43
- catch (error) {
44
- if (error instanceof Error) {
45
- console.log(error.stack);
46
- }
47
- console.log("Failed to get from Bedrock.");
43
+ return body.content[0].text;
44
+ }
45
+ catch (error) {
46
+ if (error instanceof Error) {
47
+ console.log(error.stack);
48
48
  }
49
+ console.log("Failed to get from Bedrock.");
49
50
  }
50
- console.log("Failed to get from Bedrock, quitting.");
51
51
  return undefined;
52
52
  }
53
53
  async nova_invoke(model_id, prompt) {
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.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi");
19
+ const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage: true });
20
20
  console.log(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.50",
3
+ "version": "1.4.52",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -10,54 +10,55 @@ export class UtilsBedrock {
10
10
  this.text_decoder = new TextDecoder()
11
11
  }
12
12
 
13
- async claude_sonnet_invoke(
13
+ async claude_invoke(
14
14
  model_id : string,
15
15
  prompt : string,
16
16
  attachment_pdf? : string,
17
17
  options : {
18
- max_tokens? : number
18
+ max_tokens? : number,
19
+ print_usage? : boolean
19
20
  } = {}
20
21
  ) : Promise<string | undefined> {
21
- for (let i = 0; i < 3; i++) {
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
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
32
39
  },
33
- ...(attachment_pdf !== undefined ? [{
34
- type: "document",
35
- source: {
36
- type: "base64",
37
- media_type: "application/pdf",
38
- data: attachment_pdf
39
- },
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"
49
- })
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"
50
49
  })
51
- const body = JSON.parse(this.text_decoder.decode(response.body))
52
- return body.content[0].text
53
- } catch (error) {
54
- if (error instanceof Error) {
55
- console.log(error.stack)
56
- }
57
- 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)
58
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.")
59
61
  }
60
- console.log("Failed to get from Bedrock, quitting.")
61
62
  return undefined
62
63
  }
63
64
 
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.claude_sonnet_invoke("global.anthropic.claude-sonnet-4-5-20250929-v1:0", "hi")
30
+ const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
31
31
  console.log(text)