triangle-utils 1.4.81 → 1.4.82
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.
|
@@ -4,11 +4,13 @@ export declare class UtilsAnthropic {
|
|
|
4
4
|
claude_converse(model_id: string, messages: {
|
|
5
5
|
role: "user" | "assistant" | "system";
|
|
6
6
|
text: string;
|
|
7
|
-
}[],
|
|
7
|
+
}[], options?: {
|
|
8
|
+
system_prompt?: string;
|
|
8
9
|
max_tokens?: number;
|
|
9
10
|
print_usage?: boolean;
|
|
10
11
|
json_format?: Record<string, any>;
|
|
11
12
|
web?: boolean;
|
|
13
|
+
cache_period?: "5m" | "1h";
|
|
12
14
|
}): Promise<string | undefined>;
|
|
13
15
|
claude_multi_query(model_id: string, prompts: string[], options?: {
|
|
14
16
|
max_tokens?: number;
|
|
@@ -4,7 +4,7 @@ export class UtilsAnthropic {
|
|
|
4
4
|
constructor(anthropic_api_key) {
|
|
5
5
|
this.anthropic = new Anthropic({ apiKey: anthropic_api_key });
|
|
6
6
|
}
|
|
7
|
-
async claude_converse(model_id, messages,
|
|
7
|
+
async claude_converse(model_id, messages, options = {}) {
|
|
8
8
|
try {
|
|
9
9
|
const response = await this.anthropic.messages.create({
|
|
10
10
|
model: model_id,
|
|
@@ -17,7 +17,7 @@ export class UtilsAnthropic {
|
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
19
|
})),
|
|
20
|
-
system: system_prompt,
|
|
20
|
+
system: options.system_prompt,
|
|
21
21
|
tools: options.web === true ? [{ name: "web_search", type: "web_search_20260209" }] : [],
|
|
22
22
|
max_tokens: options.max_tokens || 1000,
|
|
23
23
|
output_config: options.json_format !== undefined ? {
|
|
@@ -25,7 +25,11 @@ export class UtilsAnthropic {
|
|
|
25
25
|
type: "json_schema",
|
|
26
26
|
schema: options.json_format
|
|
27
27
|
}
|
|
28
|
-
} : undefined
|
|
28
|
+
} : undefined,
|
|
29
|
+
cache_control: {
|
|
30
|
+
type: "ephemeral",
|
|
31
|
+
ttl: options.cache_period
|
|
32
|
+
}
|
|
29
33
|
});
|
|
30
34
|
const usage = response.usage;
|
|
31
35
|
if (options.print_usage !== undefined && options.print_usage) {
|
|
@@ -96,7 +100,7 @@ export class UtilsAnthropic {
|
|
|
96
100
|
},
|
|
97
101
|
title: "Attachment",
|
|
98
102
|
citations: { "enabled": false },
|
|
99
|
-
cache_control: {
|
|
103
|
+
cache_control: { type: "ephemeral" }
|
|
100
104
|
} : undefined;
|
|
101
105
|
if (attachment_content !== undefined) {
|
|
102
106
|
message_contents.push(attachment_content);
|
package/package.json
CHANGED
package/src/UtilsAnthropic.ts
CHANGED
|
@@ -11,12 +11,13 @@ export class UtilsAnthropic {
|
|
|
11
11
|
async claude_converse(
|
|
12
12
|
model_id : string,
|
|
13
13
|
messages : { role : "user" | "assistant" | "system", text : string }[],
|
|
14
|
-
system_prompt? : string,
|
|
15
14
|
options : {
|
|
15
|
+
system_prompt? : string,
|
|
16
16
|
max_tokens? : number,
|
|
17
17
|
print_usage? : boolean,
|
|
18
18
|
json_format? : Record<string, any>,
|
|
19
|
-
web? : boolean
|
|
19
|
+
web? : boolean,
|
|
20
|
+
cache_period? : "5m" | "1h"
|
|
20
21
|
} = {}
|
|
21
22
|
) : Promise<string | undefined> {
|
|
22
23
|
try {
|
|
@@ -32,7 +33,7 @@ export class UtilsAnthropic {
|
|
|
32
33
|
}
|
|
33
34
|
]
|
|
34
35
|
})),
|
|
35
|
-
system : system_prompt,
|
|
36
|
+
system : options.system_prompt,
|
|
36
37
|
tools : options.web === true ? [{ name : "web_search", type : "web_search_20260209" }] : [],
|
|
37
38
|
max_tokens : options.max_tokens || 1000,
|
|
38
39
|
output_config : options.json_format !== undefined ? {
|
|
@@ -40,7 +41,11 @@ export class UtilsAnthropic {
|
|
|
40
41
|
type : "json_schema",
|
|
41
42
|
schema : options.json_format
|
|
42
43
|
}
|
|
43
|
-
} : undefined
|
|
44
|
+
} : undefined,
|
|
45
|
+
cache_control : {
|
|
46
|
+
type : "ephemeral",
|
|
47
|
+
ttl : options.cache_period
|
|
48
|
+
}
|
|
44
49
|
})
|
|
45
50
|
|
|
46
51
|
const usage = response.usage
|
|
@@ -133,7 +138,7 @@ export class UtilsAnthropic {
|
|
|
133
138
|
},
|
|
134
139
|
title: "Attachment",
|
|
135
140
|
citations: { "enabled": false },
|
|
136
|
-
cache_control: {
|
|
141
|
+
cache_control: {type: "ephemeral"}
|
|
137
142
|
} : undefined
|
|
138
143
|
|
|
139
144
|
if (attachment_content !== undefined) {
|