triangle-utils 1.4.52 → 1.4.53
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 +8 -0
- package/dist/src/UtilsAnthropic.js +52 -0
- package/dist/src/f.js +4 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +4 -0
- package/package.json +2 -1
- package/src/UtilsAnthropic.ts +66 -0
- package/src/f.ts +7 -2
- package/src/index.ts +4 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class UtilsAnthropic {
|
|
2
|
+
private readonly anthropic;
|
|
3
|
+
constructor(anthropic_api_key: string | undefined);
|
|
4
|
+
claude_query(model_id: string, prompt: string, attachment_pdf?: string, options?: {
|
|
5
|
+
max_tokens?: number;
|
|
6
|
+
print_usage?: boolean;
|
|
7
|
+
}): Promise<string | undefined>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
export class UtilsAnthropic {
|
|
3
|
+
anthropic;
|
|
4
|
+
constructor(anthropic_api_key) {
|
|
5
|
+
this.anthropic = new Anthropic({ apiKey: anthropic_api_key });
|
|
6
|
+
}
|
|
7
|
+
async claude_query(model_id, prompt, attachment_pdf, options = {}) {
|
|
8
|
+
try {
|
|
9
|
+
const message_contents = [
|
|
10
|
+
{
|
|
11
|
+
type: "text",
|
|
12
|
+
text: prompt
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
const attachment_content = attachment_pdf !== undefined ? {
|
|
16
|
+
type: "document",
|
|
17
|
+
source: {
|
|
18
|
+
type: "base64",
|
|
19
|
+
media_type: "application/pdf",
|
|
20
|
+
data: attachment_pdf
|
|
21
|
+
},
|
|
22
|
+
title: "Attachment",
|
|
23
|
+
citations: { "enabled": false },
|
|
24
|
+
cache_control: { "type": "ephemeral" }
|
|
25
|
+
} : undefined;
|
|
26
|
+
if (attachment_content !== undefined) {
|
|
27
|
+
message_contents.push(attachment_content);
|
|
28
|
+
}
|
|
29
|
+
const response = await this.anthropic.messages.create({
|
|
30
|
+
model: model_id,
|
|
31
|
+
messages: [{
|
|
32
|
+
role: "user",
|
|
33
|
+
content: message_contents
|
|
34
|
+
}],
|
|
35
|
+
max_tokens: options.max_tokens || 1000
|
|
36
|
+
});
|
|
37
|
+
const usage = response.usage;
|
|
38
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
39
|
+
console.log(usage);
|
|
40
|
+
}
|
|
41
|
+
const text = response.content.filter(content => content.type === "text")[0].text;
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
console.log(error.stack);
|
|
47
|
+
}
|
|
48
|
+
console.log("Failed to get from Anthropic.");
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/src/f.js
CHANGED
|
@@ -13,8 +13,11 @@ const config = {
|
|
|
13
13
|
region: "us-east-1",
|
|
14
14
|
...api_keys
|
|
15
15
|
};
|
|
16
|
+
console.log(config);
|
|
16
17
|
const utils = new TriangleUtils(config);
|
|
17
18
|
// const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
|
|
18
19
|
// console.log(foods)
|
|
19
|
-
const text = await utils.
|
|
20
|
+
const text = await utils.anthropic.claude_query("claude-opus-4-6", "hi", undefined, { print_usage: true });
|
|
20
21
|
console.log(text);
|
|
22
|
+
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
23
|
+
// console.log(text)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { UtilsMisc } from "./UtilsMisc.js";
|
|
|
10
10
|
import { UtilsYoutube } from "./UtilsYoutube.js";
|
|
11
11
|
import { UtilsXAI } from "./UtilsXAI.js";
|
|
12
12
|
import { UtilsNitter } from "./UtilsNitter.js";
|
|
13
|
+
import { UtilsAnthropic } from "./UtilsAnthropic.js";
|
|
13
14
|
export declare class TriangleUtils extends UtilsMisc {
|
|
14
15
|
readonly dynamodb: UtilsDynamoDB;
|
|
15
16
|
readonly s3: UtilsS3;
|
|
@@ -19,12 +20,14 @@ export declare class TriangleUtils extends UtilsMisc {
|
|
|
19
20
|
readonly ses: UtilsSES;
|
|
20
21
|
readonly bee: UtilsBee;
|
|
21
22
|
readonly youtube: UtilsYoutube;
|
|
23
|
+
readonly anthropic: UtilsAnthropic;
|
|
22
24
|
readonly xai: UtilsXAI;
|
|
23
25
|
readonly nitter: UtilsNitter;
|
|
24
26
|
constructor(config: TriangleUtilsConfig);
|
|
25
27
|
}
|
|
26
28
|
export * from "./types/TriangleUtilsConfig.js";
|
|
27
29
|
export * from "./UtilsMisc.js";
|
|
30
|
+
export * from "./UtilsAnthropic.js";
|
|
28
31
|
export * from "./UtilsDynamoDB.js";
|
|
29
32
|
export * from "./UtilsS3.js";
|
|
30
33
|
export * from "./UtilsBedrock.js";
|
package/dist/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { UtilsMisc } from "./UtilsMisc.js";
|
|
|
9
9
|
import { UtilsYoutube } from "./UtilsYoutube.js";
|
|
10
10
|
import { UtilsXAI } from "./UtilsXAI.js";
|
|
11
11
|
import { UtilsNitter } from "./UtilsNitter.js";
|
|
12
|
+
import { UtilsAnthropic } from "./UtilsAnthropic.js";
|
|
12
13
|
export class TriangleUtils extends UtilsMisc {
|
|
13
14
|
dynamodb;
|
|
14
15
|
s3;
|
|
@@ -18,6 +19,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
18
19
|
ses;
|
|
19
20
|
bee;
|
|
20
21
|
youtube;
|
|
22
|
+
anthropic;
|
|
21
23
|
xai;
|
|
22
24
|
nitter;
|
|
23
25
|
constructor(config) {
|
|
@@ -30,12 +32,14 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
30
32
|
this.ses = new UtilsSES(config.region);
|
|
31
33
|
this.bee = new UtilsBee(config.scraping_bee_api_key);
|
|
32
34
|
this.youtube = new UtilsYoutube(config.youtube_api_key);
|
|
35
|
+
this.anthropic = new UtilsAnthropic(config.anthropic_api_key);
|
|
33
36
|
this.xai = new UtilsXAI(config.xai_api_key);
|
|
34
37
|
this.nitter = new UtilsNitter(config.scraping_bee_api_key);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
export * from "./types/TriangleUtilsConfig.js";
|
|
38
41
|
export * from "./UtilsMisc.js";
|
|
42
|
+
export * from "./UtilsAnthropic.js";
|
|
39
43
|
export * from "./UtilsDynamoDB.js";
|
|
40
44
|
export * from "./UtilsS3.js";
|
|
41
45
|
export * from "./UtilsBedrock.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.53",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"description": "",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@anthropic-ai/sdk": "^0.94.0",
|
|
18
19
|
"@aws-sdk/client-bedrock-runtime": "^3.953.0",
|
|
19
20
|
"@aws-sdk/client-cognito-identity-provider": "^3.1004.0",
|
|
20
21
|
"@aws-sdk/client-dynamodb": "^3.953.0",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Anthropic from "@anthropic-ai/sdk"
|
|
2
|
+
|
|
3
|
+
export class UtilsAnthropic {
|
|
4
|
+
|
|
5
|
+
private readonly anthropic : Anthropic
|
|
6
|
+
|
|
7
|
+
constructor(anthropic_api_key : string | undefined) {
|
|
8
|
+
this.anthropic = new Anthropic({ apiKey : anthropic_api_key })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async claude_query(
|
|
12
|
+
model_id : string,
|
|
13
|
+
prompt : string,
|
|
14
|
+
attachment_pdf? : string,
|
|
15
|
+
options : {
|
|
16
|
+
max_tokens? : number,
|
|
17
|
+
print_usage? : boolean
|
|
18
|
+
} = {}
|
|
19
|
+
) : Promise<string | undefined> {
|
|
20
|
+
try {
|
|
21
|
+
const message_contents : Anthropic.Messages.ContentBlockParam[] = [
|
|
22
|
+
{
|
|
23
|
+
type : "text",
|
|
24
|
+
text : prompt
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
const attachment_content : Anthropic.Messages.ContentBlockParam | undefined = attachment_pdf !== undefined ? {
|
|
28
|
+
type: "document",
|
|
29
|
+
source: {
|
|
30
|
+
type: "base64",
|
|
31
|
+
media_type: "application/pdf",
|
|
32
|
+
data: attachment_pdf
|
|
33
|
+
},
|
|
34
|
+
title: "Attachment",
|
|
35
|
+
citations: { "enabled": false },
|
|
36
|
+
cache_control: {"type": "ephemeral"}
|
|
37
|
+
} : undefined
|
|
38
|
+
|
|
39
|
+
if (attachment_content !== undefined) {
|
|
40
|
+
message_contents.push(attachment_content)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const response = await this.anthropic.messages.create({
|
|
44
|
+
model : model_id,
|
|
45
|
+
messages : [{
|
|
46
|
+
role : "user",
|
|
47
|
+
content : message_contents
|
|
48
|
+
}],
|
|
49
|
+
max_tokens : options.max_tokens || 1000
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const usage = response.usage
|
|
53
|
+
if (options.print_usage !== undefined && options.print_usage) {
|
|
54
|
+
console.log(usage)
|
|
55
|
+
}
|
|
56
|
+
const text = response.content.filter(content => content.type === "text")[0].text
|
|
57
|
+
return text
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
console.log(error.stack)
|
|
61
|
+
}
|
|
62
|
+
console.log("Failed to get from Anthropic.")
|
|
63
|
+
}
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/f.ts
CHANGED
|
@@ -20,12 +20,17 @@ const config = {
|
|
|
20
20
|
...api_keys
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
console.log(config)
|
|
24
|
+
|
|
23
25
|
const utils = new TriangleUtils(config)
|
|
24
26
|
|
|
25
27
|
// const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
|
|
26
28
|
|
|
27
29
|
// console.log(foods)
|
|
28
30
|
|
|
31
|
+
const text = await utils.anthropic.claude_query("claude-opus-4-6", "hi", undefined, { print_usage : true })
|
|
32
|
+
|
|
33
|
+
console.log(text)
|
|
29
34
|
|
|
30
|
-
const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
31
|
-
console.log(text)
|
|
35
|
+
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
36
|
+
// console.log(text)
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { UtilsMisc } from "./UtilsMisc"
|
|
|
10
10
|
import { UtilsYoutube } from "./UtilsYoutube"
|
|
11
11
|
import { UtilsXAI } from "./UtilsXAI"
|
|
12
12
|
import { UtilsNitter } from "./UtilsNitter"
|
|
13
|
+
import { UtilsAnthropic } from "./UtilsAnthropic"
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
|
|
@@ -23,6 +24,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
23
24
|
readonly ses : UtilsSES
|
|
24
25
|
readonly bee : UtilsBee
|
|
25
26
|
readonly youtube : UtilsYoutube
|
|
27
|
+
readonly anthropic : UtilsAnthropic
|
|
26
28
|
readonly xai : UtilsXAI
|
|
27
29
|
readonly nitter : UtilsNitter
|
|
28
30
|
|
|
@@ -36,6 +38,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
36
38
|
this.ses = new UtilsSES(config.region)
|
|
37
39
|
this.bee = new UtilsBee(config.scraping_bee_api_key)
|
|
38
40
|
this.youtube = new UtilsYoutube(config.youtube_api_key)
|
|
41
|
+
this.anthropic = new UtilsAnthropic(config.anthropic_api_key)
|
|
39
42
|
this.xai = new UtilsXAI(config.xai_api_key)
|
|
40
43
|
this.nitter = new UtilsNitter(config.scraping_bee_api_key)
|
|
41
44
|
}
|
|
@@ -43,6 +46,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
43
46
|
|
|
44
47
|
export * from "./types/TriangleUtilsConfig"
|
|
45
48
|
export * from "./UtilsMisc"
|
|
49
|
+
export * from "./UtilsAnthropic"
|
|
46
50
|
export * from "./UtilsDynamoDB"
|
|
47
51
|
export * from "./UtilsS3"
|
|
48
52
|
export * from "./UtilsBedrock"
|