triangle-utils 1.4.86 → 1.4.88
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 +1 -0
- package/dist/src/UtilsBedrock.js +3 -0
- package/dist/src/UtilsS3.js +12 -6
- package/dist/src/UtilsS3Vectors.js +7 -0
- package/dist/src/f.js +15 -8
- package/package.json +1 -1
- package/src/UtilsBedrock.ts +4 -0
- package/src/UtilsS3.ts +13 -7
- package/src/UtilsS3Vectors.ts +15 -0
- package/src/UtilsXAI.ts +1 -1
- package/src/f.ts +17 -12
package/dist/src/UtilsBedrock.js
CHANGED
|
@@ -44,6 +44,9 @@ export class UtilsBedrock {
|
|
|
44
44
|
if (options.print_usage !== undefined && options.print_usage) {
|
|
45
45
|
console.log(usage);
|
|
46
46
|
}
|
|
47
|
+
if (options.print_content !== undefined && options.print_content) {
|
|
48
|
+
console.log(response.content);
|
|
49
|
+
}
|
|
47
50
|
const text = response.content.filter(content => content.type === "text")[0].text;
|
|
48
51
|
return text;
|
|
49
52
|
}
|
package/dist/src/UtilsS3.js
CHANGED
|
@@ -103,21 +103,27 @@ export class UtilsS3 {
|
|
|
103
103
|
const s3_ids = [];
|
|
104
104
|
let last_token = undefined;
|
|
105
105
|
while (true) {
|
|
106
|
-
const
|
|
106
|
+
const request = {
|
|
107
107
|
Bucket: s3_key.Bucket,
|
|
108
108
|
Delimiter: "/",
|
|
109
109
|
Prefix: s3_key.Key,
|
|
110
110
|
ContinuationToken: last_token
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
const new_s3_ids = response.Contents
|
|
111
|
+
};
|
|
112
|
+
const response = await this.s3.listObjectsV2(request);
|
|
113
|
+
const new_s3_ids = (response.Contents || [])
|
|
116
114
|
.map(content => content.Key)
|
|
117
115
|
.filter(key => key !== undefined)
|
|
118
116
|
.filter(key => key.substring(key.length - 1) !== "/")
|
|
119
117
|
.map(key => "s3://" + s3_key.Bucket + "/" + key);
|
|
120
118
|
s3_ids.push(...new_s3_ids);
|
|
119
|
+
const sub_s3_id_prefixes = (response.CommonPrefixes || [])
|
|
120
|
+
.map(prefix => prefix.Prefix)
|
|
121
|
+
.filter(prefix => prefix !== undefined)
|
|
122
|
+
.map(prefix => "s3://" + s3_key.Bucket + "/" + prefix);
|
|
123
|
+
for (const sub_s3_id_prefix of sub_s3_id_prefixes) {
|
|
124
|
+
const new_sub_s3_ids = await this.query_prefix(sub_s3_id_prefix);
|
|
125
|
+
s3_ids.push(...new_sub_s3_ids);
|
|
126
|
+
}
|
|
121
127
|
if (response.NextContinuationToken === undefined || !compile) {
|
|
122
128
|
return s3_ids;
|
|
123
129
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { S3Vectors } from "@aws-sdk/client-s3vectors";
|
|
2
|
+
function get_vector_key(vector_id) {
|
|
3
|
+
const [vector_bucket_name, vector_index_name, vector_key] = (vector_id.match(/^s3vectors\:\/\/([^\/]+)\/([^\/]+)\/([^$]+)$/) || []).slice(1, 4);
|
|
4
|
+
if (vector_bucket_name === undefined || vector_index_name === undefined || vector_key === undefined) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return { vector_bucket_name: vector_bucket_name, vector_index_name: vector_index_name, vector_key: vector_key };
|
|
8
|
+
}
|
|
2
9
|
export class UtilsS3Vectors {
|
|
3
10
|
s3vectors;
|
|
4
11
|
constructor(region) {
|
package/dist/src/f.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
2
|
import { TriangleUtils } from "./index.js";
|
|
3
3
|
console.log("Starting triangle-utils!");
|
|
4
|
-
const secret_name = "
|
|
4
|
+
const secret_name = "global_config";
|
|
5
5
|
const secrets_manager = new SecretsManager({ region: "us-east-1" });
|
|
6
6
|
const secret = await secrets_manager.getSecretValue({
|
|
7
7
|
SecretId: secret_name
|
|
@@ -15,6 +15,9 @@ const config = {
|
|
|
15
15
|
};
|
|
16
16
|
console.log(config);
|
|
17
17
|
const utils = new TriangleUtils(config);
|
|
18
|
+
const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/";
|
|
19
|
+
const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile: true });
|
|
20
|
+
console.log(raw_s3_ids);
|
|
18
21
|
// const text = await utils.xai.grok_simple_query("grok-4.3", "Find the X username corresponding to the candidate of the committee \"Darializa for Congress\"", {
|
|
19
22
|
// print_usage : true,
|
|
20
23
|
// json_format : {
|
|
@@ -218,10 +221,14 @@ const utils = new TriangleUtils(config);
|
|
|
218
221
|
// console.log(results)
|
|
219
222
|
// 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
223
|
// console.log(f)
|
|
221
|
-
console.log("YERP")
|
|
222
|
-
const response = await utils.bedrock.claude_converse(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
// console.log("YERP")
|
|
225
|
+
// const response = await utils.bedrock.claude_converse(
|
|
226
|
+
// "anthropic.claude-opus-4-8",
|
|
227
|
+
// [
|
|
228
|
+
// { role : "user", text : "Hi" }
|
|
229
|
+
// ],
|
|
230
|
+
// {
|
|
231
|
+
// print_usage : true
|
|
232
|
+
// }
|
|
233
|
+
// )
|
|
234
|
+
// console.log(response)
|
package/package.json
CHANGED
package/src/UtilsBedrock.ts
CHANGED
|
@@ -29,6 +29,7 @@ export class UtilsBedrock {
|
|
|
29
29
|
system_prompt? : string,
|
|
30
30
|
max_tokens? : number,
|
|
31
31
|
print_usage? : boolean,
|
|
32
|
+
print_content? : boolean,
|
|
32
33
|
json_format? : Record<string, any>,
|
|
33
34
|
web? : boolean,
|
|
34
35
|
cache_period? : "5m" | "1h"
|
|
@@ -65,6 +66,9 @@ export class UtilsBedrock {
|
|
|
65
66
|
if (options.print_usage !== undefined && options.print_usage) {
|
|
66
67
|
console.log(usage)
|
|
67
68
|
}
|
|
69
|
+
if (options.print_content !== undefined && options.print_content) {
|
|
70
|
+
console.log(response.content)
|
|
71
|
+
}
|
|
68
72
|
const text = response.content.filter(content => content.type === "text")[0].text
|
|
69
73
|
return text
|
|
70
74
|
} catch (error) {
|
package/src/UtilsS3.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand, ListObjectsV2CommandOutput } from "@aws-sdk/client-s3"
|
|
1
|
+
import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand, ListObjectsV2CommandOutput, ListObjectsV2CommandInput } from "@aws-sdk/client-s3"
|
|
2
2
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
|
|
3
3
|
import { Readable } from "stream"
|
|
4
4
|
|
|
@@ -110,24 +110,30 @@ export class UtilsS3 {
|
|
|
110
110
|
if (s3_key === undefined) {
|
|
111
111
|
return []
|
|
112
112
|
}
|
|
113
|
-
const s3_ids = []
|
|
113
|
+
const s3_ids : string[] = []
|
|
114
114
|
let last_token : string | undefined = undefined
|
|
115
115
|
while (true) {
|
|
116
|
-
const
|
|
116
|
+
const request : ListObjectsV2CommandInput = {
|
|
117
117
|
Bucket : s3_key.Bucket,
|
|
118
118
|
Delimiter : "/",
|
|
119
119
|
Prefix : s3_key.Key,
|
|
120
120
|
ContinuationToken : last_token
|
|
121
|
-
})
|
|
122
|
-
if (response.Contents === undefined) {
|
|
123
|
-
return []
|
|
124
121
|
}
|
|
125
|
-
const
|
|
122
|
+
const response : ListObjectsV2CommandOutput = await this.s3.listObjectsV2(request)
|
|
123
|
+
const new_s3_ids = (response.Contents || [])
|
|
126
124
|
.map(content => content.Key)
|
|
127
125
|
.filter(key => key !== undefined)
|
|
128
126
|
.filter(key => key.substring(key.length - 1) !== "/")
|
|
129
127
|
.map(key => "s3://" + s3_key.Bucket + "/" + key)
|
|
130
128
|
s3_ids.push(...new_s3_ids)
|
|
129
|
+
const sub_s3_id_prefixes = (response.CommonPrefixes || [])
|
|
130
|
+
.map(prefix => prefix.Prefix)
|
|
131
|
+
.filter(prefix => prefix !== undefined)
|
|
132
|
+
.map(prefix => "s3://" + s3_key.Bucket + "/" + prefix)
|
|
133
|
+
for (const sub_s3_id_prefix of sub_s3_id_prefixes) {
|
|
134
|
+
const new_sub_s3_ids = await this.query_prefix(sub_s3_id_prefix)
|
|
135
|
+
s3_ids.push(...new_sub_s3_ids)
|
|
136
|
+
}
|
|
131
137
|
if (response.NextContinuationToken === undefined || !compile) {
|
|
132
138
|
return s3_ids
|
|
133
139
|
}
|
package/src/UtilsS3Vectors.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { ListVectorsCommandInput, S3Vectors } from "@aws-sdk/client-s3vectors"
|
|
2
2
|
|
|
3
|
+
interface VectorKey {
|
|
4
|
+
vector_bucket_name : string,
|
|
5
|
+
vector_index_name : string,
|
|
6
|
+
vector_key : string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function get_vector_key(vector_id : string) : VectorKey | undefined {
|
|
10
|
+
const [vector_bucket_name, vector_index_name, vector_key] = (vector_id.match(/^s3vectors\:\/\/([^\/]+)\/([^\/]+)\/([^$]+)$/) || []).slice(1, 4)
|
|
11
|
+
if (vector_bucket_name === undefined || vector_index_name === undefined || vector_key === undefined) {
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
return { vector_bucket_name : vector_bucket_name, vector_index_name : vector_index_name, vector_key : vector_key }
|
|
15
|
+
}
|
|
16
|
+
|
|
3
17
|
export interface Vector {
|
|
18
|
+
|
|
4
19
|
key : string,
|
|
5
20
|
data : number[],
|
|
6
21
|
metadata : any
|
package/src/UtilsXAI.ts
CHANGED
|
@@ -90,7 +90,7 @@ export class UtilsXAI {
|
|
|
90
90
|
"Authorization" : "Bearer " + this.xai_api_key
|
|
91
91
|
}
|
|
92
92
|
})
|
|
93
|
-
const output = await response.json()
|
|
93
|
+
const output : any = await response.json()
|
|
94
94
|
if (options.print_usage !== undefined && options.print_usage) {
|
|
95
95
|
console.log(output.usage)
|
|
96
96
|
}
|
package/src/f.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TriangleUtils } from "."
|
|
|
3
3
|
|
|
4
4
|
console.log("Starting triangle-utils!")
|
|
5
5
|
|
|
6
|
-
const secret_name = "
|
|
6
|
+
const secret_name = "global_config"
|
|
7
7
|
|
|
8
8
|
const secrets_manager = new SecretsManager({ region: "us-east-1" })
|
|
9
9
|
|
|
@@ -24,6 +24,11 @@ console.log(config)
|
|
|
24
24
|
|
|
25
25
|
const utils = new TriangleUtils(config)
|
|
26
26
|
|
|
27
|
+
const raw_s3_id_prefix = config.s3_scout + "/raw_scout_documents/57523929653b604e/"
|
|
28
|
+
const raw_s3_ids = await utils.s3.query_prefix(raw_s3_id_prefix, { compile : true })
|
|
29
|
+
|
|
30
|
+
console.log(raw_s3_ids)
|
|
31
|
+
|
|
27
32
|
// const text = await utils.xai.grok_simple_query("grok-4.3", "Find the X username corresponding to the candidate of the committee \"Darializa for Congress\"", {
|
|
28
33
|
// print_usage : true,
|
|
29
34
|
// json_format : {
|
|
@@ -253,14 +258,14 @@ const utils = new TriangleUtils(config)
|
|
|
253
258
|
// 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
259
|
|
|
255
260
|
// console.log(f)
|
|
256
|
-
console.log("YERP")
|
|
257
|
-
const response = await utils.bedrock.claude_converse(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
console.log(response)
|
|
261
|
+
// console.log("YERP")
|
|
262
|
+
// const response = await utils.bedrock.claude_converse(
|
|
263
|
+
// "anthropic.claude-opus-4-8",
|
|
264
|
+
// [
|
|
265
|
+
// { role : "user", text : "Hi" }
|
|
266
|
+
// ],
|
|
267
|
+
// {
|
|
268
|
+
// print_usage : true
|
|
269
|
+
// }
|
|
270
|
+
// )
|
|
271
|
+
// console.log(response)
|