triangle-utils 1.4.83 → 1.4.85
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/UtilsBedrock.d.ts +5 -1
- package/dist/src/UtilsBedrock.js +8 -4
- package/dist/src/f.js +11 -4
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +13 -6
- package/src/f.ts +16 -5
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
declare const role_ids: readonly ["user", "assistant", "system"];
|
|
2
|
+
export type RoleID = typeof role_ids[number];
|
|
3
|
+
export declare function is_role_id(role_id: any): role_id is RoleID;
|
|
1
4
|
export declare class UtilsBedrock {
|
|
2
5
|
private readonly bedrock_runtime;
|
|
3
6
|
private readonly anthropic_bedrock_mantle;
|
|
4
7
|
private readonly text_decoder;
|
|
5
8
|
constructor(region: string);
|
|
6
9
|
claude_converse(model_id: string, messages: {
|
|
7
|
-
role:
|
|
10
|
+
role: RoleID;
|
|
8
11
|
text: string;
|
|
9
12
|
}[], options?: {
|
|
10
13
|
system_prompt?: string;
|
|
@@ -23,3 +26,4 @@ export declare class UtilsBedrock {
|
|
|
23
26
|
gpt_converse(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
|
|
24
27
|
titan_invoke(text: string): Promise<number[] | undefined>;
|
|
25
28
|
}
|
|
29
|
+
export {};
|
package/dist/src/UtilsBedrock.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime";
|
|
2
2
|
import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk";
|
|
3
|
+
const role_ids = ["user", "assistant", "system"];
|
|
4
|
+
export function is_role_id(role_id) {
|
|
5
|
+
return role_ids.includes(role_id);
|
|
6
|
+
}
|
|
3
7
|
export class UtilsBedrock {
|
|
4
8
|
bedrock_runtime;
|
|
5
9
|
anthropic_bedrock_mantle;
|
|
@@ -31,10 +35,10 @@ export class UtilsBedrock {
|
|
|
31
35
|
schema: options.json_format
|
|
32
36
|
}
|
|
33
37
|
} : undefined,
|
|
34
|
-
cache_control: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
+
// cache_control : {
|
|
39
|
+
// type : "ephemeral",
|
|
40
|
+
// ttl : options.cache_period
|
|
41
|
+
// }
|
|
38
42
|
});
|
|
39
43
|
const usage = response.usage;
|
|
40
44
|
if (options.print_usage !== undefined && options.print_usage) {
|
package/dist/src/f.js
CHANGED
|
@@ -3,10 +3,10 @@ import { TriangleUtils } from "./index.js";
|
|
|
3
3
|
console.log("Starting triangle-utils!");
|
|
4
4
|
const secret_name = "elections_config";
|
|
5
5
|
const secrets_manager = new SecretsManager({ region: "us-east-1" });
|
|
6
|
-
const
|
|
6
|
+
const secret = await secrets_manager.getSecretValue({
|
|
7
7
|
SecretId: secret_name
|
|
8
8
|
});
|
|
9
|
-
const api_keys = JSON.parse(
|
|
9
|
+
const api_keys = JSON.parse(secret?.SecretString || "");
|
|
10
10
|
const config = {
|
|
11
11
|
google_email: "louishou@triangleanalytics.com",
|
|
12
12
|
alerts_email: "alerts@triangleanalytics.com",
|
|
@@ -216,5 +216,12 @@ const utils = new TriangleUtils(config);
|
|
|
216
216
|
// min_twitter_tweet_id : "2061610563679985813"
|
|
217
217
|
// })
|
|
218
218
|
// console.log(results)
|
|
219
|
-
const f = await utils.dynamodb.query_range("federal_election_donations:donor_address_state_id.federal_election_committee_id-receipt_date-federal_election_donation_id", { donor_address_state_id: "NH", federal_election_committee_id: "C00694323" }, { receipt_date: ["2021", "2023"] }, { compile: false })
|
|
220
|
-
console.log(f)
|
|
219
|
+
// const f = await utils.dynamodb.query_range("federal_election_donations:donor_address_state_id.federal_election_committee_id-receipt_date-federal_election_donation_id", { donor_address_state_id : "NH", federal_election_committee_id : "C00694323" }, { receipt_date : ["2021", "2023"] }, { compile : false })
|
|
220
|
+
// console.log(f)
|
|
221
|
+
console.log("YERP");
|
|
222
|
+
const response = await utils.bedrock.claude_converse("anthropic.claude-opus-4-8", [
|
|
223
|
+
{ role: "user", text: "Hi" }
|
|
224
|
+
], {
|
|
225
|
+
print_usage: true
|
|
226
|
+
});
|
|
227
|
+
console.log(response);
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime"
|
|
2
2
|
import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
|
|
3
3
|
|
|
4
|
+
const role_ids = ["user", "assistant", "system"] as const
|
|
5
|
+
|
|
6
|
+
export type RoleID = typeof role_ids[number]
|
|
7
|
+
|
|
8
|
+
export function is_role_id(role_id : any) : role_id is RoleID {
|
|
9
|
+
return role_ids.includes(role_id)
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export class UtilsBedrock {
|
|
5
13
|
|
|
6
14
|
private readonly bedrock_runtime : BedrockRuntime
|
|
@@ -16,7 +24,7 @@ export class UtilsBedrock {
|
|
|
16
24
|
|
|
17
25
|
async claude_converse(
|
|
18
26
|
model_id : string,
|
|
19
|
-
messages : { role :
|
|
27
|
+
messages : { role : RoleID, text : string }[],
|
|
20
28
|
options : {
|
|
21
29
|
system_prompt? : string,
|
|
22
30
|
max_tokens? : number,
|
|
@@ -27,7 +35,6 @@ export class UtilsBedrock {
|
|
|
27
35
|
} = {}
|
|
28
36
|
) {
|
|
29
37
|
try {
|
|
30
|
-
|
|
31
38
|
const response = await this.anthropic_bedrock_mantle.messages.create({
|
|
32
39
|
model : model_id,
|
|
33
40
|
messages : messages.map(message => ({
|
|
@@ -48,10 +55,10 @@ export class UtilsBedrock {
|
|
|
48
55
|
schema : options.json_format
|
|
49
56
|
}
|
|
50
57
|
} : undefined,
|
|
51
|
-
cache_control : {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
58
|
+
// cache_control : {
|
|
59
|
+
// type : "ephemeral",
|
|
60
|
+
// ttl : options.cache_period
|
|
61
|
+
// }
|
|
55
62
|
})
|
|
56
63
|
|
|
57
64
|
const usage = response.usage
|
package/src/f.ts
CHANGED
|
@@ -7,11 +7,11 @@ const secret_name = "elections_config"
|
|
|
7
7
|
|
|
8
8
|
const secrets_manager = new SecretsManager({ region: "us-east-1" })
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const secret = await secrets_manager.getSecretValue({
|
|
11
11
|
SecretId: secret_name
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
const api_keys = JSON.parse(
|
|
14
|
+
const api_keys = JSON.parse(secret?.SecretString || "")
|
|
15
15
|
|
|
16
16
|
const config = {
|
|
17
17
|
google_email : "louishou@triangleanalytics.com",
|
|
@@ -250,6 +250,17 @@ const utils = new TriangleUtils(config)
|
|
|
250
250
|
|
|
251
251
|
// console.log(results)
|
|
252
252
|
|
|
253
|
-
const f = await utils.dynamodb.query_range("federal_election_donations:donor_address_state_id.federal_election_committee_id-receipt_date-federal_election_donation_id", { donor_address_state_id : "NH", federal_election_committee_id : "C00694323" }, { receipt_date : ["2021", "2023"] }, { compile : false })
|
|
254
|
-
|
|
255
|
-
console.log(f)
|
|
253
|
+
// const f = await utils.dynamodb.query_range("federal_election_donations:donor_address_state_id.federal_election_committee_id-receipt_date-federal_election_donation_id", { donor_address_state_id : "NH", federal_election_committee_id : "C00694323" }, { receipt_date : ["2021", "2023"] }, { compile : false })
|
|
254
|
+
|
|
255
|
+
// console.log(f)
|
|
256
|
+
console.log("YERP")
|
|
257
|
+
const response = await utils.bedrock.claude_converse(
|
|
258
|
+
"anthropic.claude-opus-4-8",
|
|
259
|
+
[
|
|
260
|
+
{ role : "user", text : "Hi" }
|
|
261
|
+
],
|
|
262
|
+
{
|
|
263
|
+
print_usage : true
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
console.log(response)
|