triangle-utils 1.4.144 → 1.4.146

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.
@@ -15,7 +15,6 @@ export declare class UtilsBedrock {
15
15
  max_num_tokens?: number;
16
16
  verbosity?: number;
17
17
  json_format?: Record<string, any>;
18
- web?: boolean;
19
18
  cache_period?: "5m" | "1h";
20
19
  }): Promise<string | undefined>;
21
20
  claude_invoke(model_id: string, messages: {
@@ -24,8 +23,8 @@ export declare class UtilsBedrock {
24
23
  pdf?: string;
25
24
  }[], options?: {
26
25
  system_prompt?: string;
27
- max_tokens?: number;
28
- print?: boolean;
26
+ max_num_tokens?: number;
27
+ verbosity?: number;
29
28
  json_format?: Record<string, any>;
30
29
  web?: boolean;
31
30
  cache_period?: "5m" | "1h";
@@ -52,12 +52,11 @@ export class UtilsBedrock {
52
52
  model: model_id,
53
53
  messages: message_params,
54
54
  system: options.system_prompt,
55
- tools: options.web === true ? [{ name: "web_search", type: "web_search_20250305" }] : undefined,
56
55
  max_tokens: options.max_num_tokens || 1000,
57
56
  output_config: output_config
58
57
  };
59
58
  if (verbosity > 1) {
60
- console.log(request);
59
+ console.log(JSON.stringify(request, undefined, 4));
61
60
  }
62
61
  const response = await this.anthropic_bedrock_mantle.messages.create(request);
63
62
  const usage = response.usage;
@@ -65,7 +64,7 @@ export class UtilsBedrock {
65
64
  console.log(usage);
66
65
  }
67
66
  if (verbosity > 1) {
68
- console.log(response.content);
67
+ console.log(JSON.stringify(response.content, undefined, 4));
69
68
  }
70
69
  const text = response.content.filter(content => content.type === "text")[0].text;
71
70
  return text;
@@ -79,78 +78,61 @@ export class UtilsBedrock {
79
78
  return undefined;
80
79
  }
81
80
  async claude_invoke(model_id, messages, options = {}) {
81
+ const verbosity = options.verbosity || 0;
82
82
  try {
83
- // const message_params : MessageParam[] = []
84
- // for (const message of messages) {
85
- // const content : ContentBlockParam[] = [
86
- // {
87
- // type : "text",
88
- // text : message.text
89
- // }
90
- // ]
91
- // if (message.pdf !== undefined) {
92
- // content.push({
93
- // type: "document",
94
- // source: {
95
- // type: "base64",
96
- // media_type: "application/pdf",
97
- // data: message.pdf
98
- // },
99
- // title: "Attachment",
100
- // citations: { "enabled": false },
101
- // cache_control: {"type": "ephemeral"}
102
- // })
103
- // }
104
- // message_params.push({
105
- // role : message.role,
106
- // content : content
107
- // })
108
- // }
109
- // if (options.print) {
110
- // console.log("Constructed messages.")
111
- // }
83
+ const message_params = [];
84
+ for (const message of messages) {
85
+ const content = [
86
+ {
87
+ type: "text",
88
+ text: message.text
89
+ }
90
+ ];
91
+ if (message.pdf !== undefined) {
92
+ content.push({
93
+ type: "document",
94
+ source: {
95
+ type: "base64",
96
+ media_type: "application/pdf",
97
+ data: message.pdf
98
+ },
99
+ title: "Attachment",
100
+ citations: { "enabled": false },
101
+ cache_control: { "type": "ephemeral" }
102
+ });
103
+ }
104
+ message_params.push({
105
+ role: message.role,
106
+ content: content
107
+ });
108
+ }
109
+ const output_config = options.json_format !== undefined ? {
110
+ format: {
111
+ type: "json_schema",
112
+ schema: options.json_format
113
+ }
114
+ } : undefined;
112
115
  const request = {
113
116
  modelId: model_id,
114
117
  body: JSON.stringify({
115
- messages: messages.map(message => ({
116
- role: message.role,
117
- content: [
118
- {
119
- type: "text",
120
- text: message.text
121
- },
122
- ...(message.pdf !== undefined ? [
123
- {
124
- type: "document",
125
- source: {
126
- type: "base64",
127
- media_type: "application/pdf",
128
- data: message.pdf
129
- },
130
- title: "Attachment",
131
- citations: { "enabled": false },
132
- cache_control: { "type": "ephemeral" }
133
- }
134
- ] : [])
135
- ]
136
- })),
118
+ messages: message_params,
137
119
  system: options.system_prompt,
138
- tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
139
- max_tokens: options.max_tokens || 1000,
140
- temperature: 0,
120
+ max_tokens: options.max_num_tokens || 1000,
121
+ output_config: output_config,
141
122
  anthropic_version: "bedrock-2023-05-31"
142
123
  })
143
124
  };
144
- if (options.print) {
145
- console.log("Constructed request.");
125
+ if (verbosity > 1) {
126
+ console.log(JSON.stringify(request, undefined, 4));
146
127
  }
147
128
  const response = await this.bedrock_runtime.invokeModel(request);
148
129
  const body = JSON.parse(this.text_decoder.decode(response.body));
149
- if (options.print) {
150
- console.log(body.usage);
130
+ const usage = body.usage;
131
+ if (verbosity > 0) {
132
+ console.log(usage);
151
133
  }
152
- if (options.print) {
153
- console.log(body.content);
134
+ if (verbosity > 1) {
135
+ console.log(JSON.stringify(body.content, undefined, 4));
154
136
  }
155
137
  const text = body.content.filter((content) => content.type === "text")[0].text;
156
138
  return text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.144",
3
+ "version": "1.4.146",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -1,4 +1,4 @@
1
- import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime"
1
+ import { BedrockRuntime, InvokeModelCommandInput } from "@aws-sdk/client-bedrock-runtime"
2
2
  import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
3
3
  import { ContentBlockParam, MessageCreateParams, MessageParam, OutputConfig } from "@anthropic-ai/sdk/resources"
4
4
 
@@ -31,7 +31,6 @@ export class UtilsBedrock {
31
31
  max_num_tokens? : number,
32
32
  verbosity? : number,
33
33
  json_format? : Record<string, any>,
34
- web? : boolean,
35
34
  cache_period? : "5m" | "1h"
36
35
  } = {}
37
36
  ) {
@@ -73,12 +72,11 @@ export class UtilsBedrock {
73
72
  model : model_id,
74
73
  messages : message_params,
75
74
  system : options.system_prompt,
76
- tools : options.web === true ? [{ name : "web_search", type : "web_search_20250305" }] : undefined,
77
75
  max_tokens : options.max_num_tokens || 1000,
78
76
  output_config : output_config
79
77
  }
80
78
  if (verbosity > 1) {
81
- console.log(request)
79
+ console.log(JSON.stringify(request, undefined, 4))
82
80
  }
83
81
  const response = await this.anthropic_bedrock_mantle.messages.create(request)
84
82
 
@@ -87,7 +85,7 @@ export class UtilsBedrock {
87
85
  console.log(usage)
88
86
  }
89
87
  if (verbosity > 1) {
90
- console.log(response.content)
88
+ console.log(JSON.stringify(response.content, undefined, 4))
91
89
  }
92
90
  const text = response.content.filter(content => content.type === "text")[0].text
93
91
  return text
@@ -105,86 +103,68 @@ export class UtilsBedrock {
105
103
  messages : { role : Role, text : string, pdf? : string }[],
106
104
  options : {
107
105
  system_prompt? : string,
108
- max_tokens? : number,
109
- print? : boolean,
106
+ max_num_tokens? : number,
107
+ verbosity? : number,
110
108
  json_format? : Record<string, any>,
111
109
  web? : boolean,
112
110
  cache_period? : "5m" | "1h"
113
111
  } = {}
114
112
  ) : Promise<string | undefined> {
113
+ const verbosity = options.verbosity || 0
115
114
  try {
116
- // const message_params : MessageParam[] = []
117
- // for (const message of messages) {
118
- // const content : ContentBlockParam[] = [
119
- // {
120
- // type : "text",
121
- // text : message.text
122
- // }
123
- // ]
124
- // if (message.pdf !== undefined) {
125
- // content.push({
126
- // type: "document",
127
- // source: {
128
- // type: "base64",
129
- // media_type: "application/pdf",
130
- // data: message.pdf
131
- // },
132
- // title: "Attachment",
133
- // citations: { "enabled": false },
134
- // cache_control: {"type": "ephemeral"}
135
- // })
136
- // }
137
- // message_params.push({
138
- // role : message.role,
139
- // content : content
140
- // })
141
-
142
- // }
143
- // if (options.print) {
144
- // console.log("Constructed messages.")
145
- // }
146
- const request = {
115
+ const message_params : MessageParam[] = []
116
+ for (const message of messages) {
117
+ const content : ContentBlockParam[] = [
118
+ {
119
+ type : "text",
120
+ text : message.text
121
+ }
122
+ ]
123
+ if (message.pdf !== undefined) {
124
+ content.push({
125
+ type: "document",
126
+ source: {
127
+ type: "base64",
128
+ media_type: "application/pdf",
129
+ data: message.pdf
130
+ },
131
+ title: "Attachment",
132
+ citations: { "enabled": false },
133
+ cache_control: {"type": "ephemeral"}
134
+ })
135
+ }
136
+ message_params.push({
137
+ role : message.role,
138
+ content : content
139
+ })
140
+ }
141
+ const output_config : OutputConfig | undefined = options.json_format !== undefined ? {
142
+ format : {
143
+ type : "json_schema",
144
+ schema : options.json_format
145
+ }
146
+ } : undefined
147
+ const request : InvokeModelCommandInput = {
147
148
  modelId : model_id,
148
149
  body : JSON.stringify({
149
- messages : messages.map(message => ({
150
- role : message.role,
151
- content : [
152
- {
153
- type : "text",
154
- text : message.text
155
- },
156
- ...(message.pdf !== undefined ? [
157
- {
158
- type: "document",
159
- source: {
160
- type: "base64",
161
- media_type: "application/pdf",
162
- data: message.pdf
163
- },
164
- title: "Attachment",
165
- citations: { "enabled" : false },
166
- cache_control: {"type": "ephemeral"}
167
- }
168
- ] : [])
169
- ]
170
- })),
150
+ messages : message_params,
171
151
  system : options.system_prompt,
172
- tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
173
- max_tokens: options.max_tokens || 1000,
174
- temperature: 0,
152
+ max_tokens: options.max_num_tokens || 1000,
153
+ output_config : output_config,
175
154
  anthropic_version: "bedrock-2023-05-31"
176
155
  })
177
156
  }
178
- if (options.print) {
179
- console.log("Constructed request.")
157
+ if (verbosity > 1) {
158
+ console.log(JSON.stringify(request, undefined, 4))
180
159
  }
181
160
  const response = await this.bedrock_runtime.invokeModel(request)
182
161
  const body = JSON.parse(this.text_decoder.decode(response.body))
183
- if (options.print) {
184
- console.log(body.usage)
162
+ const usage = body.usage
163
+ if (verbosity > 0) {
164
+ console.log(usage)
185
165
  }
186
- if (options.print) {
187
- console.log(body.content)
166
+ if (verbosity > 1) {
167
+ console.log(JSON.stringify(body.content, undefined, 4))
188
168
  }
189
169
  const text = body.content.filter((content : any) => content.type === "text")[0].text
190
170
  return text