triangle-utils 1.4.58 → 1.4.60
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.
- package/dist/src/UtilsAnthropic.d.ts +5 -0
- package/dist/src/UtilsAnthropic.js +36 -0
- package/dist/src/UtilsS3.d.ts +1 -1
- package/package.json +1 -1
- package/src/UtilsAnthropic.ts +46 -0
- package/src/UtilsS3.ts +1 -1
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export declare class UtilsAnthropic {
|
|
2
2
|
private readonly anthropic;
|
|
3
3
|
constructor(anthropic_api_key: string | undefined);
|
|
4
|
+
claude_multi_query(model_id: string, prompts: string[], options?: {
|
|
5
|
+
max_tokens?: number;
|
|
6
|
+
print_usage?: boolean;
|
|
7
|
+
json_format?: Record<string, any>;
|
|
8
|
+
}): Promise<string | undefined>;
|
|
4
9
|
claude_query(model_id: string, prompt: string, attachment_pdf?: string, options?: {
|
|
5
10
|
max_tokens?: number;
|
|
6
11
|
print_usage?: boolean;
|
|
@@ -4,6 +4,42 @@ export class UtilsAnthropic {
|
|
|
4
4
|
constructor(anthropic_api_key) {
|
|
5
5
|
this.anthropic = new Anthropic({ apiKey: anthropic_api_key });
|
|
6
6
|
}
|
|
7
|
+
async claude_multi_query(model_id, prompts, options = {}) {
|
|
8
|
+
try {
|
|
9
|
+
const response = await this.anthropic.messages.create({
|
|
10
|
+
model: model_id,
|
|
11
|
+
messages: prompts.map(prompt => ({
|
|
12
|
+
role: "user",
|
|
13
|
+
content: [
|
|
14
|
+
{
|
|
15
|
+
type: "text",
|
|
16
|
+
text: prompt
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
})),
|
|
20
|
+
max_tokens: options.max_tokens || 1000,
|
|
21
|
+
output_config: options.json_format !== undefined ? {
|
|
22
|
+
format: {
|
|
23
|
+
type: "json_schema",
|
|
24
|
+
schema: options.json_format
|
|
25
|
+
}
|
|
26
|
+
} : undefined
|
|
27
|
+
});
|
|
28
|
+
const usage = response.usage;
|
|
29
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
30
|
+
console.log(usage);
|
|
31
|
+
}
|
|
32
|
+
const text = response.content.filter(content => content.type === "text")[0].text;
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
console.log(error.stack);
|
|
38
|
+
}
|
|
39
|
+
console.log("Failed to get from Anthropic.");
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
7
43
|
async claude_query(model_id, prompt, attachment_pdf, options = {}) {
|
|
8
44
|
try {
|
|
9
45
|
const message_contents = [
|
package/dist/src/UtilsS3.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class UtilsS3 {
|
|
|
10
10
|
get_file(s3_filename: string, encoding?: string): Promise<string | undefined>;
|
|
11
11
|
get_file_buffer(s3_filename: string): Promise<Buffer | undefined>;
|
|
12
12
|
get_file_stream(s3_filename: string): Promise<Readable | undefined>;
|
|
13
|
-
create_file(s3_filename: string, content: string | Buffer, options?: {
|
|
13
|
+
create_file(s3_filename: string, content: string | Buffer | Readable, options?: {
|
|
14
14
|
content_type?: string;
|
|
15
15
|
}): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
|
|
16
16
|
delete_file(s3_filename: string): Promise<void>;
|
package/package.json
CHANGED
package/src/UtilsAnthropic.ts
CHANGED
|
@@ -8,6 +8,52 @@ export class UtilsAnthropic {
|
|
|
8
8
|
this.anthropic = new Anthropic({ apiKey : anthropic_api_key })
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
async claude_multi_query(
|
|
12
|
+
model_id : string,
|
|
13
|
+
prompts : string[],
|
|
14
|
+
options : {
|
|
15
|
+
max_tokens? : number,
|
|
16
|
+
print_usage? : boolean,
|
|
17
|
+
json_format? : Record<string, any>
|
|
18
|
+
} = {}
|
|
19
|
+
) : Promise<string | undefined> {
|
|
20
|
+
try {
|
|
21
|
+
|
|
22
|
+
const response = await this.anthropic.messages.create({
|
|
23
|
+
model : model_id,
|
|
24
|
+
messages : prompts.map(prompt => ({
|
|
25
|
+
role : "user",
|
|
26
|
+
content : [
|
|
27
|
+
{
|
|
28
|
+
type : "text",
|
|
29
|
+
text : prompt
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
})),
|
|
33
|
+
max_tokens : options.max_tokens || 1000,
|
|
34
|
+
output_config : options.json_format !== undefined ? {
|
|
35
|
+
format : {
|
|
36
|
+
type : "json_schema",
|
|
37
|
+
schema : options.json_format
|
|
38
|
+
}
|
|
39
|
+
} : undefined
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const usage = response.usage
|
|
43
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
44
|
+
console.log(usage)
|
|
45
|
+
}
|
|
46
|
+
const text = response.content.filter(content => content.type === "text")[0].text
|
|
47
|
+
return text
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
console.log(error.stack)
|
|
51
|
+
}
|
|
52
|
+
console.log("Failed to get from Anthropic.")
|
|
53
|
+
}
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
11
57
|
async claude_query(
|
|
12
58
|
model_id : string,
|
|
13
59
|
prompt : string,
|
package/src/UtilsS3.ts
CHANGED
|
@@ -147,7 +147,7 @@ export class UtilsS3 {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
async create_file(s3_filename : string, content : string | Buffer, options : {
|
|
150
|
+
async create_file(s3_filename : string, content : string | Buffer | Readable, options : {
|
|
151
151
|
content_type? : string
|
|
152
152
|
} = {}) {
|
|
153
153
|
const content_type = options.content_type !== undefined ? options.content_type : undefined
|