triangle-utils 1.4.141 → 1.4.143

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.
@@ -12,9 +12,8 @@ export declare class UtilsBedrock {
12
12
  pdf?: string;
13
13
  }[], options?: {
14
14
  system_prompt?: string;
15
- max_tokens?: number;
16
- print_usage?: boolean;
17
- print_content?: boolean;
15
+ max_num_tokens?: number;
16
+ verbosity?: number;
18
17
  json_format?: Record<string, any>;
19
18
  web?: boolean;
20
19
  cache_period?: "5m" | "1h";
@@ -14,6 +14,7 @@ export class UtilsBedrock {
14
14
  this.anthropic_bedrock_mantle = new AnthropicBedrockMantle({ awsRegion: region, defaultHeaders: { "anthropic-workspace-id": "default" } });
15
15
  }
16
16
  async claude_converse(model_id, messages, options = {}) {
17
+ const verbosity = options.verbosity || 0;
17
18
  try {
18
19
  const message_params = [];
19
20
  for (const message of messages) {
@@ -41,28 +42,29 @@ export class UtilsBedrock {
41
42
  content: content
42
43
  });
43
44
  }
44
- const response = await this.anthropic_bedrock_mantle.messages.create({
45
+ const output_config = options.json_format !== undefined ? {
46
+ format: {
47
+ type: "json_schema",
48
+ schema: options.json_format
49
+ }
50
+ } : undefined;
51
+ const request = {
45
52
  model: model_id,
46
53
  messages: message_params,
47
54
  system: options.system_prompt,
48
- tools: options.web === true ? [{ name: "web_search", type: "web_search_20250305" }] : [],
49
- max_tokens: options.max_tokens || 1000,
50
- output_config: options.json_format !== undefined ? {
51
- format: {
52
- type: "json_schema",
53
- schema: options.json_format
54
- }
55
- } : undefined,
56
- // cache_control : {
57
- // type : "ephemeral",
58
- // ttl : options.cache_period
59
- // }
60
- });
55
+ tools: options.web === true ? [{ name: "web_search", type: "web_search_20250305" }] : undefined,
56
+ max_tokens: options.max_num_tokens || 1000,
57
+ output_config: output_config
58
+ };
59
+ if (verbosity > 1) {
60
+ console.log(request);
61
+ }
62
+ const response = await this.anthropic_bedrock_mantle.messages.create(request);
61
63
  const usage = response.usage;
62
- if (options.print_usage !== undefined && options.print_usage) {
64
+ if (verbosity > 0) {
63
65
  console.log(usage);
64
66
  }
65
- if (options.print_content !== undefined && options.print_content) {
67
+ if (verbosity > 1) {
66
68
  console.log(response.content);
67
69
  }
68
70
  const text = response.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.141",
3
+ "version": "1.4.143",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -1,6 +1,6 @@
1
1
  import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime"
2
2
  import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
3
- import { ContentBlockParam, MessageParam } from "@anthropic-ai/sdk/resources"
3
+ import { ContentBlockParam, MessageCreateParams, MessageParam, OutputConfig } from "@anthropic-ai/sdk/resources"
4
4
 
5
5
  const roles = ["user", "assistant", "system"] as const
6
6
 
@@ -28,14 +28,14 @@ export class UtilsBedrock {
28
28
  messages : { role : Role, text : string, pdf? : string }[],
29
29
  options : {
30
30
  system_prompt? : string,
31
- max_tokens? : number,
32
- print_usage? : boolean,
33
- print_content? : boolean,
31
+ max_num_tokens? : number,
32
+ verbosity? : number,
34
33
  json_format? : Record<string, any>,
35
34
  web? : boolean,
36
35
  cache_period? : "5m" | "1h"
37
36
  } = {}
38
37
  ) {
38
+ const verbosity = options.verbosity || 0
39
39
  try {
40
40
  const message_params : MessageParam[] = []
41
41
  for (const message of messages) {
@@ -62,31 +62,31 @@ export class UtilsBedrock {
62
62
  role : message.role,
63
63
  content : content
64
64
  })
65
-
66
65
  }
67
- const response = await this.anthropic_bedrock_mantle.messages.create({
66
+ const output_config : OutputConfig | undefined = options.json_format !== undefined ? {
67
+ format : {
68
+ type : "json_schema",
69
+ schema : options.json_format
70
+ }
71
+ } : undefined
72
+ const request : MessageCreateParams = {
68
73
  model : model_id,
69
74
  messages : message_params,
70
75
  system : options.system_prompt,
71
- tools : options.web === true ? [{ name : "web_search", type : "web_search_20250305" }] : [],
72
- max_tokens : options.max_tokens || 1000,
73
- output_config : options.json_format !== undefined ? {
74
- format : {
75
- type : "json_schema",
76
- schema : options.json_format
77
- }
78
- } : undefined,
79
- // cache_control : {
80
- // type : "ephemeral",
81
- // ttl : options.cache_period
82
- // }
83
- })
76
+ tools : options.web === true ? [{ name : "web_search", type : "web_search_20250305" }] : undefined,
77
+ max_tokens : options.max_num_tokens || 1000,
78
+ output_config : output_config
79
+ }
80
+ if (verbosity > 1) {
81
+ console.log(request)
82
+ }
83
+ const response = await this.anthropic_bedrock_mantle.messages.create(request)
84
84
 
85
85
  const usage = response.usage
86
- if (options.print_usage !== undefined && options.print_usage) {
86
+ if (verbosity > 0) {
87
87
  console.log(usage)
88
88
  }
89
- if (options.print_content !== undefined && options.print_content) {
89
+ if (verbosity > 1) {
90
90
  console.log(response.content)
91
91
  }
92
92
  const text = response.content.filter(content => content.type === "text")[0].text