triangle-utils 1.4.100 → 1.4.102

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.
@@ -26,8 +26,7 @@ export declare class UtilsBedrock {
26
26
  }[], options?: {
27
27
  system_prompt?: string;
28
28
  max_tokens?: number;
29
- print_usage?: boolean;
30
- print_content?: boolean;
29
+ print?: boolean;
31
30
  json_format?: Record<string, any>;
32
31
  web?: boolean;
33
32
  cache_period?: "5m" | "1h";
@@ -78,48 +78,76 @@ export class UtilsBedrock {
78
78
  }
79
79
  async claude_invoke(model_id, messages, options = {}) {
80
80
  try {
81
- const message_params = [];
82
- for (const message of messages) {
83
- const content = [
84
- {
85
- type: "text",
86
- text: message.text
87
- }
88
- ];
89
- if (message.pdf !== undefined) {
90
- content.push({
91
- type: "document",
92
- source: {
93
- type: "base64",
94
- media_type: "application/pdf",
95
- data: message.pdf
96
- },
97
- title: "Attachment",
98
- citations: { "enabled": false },
99
- cache_control: { "type": "ephemeral" }
100
- });
101
- }
102
- message_params.push({
103
- role: message.role,
104
- content: content
105
- });
106
- }
107
- const response = await this.bedrock_runtime.invokeModel({
81
+ // const message_params : MessageParam[] = []
82
+ // for (const message of messages) {
83
+ // const content : ContentBlockParam[] = [
84
+ // {
85
+ // type : "text",
86
+ // text : message.text
87
+ // }
88
+ // ]
89
+ // if (message.pdf !== undefined) {
90
+ // content.push({
91
+ // type: "document",
92
+ // source: {
93
+ // type: "base64",
94
+ // media_type: "application/pdf",
95
+ // data: message.pdf
96
+ // },
97
+ // title: "Attachment",
98
+ // citations: { "enabled": false },
99
+ // cache_control: {"type": "ephemeral"}
100
+ // })
101
+ // }
102
+ // message_params.push({
103
+ // role : message.role,
104
+ // content : content
105
+ // })
106
+ // }
107
+ // if (options.print) {
108
+ // console.log("Constructed messages.")
109
+ // }
110
+ const request = {
108
111
  modelId: model_id,
109
112
  body: JSON.stringify({
110
- messages: message_params,
113
+ messages: messages.map(message => ({
114
+ role: message.role,
115
+ content: [
116
+ {
117
+ type: "text",
118
+ text: message.text
119
+ },
120
+ ...(message.pdf !== undefined ? [
121
+ {
122
+ type: "document",
123
+ source: {
124
+ type: "base64",
125
+ media_type: "application/pdf",
126
+ data: message.pdf
127
+ },
128
+ title: "Attachment",
129
+ citations: { "enabled": false },
130
+ cache_control: { "type": "ephemeral" }
131
+ }
132
+ ] : [])
133
+ ]
134
+ })),
111
135
  system: options.system_prompt,
112
136
  tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
113
137
  max_tokens: options.max_tokens || 1000,
114
138
  temperature: 0,
115
139
  anthropic_version: "bedrock-2023-05-31"
116
140
  })
117
- });
141
+ };
142
+ if (options.print) {
143
+ console.log("Constructed request.");
144
+ }
145
+ const response = await this.bedrock_runtime.invokeModel(request);
118
146
  const body = JSON.parse(this.text_decoder.decode(response.body));
119
- if (options.print_usage !== undefined && options.print_usage) {
147
+ if (options.print) {
120
148
  console.log(body.usage);
121
149
  }
122
- if (options.print_content !== undefined && options.print_content) {
150
+ if (options.print) {
123
151
  console.log(body.content);
124
152
  }
125
153
  const text = body.content.filter((content) => content.type === "text")[0].text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.100",
3
+ "version": "1.4.102",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -106,57 +106,84 @@ export class UtilsBedrock {
106
106
  options : {
107
107
  system_prompt? : string,
108
108
  max_tokens? : number,
109
- print_usage? : boolean,
110
- print_content? : boolean,
109
+ print? : boolean,
111
110
  json_format? : Record<string, any>,
112
111
  web? : boolean,
113
112
  cache_period? : "5m" | "1h"
114
113
  } = {}
115
114
  ) : Promise<string | undefined> {
116
115
  try {
117
- const message_params : MessageParam[] = []
118
- for (const message of messages) {
119
- const content : ContentBlockParam[] = [
120
- {
121
- type : "text",
122
- text : message.text
123
- }
124
- ]
125
- if (message.pdf !== undefined) {
126
- content.push({
127
- type: "document",
128
- source: {
129
- type: "base64",
130
- media_type: "application/pdf",
131
- data: message.pdf
132
- },
133
- title: "Attachment",
134
- citations: { "enabled": false },
135
- cache_control: {"type": "ephemeral"}
136
- })
137
- }
138
- message_params.push({
139
- role : message.role,
140
- content : content
141
- })
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
+ // })
142
141
 
143
- }
144
- const response = await this.bedrock_runtime.invokeModel({
142
+ // }
143
+ // if (options.print) {
144
+ // console.log("Constructed messages.")
145
+ // }
146
+ const request = {
145
147
  modelId : model_id,
146
148
  body : JSON.stringify({
147
- messages : message_params,
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
+ })),
148
171
  system : options.system_prompt,
149
172
  tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
150
173
  max_tokens: options.max_tokens || 1000,
151
174
  temperature: 0,
152
175
  anthropic_version: "bedrock-2023-05-31"
153
176
  })
154
- })
177
+ }
178
+ if (options.print) {
179
+ console.log("Constructed request.")
180
+ }
181
+ const response = await this.bedrock_runtime.invokeModel(request)
155
182
  const body = JSON.parse(this.text_decoder.decode(response.body))
156
- if (options.print_usage !== undefined && options.print_usage) {
183
+ if (options.print) {
157
184
  console.log(body.usage)
158
185
  }
159
- if (options.print_content !== undefined && options.print_content) {
186
+ if (options.print) {
160
187
  console.log(body.content)
161
188
  }
162
189
  const text = body.content.filter((content : any) => content.type === "text")[0].text