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.
@@ -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
- 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
- if (options.print_usage !== undefined && options.print_usage) {
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
- catch (error) {
47
- if (error instanceof Error) {
48
- console.log(error.stack);
49
- }
50
- 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);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.51",
3
+ "version": "1.4.52",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -19,49 +19,46 @@ export class UtilsBedrock {
19
19
  print_usage? : boolean
20
20
  } = {}
21
21
  ) : Promise<string | undefined> {
22
- for (let i = 0; i < 3; i++) {
23
- try {
24
- const response = await this.bedrock.invokeModel({
25
- modelId : model_id,
26
- body : JSON.stringify({
27
- messages : [{
28
- role : "user",
29
- content : [
30
- {
31
- type : "text",
32
- 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
33
39
  },
34
- ...(attachment_pdf !== undefined ? [{
35
- type: "document",
36
- source: {
37
- type: "base64",
38
- media_type: "application/pdf",
39
- data: attachment_pdf
40
- },
41
- title: "Attachment",
42
- citations: { "enabled": false },
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
- const body = JSON.parse(this.text_decoder.decode(response.body))
53
- if (options.print_usage !== undefined && options.print_usage) {
54
- console.log(body.usage)
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