triangle-utils 1.4.66 → 1.4.68

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.
@@ -1,6 +1,7 @@
1
1
  export declare class UtilsTwitter {
2
2
  private readonly twitter;
3
3
  constructor(twitter_api_key: string | undefined);
4
+ get_user(user_id: string): Promise<any>;
4
5
  get_user_by_username(username: string): Promise<any>;
5
6
  get_tweets(user_id: string): Promise<any>;
6
7
  }
@@ -4,6 +4,38 @@ export class UtilsTwitter {
4
4
  constructor(twitter_api_key) {
5
5
  this.twitter = new Client({ bearerToken: twitter_api_key });
6
6
  }
7
+ async get_user(user_id) {
8
+ const result = await this.twitter.users.getById(user_id, { userFields: [
9
+ "affiliation",
10
+ // "confirmed_email",
11
+ "connection_status",
12
+ "created_at",
13
+ "description",
14
+ "entities",
15
+ "id",
16
+ "is_identity_verified",
17
+ "location",
18
+ "most_recent_tweet_id",
19
+ "name",
20
+ "parody",
21
+ "pinned_tweet_id",
22
+ "profile_banner_url",
23
+ "profile_image_url",
24
+ "protected",
25
+ // "public_metrics",
26
+ // "receives_your_dm",
27
+ "subscription",
28
+ "subscription_type",
29
+ "url",
30
+ "username",
31
+ "verified",
32
+ "verified_followers_count",
33
+ "verified_type",
34
+ "withheld"
35
+ ] })
36
+ .then(response => response.data);
37
+ return result;
38
+ }
7
39
  async get_user_by_username(username) {
8
40
  const result = await this.twitter.users.getByUsername(username, { userFields: [
9
41
  "affiliation",
@@ -37,7 +69,7 @@ export class UtilsTwitter {
37
69
  return result;
38
70
  }
39
71
  async get_tweets(user_id) {
40
- const tweets = await this.twitter.users.getPosts(user_id, { tweetFields: [
72
+ const response = await this.twitter.users.getPosts(user_id, { tweetFields: [
41
73
  "article",
42
74
  "attachments",
43
75
  "author_id",
@@ -68,8 +100,8 @@ export class UtilsTwitter {
68
100
  "suggested_source_links_with_counts",
69
101
  "text",
70
102
  "withheld"
71
- ] })
72
- .then(response => response.data);
73
- return tweets;
103
+ ] });
104
+ console.log("RESPONSE", response);
105
+ return response.data;
74
106
  }
75
107
  }
@@ -18,6 +18,12 @@ export interface GrokResponse {
18
18
  export declare class UtilsXAI {
19
19
  private readonly xai_api_key;
20
20
  constructor(xai_api_key: string | undefined);
21
+ grok_simple_query(model_id: string, prompt: string, options?: {
22
+ max_tokens?: number;
23
+ print_usage?: boolean;
24
+ json_format?: Record<string, any>;
25
+ web?: boolean;
26
+ }): Promise<string | undefined>;
21
27
  grok_query(model: string, prompt: string, conversation_history?: GrokMessage[], options?: {
22
28
  require_sources: boolean;
23
29
  }): Promise<GrokResponse | undefined>;
@@ -28,6 +28,46 @@ export class UtilsXAI {
28
28
  constructor(xai_api_key) {
29
29
  this.xai_api_key = xai_api_key;
30
30
  }
31
+ async grok_simple_query(model_id, prompt, options = {}) {
32
+ const response = await fetch("https://api.x.ai/v1/responses", {
33
+ method: "POST",
34
+ body: JSON.stringify({
35
+ model: model_id,
36
+ input: prompt,
37
+ tools: [
38
+ {
39
+ type: "x_search"
40
+ }
41
+ ],
42
+ temperature: 0,
43
+ max_output_tokens: options.max_tokens || 1000,
44
+ reasoning: {
45
+ effort: "low"
46
+ },
47
+ text: options.json_format !== undefined ? {
48
+ format: {
49
+ type: "json_schema",
50
+ name: "response",
51
+ strict: true,
52
+ schema: options.json_format
53
+ }
54
+ } : undefined
55
+ }),
56
+ headers: {
57
+ "Accept": "application/json",
58
+ "Content-type": "application/json",
59
+ "Authorization": "Bearer " + this.xai_api_key
60
+ }
61
+ });
62
+ const output = await response.json();
63
+ if (options.print_usage !== undefined && options.print_usage) {
64
+ console.log(output.usage);
65
+ }
66
+ const content = output.output.at(-1).content;
67
+ const grok_message = content[0];
68
+ const text = grok_message.text;
69
+ return text;
70
+ }
31
71
  async grok_query(model, prompt, conversation_history = [], options) {
32
72
  const require_sources = options !== undefined ? options.require_sources : false;
33
73
  if (this.xai_api_key === undefined) {
package/dist/src/f.js CHANGED
@@ -1,20 +1,40 @@
1
- // import { SecretsManager } from "@aws-sdk/client-secrets-manager"
2
- // import { TriangleUtils } from "./index.js"
3
- // console.log("Starting triangle-utils!")
4
- // const secret_name = "triage_config"
5
- // const secrets_manager = new SecretsManager({ region: "us-east-1" })
6
- // const response = await secrets_manager.getSecretValue({
7
- // SecretId: secret_name
8
- // })
9
- // const api_keys = JSON.parse(response?.SecretString || "")
10
- // const config = {
11
- // google_email : "louishou@triangleanalytics.com",
12
- // alerts_email : "alerts@triangleanalytics.com",
13
- // region : "us-east-1",
14
- // ...api_keys
15
- // }
16
- // console.log(config)
17
- // const utils = new TriangleUtils(config)
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
+ import { TriangleUtils } from "./index.js";
3
+ console.log("Starting triangle-utils!");
4
+ const secret_name = "elections_config";
5
+ const secrets_manager = new SecretsManager({ region: "us-east-1" });
6
+ const response = await secrets_manager.getSecretValue({
7
+ SecretId: secret_name
8
+ });
9
+ const api_keys = JSON.parse(response?.SecretString || "");
10
+ const config = {
11
+ google_email: "louishou@triangleanalytics.com",
12
+ alerts_email: "alerts@triangleanalytics.com",
13
+ region: "us-east-1",
14
+ ...api_keys
15
+ };
16
+ console.log(config);
17
+ const utils = new TriangleUtils(config);
18
+ 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
+ print_usage: true,
20
+ json_format: {
21
+ type: "object",
22
+ properties: {
23
+ username: {
24
+ type: "string"
25
+ },
26
+ explanation: {
27
+ type: "string"
28
+ }
29
+ },
30
+ required: [
31
+ "username",
32
+ "explanation"
33
+ ],
34
+ additionalProperties: false
35
+ }
36
+ });
37
+ console.log(text);
18
38
  // const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
19
39
  // console.log(foods)
20
40
  // const text = await utils.bee.get("https://www.doyourjobs.org", { return_page_text : true })
@@ -49,9 +69,9 @@
49
69
  // }
50
70
  // )
51
71
  // console.log(output)
52
- import { Client } from "@xdevplatform/xdk";
53
- const x = new Client({ bearerToken: "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534%2Fd9dKmieHRY6vQkv2s%3DyY2VerXmrA7w794ACFr9ALvoaJfuAHSlWwZdiDeVaOVpA6HCub" });
54
- // const user = await x.users.getByUsername("Iam_award", { userFields : [
72
+ // import { Client } from "@xdevplatform/xdk"
73
+ // const x = new Client({ bearerToken : "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534%2Fd9dKmieHRY6vQkv2s%3DyY2VerXmrA7w794ACFr9ALvoaJfuAHSlWwZdiDeVaOVpA6HCub" })
74
+ // const user = await x.users.getByUsername("umichvoter", { userFields : [
55
75
  // "affiliation",
56
76
  // // "confirmed_email",
57
77
  // "connection_status",
@@ -80,40 +100,41 @@ const x = new Client({ bearerToken: "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534
80
100
  // "withheld"
81
101
  // ] })
82
102
  // console.log(JSON.stringify(user, null, 4))
83
- const tweets = await x.users.getPosts("0000000000184903215", { tweetFields: [
84
- "article",
85
- "attachments",
86
- "author_id",
87
- "card_uri",
88
- "community_id",
89
- "context_annotations",
90
- "conversation_id",
91
- "created_at",
92
- "display_text_range",
93
- "edit_controls",
94
- "edit_history_tweet_ids",
95
- "entities",
96
- "geo",
97
- "id",
98
- "in_reply_to_user_id",
99
- "lang",
100
- "matched_media_notes",
101
- "media_metadata",
102
- "note_request_suggestions",
103
- "note_tweet",
104
- "paid_partnership",
105
- "possibly_sensitive",
106
- "referenced_tweets",
107
- "reply_settings",
108
- "scopes",
109
- "source",
110
- "suggested_source_links",
111
- "suggested_source_links_with_counts",
112
- "text",
113
- "withheld"
114
- ] });
115
- for (const tweet of tweets.data || []) {
116
- console.log(JSON.stringify(tweet, undefined, 4));
117
- }
103
+ // const tweets = await x.users.getPosts(user.data?.id || "", { tweetFields : [
104
+ // "article",
105
+ // "attachments",
106
+ // "author_id",
107
+ // "card_uri",
108
+ // "community_id",
109
+ // "context_annotations",
110
+ // "conversation_id",
111
+ // "created_at",
112
+ // "display_text_range",
113
+ // "edit_controls",
114
+ // "edit_history_tweet_ids",
115
+ // "entities",
116
+ // "geo",
117
+ // "id",
118
+ // "in_reply_to_user_id",
119
+ // "lang",
120
+ // "matched_media_notes",
121
+ // "media_metadata",
122
+ // "note_request_suggestions",
123
+ // "note_tweet",
124
+ // "paid_partnership",
125
+ // "possibly_sensitive",
126
+ // "referenced_tweets",
127
+ // "reply_settings",
128
+ // "scopes",
129
+ // "source",
130
+ // "suggested_source_links",
131
+ // "suggested_source_links_with_counts",
132
+ // "text",
133
+ // "withheld"
134
+ // ]})
135
+ // console.log(tweets)
136
+ // for (const tweet of tweets.data || []) {
137
+ // console.log(JSON.stringify(tweet, undefined, 4))
138
+ // }
118
139
  // const tweet = await x.posts.getReposts("2068675973722128815")
119
140
  // console.log(tweets)
package/f.txt ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.66",
3
+ "version": "1.4.68",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -8,6 +8,39 @@ export class UtilsTwitter {
8
8
  this.twitter = new Client({ bearerToken : twitter_api_key })
9
9
  }
10
10
 
11
+ async get_user(user_id : string) : Promise<any> {
12
+ const result = await this.twitter.users.getById(user_id, { userFields : [
13
+ "affiliation",
14
+ // "confirmed_email",
15
+ "connection_status",
16
+ "created_at",
17
+ "description",
18
+ "entities",
19
+ "id",
20
+ "is_identity_verified",
21
+ "location",
22
+ "most_recent_tweet_id",
23
+ "name",
24
+ "parody",
25
+ "pinned_tweet_id",
26
+ "profile_banner_url",
27
+ "profile_image_url",
28
+ "protected",
29
+ // "public_metrics",
30
+ // "receives_your_dm",
31
+ "subscription",
32
+ "subscription_type",
33
+ "url",
34
+ "username",
35
+ "verified",
36
+ "verified_followers_count",
37
+ "verified_type",
38
+ "withheld"
39
+ ] })
40
+ .then(response => response.data)
41
+ return result
42
+ }
43
+
11
44
  async get_user_by_username(username : string) : Promise<any> {
12
45
  const result = await this.twitter.users.getByUsername(username, { userFields : [
13
46
  "affiliation",
@@ -42,7 +75,7 @@ export class UtilsTwitter {
42
75
  }
43
76
 
44
77
  async get_tweets(user_id : string) : Promise<any> {
45
- const tweets = await this.twitter.users.getPosts(user_id, { tweetFields : [
78
+ const response = await this.twitter.users.getPosts(user_id, { tweetFields : [
46
79
  "article",
47
80
  "attachments",
48
81
  "author_id",
@@ -74,7 +107,7 @@ export class UtilsTwitter {
74
107
  "text",
75
108
  "withheld"
76
109
  ]})
77
- .then(response => response.data)
78
- return tweets
110
+ console.log("RESPONSE", response)
111
+ return response.data
79
112
  }
80
113
  }
package/src/UtilsXAI.ts CHANGED
@@ -46,6 +46,57 @@ export class UtilsXAI {
46
46
  this.xai_api_key = xai_api_key
47
47
  }
48
48
 
49
+ async grok_simple_query(
50
+ model_id : string,
51
+ prompt : string,
52
+ options : {
53
+ max_tokens? : number,
54
+ print_usage? : boolean,
55
+ json_format? : Record<string, any>,
56
+ web? : boolean
57
+ } = {}
58
+ ) : Promise<string | undefined> {
59
+ const response = await fetch("https://api.x.ai/v1/responses", {
60
+ method: "POST",
61
+ body : JSON.stringify({
62
+ model: model_id,
63
+ input: prompt,
64
+ tools : [
65
+ {
66
+ type : "x_search"
67
+ }
68
+ ],
69
+ temperature : 0,
70
+ max_output_tokens : options.max_tokens || 1000,
71
+ reasoning : {
72
+ effort : "low"
73
+ },
74
+ text : options.json_format !== undefined ? {
75
+ format : {
76
+ type : "json_schema",
77
+ name : "response",
78
+ strict : true,
79
+ schema : options.json_format
80
+ }
81
+ } : undefined
82
+
83
+ }),
84
+ headers: {
85
+ "Accept" : "application/json",
86
+ "Content-type" : "application/json",
87
+ "Authorization" : "Bearer " + this.xai_api_key
88
+ }
89
+ })
90
+ const output = await response.json()
91
+ if (options.print_usage !== undefined && options.print_usage) {
92
+ console.log(output.usage)
93
+ }
94
+ const content = output.output.at(-1).content
95
+ const grok_message = content[0]
96
+ const text = grok_message.text
97
+ return text
98
+ }
99
+
49
100
  async grok_query(model : string, prompt : string, conversation_history : GrokMessage[] = [], options? : { require_sources : boolean }) : Promise<GrokResponse | undefined> {
50
101
  const require_sources = options !== undefined ? options.require_sources : false
51
102
  if (this.xai_api_key === undefined) {
package/src/f.ts CHANGED
@@ -1,28 +1,49 @@
1
- // import { SecretsManager } from "@aws-sdk/client-secrets-manager"
2
- // import { TriangleUtils } from "."
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager"
2
+ import { TriangleUtils } from "."
3
3
 
4
- // console.log("Starting triangle-utils!")
4
+ console.log("Starting triangle-utils!")
5
5
 
6
- // const secret_name = "triage_config"
6
+ const secret_name = "elections_config"
7
7
 
8
- // const secrets_manager = new SecretsManager({ region: "us-east-1" })
8
+ const secrets_manager = new SecretsManager({ region: "us-east-1" })
9
9
 
10
- // const response = await secrets_manager.getSecretValue({
11
- // SecretId: secret_name
12
- // })
10
+ const response = await secrets_manager.getSecretValue({
11
+ SecretId: secret_name
12
+ })
13
13
 
14
- // const api_keys = JSON.parse(response?.SecretString || "")
14
+ const api_keys = JSON.parse(response?.SecretString || "")
15
15
 
16
- // const config = {
17
- // google_email : "louishou@triangleanalytics.com",
18
- // alerts_email : "alerts@triangleanalytics.com",
19
- // region : "us-east-1",
20
- // ...api_keys
21
- // }
22
-
23
- // console.log(config)
16
+ const config = {
17
+ google_email : "louishou@triangleanalytics.com",
18
+ alerts_email : "alerts@triangleanalytics.com",
19
+ region : "us-east-1",
20
+ ...api_keys
21
+ }
24
22
 
25
- // const utils = new TriangleUtils(config)
23
+ console.log(config)
24
+
25
+ const utils = new TriangleUtils(config)
26
+
27
+ 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
+ print_usage : true,
29
+ json_format : {
30
+ type : "object",
31
+ properties : {
32
+ username : {
33
+ type: "string"
34
+ },
35
+ explanation : {
36
+ type: "string"
37
+ }
38
+ },
39
+ required : [
40
+ "username",
41
+ "explanation"
42
+ ],
43
+ additionalProperties : false
44
+ }
45
+ })
46
+ console.log(text)
26
47
 
27
48
  // const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
28
49
 
@@ -68,12 +89,12 @@
68
89
 
69
90
  // console.log(output)
70
91
 
71
- import { Client } from "@xdevplatform/xdk"
92
+ // import { Client } from "@xdevplatform/xdk"
72
93
 
73
- const x = new Client({ bearerToken : "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534%2Fd9dKmieHRY6vQkv2s%3DyY2VerXmrA7w794ACFr9ALvoaJfuAHSlWwZdiDeVaOVpA6HCub" })
94
+ // const x = new Client({ bearerToken : "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534%2Fd9dKmieHRY6vQkv2s%3DyY2VerXmrA7w794ACFr9ALvoaJfuAHSlWwZdiDeVaOVpA6HCub" })
74
95
 
75
96
 
76
- // const user = await x.users.getByUsername("Iam_award", { userFields : [
97
+ // const user = await x.users.getByUsername("umichvoter", { userFields : [
77
98
  // "affiliation",
78
99
  // // "confirmed_email",
79
100
  // "connection_status",
@@ -104,42 +125,44 @@ const x = new Client({ bearerToken : "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP53
104
125
 
105
126
  // console.log(JSON.stringify(user, null, 4))
106
127
 
107
- const tweets = await x.users.getPosts("0000000000184903215", { tweetFields : [
108
- "article",
109
- "attachments",
110
- "author_id",
111
- "card_uri",
112
- "community_id",
113
- "context_annotations",
114
- "conversation_id",
115
- "created_at",
116
- "display_text_range",
117
- "edit_controls",
118
- "edit_history_tweet_ids",
119
- "entities",
120
- "geo",
121
- "id",
122
- "in_reply_to_user_id",
123
- "lang",
124
- "matched_media_notes",
125
- "media_metadata",
126
- "note_request_suggestions",
127
- "note_tweet",
128
- "paid_partnership",
129
- "possibly_sensitive",
130
- "referenced_tweets",
131
- "reply_settings",
132
- "scopes",
133
- "source",
134
- "suggested_source_links",
135
- "suggested_source_links_with_counts",
136
- "text",
137
- "withheld"
138
- ]})
139
-
140
- for (const tweet of tweets.data || []) {
141
- console.log(JSON.stringify(tweet, undefined, 4))
142
- }
128
+ // const tweets = await x.users.getPosts(user.data?.id || "", { tweetFields : [
129
+ // "article",
130
+ // "attachments",
131
+ // "author_id",
132
+ // "card_uri",
133
+ // "community_id",
134
+ // "context_annotations",
135
+ // "conversation_id",
136
+ // "created_at",
137
+ // "display_text_range",
138
+ // "edit_controls",
139
+ // "edit_history_tweet_ids",
140
+ // "entities",
141
+ // "geo",
142
+ // "id",
143
+ // "in_reply_to_user_id",
144
+ // "lang",
145
+ // "matched_media_notes",
146
+ // "media_metadata",
147
+ // "note_request_suggestions",
148
+ // "note_tweet",
149
+ // "paid_partnership",
150
+ // "possibly_sensitive",
151
+ // "referenced_tweets",
152
+ // "reply_settings",
153
+ // "scopes",
154
+ // "source",
155
+ // "suggested_source_links",
156
+ // "suggested_source_links_with_counts",
157
+ // "text",
158
+ // "withheld"
159
+ // ]})
160
+
161
+ // console.log(tweets)
162
+
163
+ // for (const tweet of tweets.data || []) {
164
+ // console.log(JSON.stringify(tweet, undefined, 4))
165
+ // }
143
166
 
144
167
  // const tweet = await x.posts.getReposts("2068675973722128815")
145
168