triangle-utils 1.4.65 → 1.4.67
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/UtilsTwitter.d.ts +6 -0
- package/dist/src/UtilsTwitter.js +75 -0
- package/dist/src/UtilsXAI.d.ts +6 -0
- package/dist/src/UtilsXAI.js +40 -0
- package/dist/src/f.js +118 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +4 -4
- package/f.txt +0 -0
- package/package.json +2 -1
- package/src/UtilsTwitter.ts +80 -0
- package/src/UtilsXAI.ts +51 -0
- package/src/f.ts +133 -6
- package/src/index.ts +4 -4
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Client } from "@xdevplatform/xdk";
|
|
2
|
+
export class UtilsTwitter {
|
|
3
|
+
twitter;
|
|
4
|
+
constructor(twitter_api_key) {
|
|
5
|
+
this.twitter = new Client({ bearerToken: twitter_api_key });
|
|
6
|
+
}
|
|
7
|
+
async get_user_by_username(username) {
|
|
8
|
+
const result = await this.twitter.users.getByUsername(username, { 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
|
+
}
|
|
39
|
+
async get_tweets(user_id) {
|
|
40
|
+
const response = await this.twitter.users.getPosts(user_id, { tweetFields: [
|
|
41
|
+
"article",
|
|
42
|
+
"attachments",
|
|
43
|
+
"author_id",
|
|
44
|
+
"card_uri",
|
|
45
|
+
"community_id",
|
|
46
|
+
"context_annotations",
|
|
47
|
+
"conversation_id",
|
|
48
|
+
"created_at",
|
|
49
|
+
"display_text_range",
|
|
50
|
+
"edit_controls",
|
|
51
|
+
"edit_history_tweet_ids",
|
|
52
|
+
"entities",
|
|
53
|
+
"geo",
|
|
54
|
+
"id",
|
|
55
|
+
"in_reply_to_user_id",
|
|
56
|
+
"lang",
|
|
57
|
+
"matched_media_notes",
|
|
58
|
+
"media_metadata",
|
|
59
|
+
"note_request_suggestions",
|
|
60
|
+
"note_tweet",
|
|
61
|
+
"paid_partnership",
|
|
62
|
+
"possibly_sensitive",
|
|
63
|
+
"referenced_tweets",
|
|
64
|
+
"reply_settings",
|
|
65
|
+
"scopes",
|
|
66
|
+
"source",
|
|
67
|
+
"suggested_source_links",
|
|
68
|
+
"suggested_source_links_with_counts",
|
|
69
|
+
"text",
|
|
70
|
+
"withheld"
|
|
71
|
+
] });
|
|
72
|
+
console.log("RESPONSE", response);
|
|
73
|
+
return response.data;
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/src/UtilsXAI.d.ts
CHANGED
|
@@ -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>;
|
package/dist/src/UtilsXAI.js
CHANGED
|
@@ -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,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 = "elections_config";
|
|
5
5
|
const secrets_manager = new SecretsManager({ region: "us-east-1" });
|
|
6
6
|
const response = await secrets_manager.getSecretValue({
|
|
7
7
|
SecretId: secret_name
|
|
@@ -15,12 +15,126 @@ const config = {
|
|
|
15
15
|
};
|
|
16
16
|
console.log(config);
|
|
17
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 })
|
|
21
41
|
// console.log(text)
|
|
22
42
|
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
23
43
|
// console.log(text)
|
|
24
|
-
const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379"
|
|
25
|
-
const html = await utils.bee.get(url, { render_js: false })
|
|
26
|
-
console.log(html)
|
|
44
|
+
// const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379"
|
|
45
|
+
// const html = await utils.bee.get(url, { render_js : false })
|
|
46
|
+
// console.log(html)
|
|
47
|
+
// const prompt = "Is Mark Kelly a veteran?"
|
|
48
|
+
// console.log(prompt)
|
|
49
|
+
// const output = await utils.anthropic.claude_query("claude-opus-4-8",
|
|
50
|
+
// prompt,
|
|
51
|
+
// undefined,
|
|
52
|
+
// {
|
|
53
|
+
// print_usage : true,
|
|
54
|
+
// max_tokens : 20000,
|
|
55
|
+
// json_format : {
|
|
56
|
+
// type : "object",
|
|
57
|
+
// properties : {
|
|
58
|
+
// is_veteran : {
|
|
59
|
+
// type : "string"
|
|
60
|
+
// },
|
|
61
|
+
// explanation : {
|
|
62
|
+
// type : "string"
|
|
63
|
+
// }
|
|
64
|
+
// },
|
|
65
|
+
// required : ["is_veteran", "explanation"],
|
|
66
|
+
// additionalProperties : false
|
|
67
|
+
// },
|
|
68
|
+
// web : true
|
|
69
|
+
// }
|
|
70
|
+
// )
|
|
71
|
+
// console.log(output)
|
|
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 : [
|
|
75
|
+
// "affiliation",
|
|
76
|
+
// // "confirmed_email",
|
|
77
|
+
// "connection_status",
|
|
78
|
+
// "created_at",
|
|
79
|
+
// "description",
|
|
80
|
+
// "entities",
|
|
81
|
+
// "id",
|
|
82
|
+
// "is_identity_verified",
|
|
83
|
+
// "location",
|
|
84
|
+
// "most_recent_tweet_id",
|
|
85
|
+
// "name",
|
|
86
|
+
// "parody",
|
|
87
|
+
// "pinned_tweet_id",
|
|
88
|
+
// "profile_banner_url",
|
|
89
|
+
// "profile_image_url",
|
|
90
|
+
// "protected",
|
|
91
|
+
// "public_metrics",
|
|
92
|
+
// // "receives_your_dm",
|
|
93
|
+
// "subscription",
|
|
94
|
+
// "subscription_type",
|
|
95
|
+
// "url",
|
|
96
|
+
// "username",
|
|
97
|
+
// "verified",
|
|
98
|
+
// "verified_followers_count",
|
|
99
|
+
// "verified_type",
|
|
100
|
+
// "withheld"
|
|
101
|
+
// ] })
|
|
102
|
+
// console.log(JSON.stringify(user, null, 4))
|
|
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
|
+
// }
|
|
139
|
+
// const tweet = await x.posts.getReposts("2068675973722128815")
|
|
140
|
+
// console.log(tweets)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { UtilsSES } from "./UtilsSES.js";
|
|
|
9
9
|
import { UtilsMisc } from "./UtilsMisc.js";
|
|
10
10
|
import { UtilsYoutube } from "./UtilsYoutube.js";
|
|
11
11
|
import { UtilsXAI } from "./UtilsXAI.js";
|
|
12
|
-
import { UtilsNitter } from "./UtilsNitter.js";
|
|
13
12
|
import { UtilsAnthropic } from "./UtilsAnthropic.js";
|
|
13
|
+
import { UtilsTwitter } from "./UtilsTwitter.js";
|
|
14
14
|
export declare class TriangleUtils extends UtilsMisc {
|
|
15
15
|
readonly dynamodb: UtilsDynamoDB;
|
|
16
16
|
readonly s3: UtilsS3;
|
|
@@ -22,7 +22,7 @@ export declare class TriangleUtils extends UtilsMisc {
|
|
|
22
22
|
readonly youtube: UtilsYoutube;
|
|
23
23
|
readonly anthropic: UtilsAnthropic;
|
|
24
24
|
readonly xai: UtilsXAI;
|
|
25
|
-
readonly
|
|
25
|
+
readonly twitter: UtilsTwitter;
|
|
26
26
|
constructor(config: TriangleUtilsConfig);
|
|
27
27
|
}
|
|
28
28
|
export * from "./types/TriangleUtilsConfig.js";
|
|
@@ -35,6 +35,6 @@ export * from "./UtilsBee.js";
|
|
|
35
35
|
export * from "./UtilsCognito.js";
|
|
36
36
|
export * from "./UtilsS3Vectors.js";
|
|
37
37
|
export * from "./UtilsSES.js";
|
|
38
|
-
export * from "./
|
|
38
|
+
export * from "./UtilsTwitter.js";
|
|
39
39
|
export * from "./UtilsXAI.js";
|
|
40
40
|
export * from "./UtilsYoutube.js";
|
package/dist/src/index.js
CHANGED
|
@@ -8,8 +8,8 @@ import { UtilsSES } from "./UtilsSES.js";
|
|
|
8
8
|
import { UtilsMisc } from "./UtilsMisc.js";
|
|
9
9
|
import { UtilsYoutube } from "./UtilsYoutube.js";
|
|
10
10
|
import { UtilsXAI } from "./UtilsXAI.js";
|
|
11
|
-
import { UtilsNitter } from "./UtilsNitter.js";
|
|
12
11
|
import { UtilsAnthropic } from "./UtilsAnthropic.js";
|
|
12
|
+
import { UtilsTwitter } from "./UtilsTwitter.js";
|
|
13
13
|
export class TriangleUtils extends UtilsMisc {
|
|
14
14
|
dynamodb;
|
|
15
15
|
s3;
|
|
@@ -21,7 +21,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
21
21
|
youtube;
|
|
22
22
|
anthropic;
|
|
23
23
|
xai;
|
|
24
|
-
|
|
24
|
+
twitter;
|
|
25
25
|
constructor(config) {
|
|
26
26
|
super(config);
|
|
27
27
|
this.dynamodb = new UtilsDynamoDB(config.region);
|
|
@@ -34,7 +34,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
34
34
|
this.youtube = new UtilsYoutube(config.youtube_api_key);
|
|
35
35
|
this.anthropic = new UtilsAnthropic(config.anthropic_api_key);
|
|
36
36
|
this.xai = new UtilsXAI(config.xai_api_key);
|
|
37
|
-
this.
|
|
37
|
+
this.twitter = new UtilsTwitter(config.twitter_api_key);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
export * from "./types/TriangleUtilsConfig.js";
|
|
@@ -47,6 +47,6 @@ export * from "./UtilsBee.js";
|
|
|
47
47
|
export * from "./UtilsCognito.js";
|
|
48
48
|
export * from "./UtilsS3Vectors.js";
|
|
49
49
|
export * from "./UtilsSES.js";
|
|
50
|
-
export * from "./
|
|
50
|
+
export * from "./UtilsTwitter.js";
|
|
51
51
|
export * from "./UtilsXAI.js";
|
|
52
52
|
export * from "./UtilsYoutube.js";
|
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.
|
|
3
|
+
"version": "1.4.67",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@types/jsdom": "^28.0.1",
|
|
28
28
|
"@types/node": "^25.2.3",
|
|
29
29
|
"@types/nodemailer": "^7.0.9",
|
|
30
|
+
"@xdevplatform/xdk": "^0.5.0",
|
|
30
31
|
"googleapis": "^170.0.0",
|
|
31
32
|
"jsdom": "^29.0.1",
|
|
32
33
|
"scrapingbee": "^1.8.2"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Client } from "@xdevplatform/xdk"
|
|
2
|
+
|
|
3
|
+
export class UtilsTwitter {
|
|
4
|
+
|
|
5
|
+
private readonly twitter : Client
|
|
6
|
+
|
|
7
|
+
constructor(twitter_api_key : string | undefined) {
|
|
8
|
+
this.twitter = new Client({ bearerToken : twitter_api_key })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async get_user_by_username(username : string) : Promise<any> {
|
|
12
|
+
const result = await this.twitter.users.getByUsername(username, { 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
|
+
|
|
44
|
+
async get_tweets(user_id : string) : Promise<any> {
|
|
45
|
+
const response = await this.twitter.users.getPosts(user_id, { tweetFields : [
|
|
46
|
+
"article",
|
|
47
|
+
"attachments",
|
|
48
|
+
"author_id",
|
|
49
|
+
"card_uri",
|
|
50
|
+
"community_id",
|
|
51
|
+
"context_annotations",
|
|
52
|
+
"conversation_id",
|
|
53
|
+
"created_at",
|
|
54
|
+
"display_text_range",
|
|
55
|
+
"edit_controls",
|
|
56
|
+
"edit_history_tweet_ids",
|
|
57
|
+
"entities",
|
|
58
|
+
"geo",
|
|
59
|
+
"id",
|
|
60
|
+
"in_reply_to_user_id",
|
|
61
|
+
"lang",
|
|
62
|
+
"matched_media_notes",
|
|
63
|
+
"media_metadata",
|
|
64
|
+
"note_request_suggestions",
|
|
65
|
+
"note_tweet",
|
|
66
|
+
"paid_partnership",
|
|
67
|
+
"possibly_sensitive",
|
|
68
|
+
"referenced_tweets",
|
|
69
|
+
"reply_settings",
|
|
70
|
+
"scopes",
|
|
71
|
+
"source",
|
|
72
|
+
"suggested_source_links",
|
|
73
|
+
"suggested_source_links_with_counts",
|
|
74
|
+
"text",
|
|
75
|
+
"withheld"
|
|
76
|
+
]})
|
|
77
|
+
console.log("RESPONSE", response)
|
|
78
|
+
return response.data
|
|
79
|
+
}
|
|
80
|
+
}
|
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
|
@@ -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 = "elections_config"
|
|
7
7
|
|
|
8
8
|
const secrets_manager = new SecretsManager({ region: "us-east-1" })
|
|
9
9
|
|
|
@@ -24,6 +24,27 @@ console.log(config)
|
|
|
24
24
|
|
|
25
25
|
const utils = new TriangleUtils(config)
|
|
26
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)
|
|
47
|
+
|
|
27
48
|
// const foods = await utils.dynamodb.query("triage_docket_documents:register_document_id", { register_document_id : "E6-17065" })
|
|
28
49
|
|
|
29
50
|
// console.log(foods)
|
|
@@ -35,8 +56,114 @@ const utils = new TriangleUtils(config)
|
|
|
35
56
|
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
36
57
|
// console.log(text)
|
|
37
58
|
|
|
38
|
-
const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379"
|
|
39
|
-
|
|
40
|
-
const html = await utils.bee.get(url, { render_js : false })
|
|
41
|
-
|
|
42
|
-
console.log(html)
|
|
59
|
+
// const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379"
|
|
60
|
+
|
|
61
|
+
// const html = await utils.bee.get(url, { render_js : false })
|
|
62
|
+
|
|
63
|
+
// console.log(html)
|
|
64
|
+
|
|
65
|
+
// const prompt = "Is Mark Kelly a veteran?"
|
|
66
|
+
// console.log(prompt)
|
|
67
|
+
// const output = await utils.anthropic.claude_query("claude-opus-4-8",
|
|
68
|
+
// prompt,
|
|
69
|
+
// undefined,
|
|
70
|
+
// {
|
|
71
|
+
// print_usage : true,
|
|
72
|
+
// max_tokens : 20000,
|
|
73
|
+
// json_format : {
|
|
74
|
+
// type : "object",
|
|
75
|
+
// properties : {
|
|
76
|
+
// is_veteran : {
|
|
77
|
+
// type : "string"
|
|
78
|
+
// },
|
|
79
|
+
// explanation : {
|
|
80
|
+
// type : "string"
|
|
81
|
+
// }
|
|
82
|
+
// },
|
|
83
|
+
// required : ["is_veteran", "explanation"],
|
|
84
|
+
// additionalProperties : false
|
|
85
|
+
// },
|
|
86
|
+
// web : true
|
|
87
|
+
// }
|
|
88
|
+
// )
|
|
89
|
+
|
|
90
|
+
// console.log(output)
|
|
91
|
+
|
|
92
|
+
// import { Client } from "@xdevplatform/xdk"
|
|
93
|
+
|
|
94
|
+
// const x = new Client({ bearerToken : "AAAAAAAAAAAAAAAAAAAAAKoQ%2BQEAAAAAaej7PP534%2Fd9dKmieHRY6vQkv2s%3DyY2VerXmrA7w794ACFr9ALvoaJfuAHSlWwZdiDeVaOVpA6HCub" })
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
// const user = await x.users.getByUsername("umichvoter", { userFields : [
|
|
98
|
+
// "affiliation",
|
|
99
|
+
// // "confirmed_email",
|
|
100
|
+
// "connection_status",
|
|
101
|
+
// "created_at",
|
|
102
|
+
// "description",
|
|
103
|
+
// "entities",
|
|
104
|
+
// "id",
|
|
105
|
+
// "is_identity_verified",
|
|
106
|
+
// "location",
|
|
107
|
+
// "most_recent_tweet_id",
|
|
108
|
+
// "name",
|
|
109
|
+
// "parody",
|
|
110
|
+
// "pinned_tweet_id",
|
|
111
|
+
// "profile_banner_url",
|
|
112
|
+
// "profile_image_url",
|
|
113
|
+
// "protected",
|
|
114
|
+
// "public_metrics",
|
|
115
|
+
// // "receives_your_dm",
|
|
116
|
+
// "subscription",
|
|
117
|
+
// "subscription_type",
|
|
118
|
+
// "url",
|
|
119
|
+
// "username",
|
|
120
|
+
// "verified",
|
|
121
|
+
// "verified_followers_count",
|
|
122
|
+
// "verified_type",
|
|
123
|
+
// "withheld"
|
|
124
|
+
// ] })
|
|
125
|
+
|
|
126
|
+
// console.log(JSON.stringify(user, null, 4))
|
|
127
|
+
|
|
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
|
+
// }
|
|
166
|
+
|
|
167
|
+
// const tweet = await x.posts.getReposts("2068675973722128815")
|
|
168
|
+
|
|
169
|
+
// console.log(tweets)
|
package/src/index.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { UtilsSES } from "./UtilsSES"
|
|
|
9
9
|
import { UtilsMisc } from "./UtilsMisc"
|
|
10
10
|
import { UtilsYoutube } from "./UtilsYoutube"
|
|
11
11
|
import { UtilsXAI } from "./UtilsXAI"
|
|
12
|
-
import { UtilsNitter } from "./UtilsNitter"
|
|
13
12
|
import { UtilsAnthropic } from "./UtilsAnthropic"
|
|
13
|
+
import { UtilsTwitter } from "./UtilsTwitter"
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
26
26
|
readonly youtube : UtilsYoutube
|
|
27
27
|
readonly anthropic : UtilsAnthropic
|
|
28
28
|
readonly xai : UtilsXAI
|
|
29
|
-
readonly
|
|
29
|
+
readonly twitter : UtilsTwitter
|
|
30
30
|
|
|
31
31
|
constructor(config : TriangleUtilsConfig) {
|
|
32
32
|
super(config)
|
|
@@ -40,7 +40,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
40
40
|
this.youtube = new UtilsYoutube(config.youtube_api_key)
|
|
41
41
|
this.anthropic = new UtilsAnthropic(config.anthropic_api_key)
|
|
42
42
|
this.xai = new UtilsXAI(config.xai_api_key)
|
|
43
|
-
this.
|
|
43
|
+
this.twitter = new UtilsTwitter(config.twitter_api_key)
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -54,6 +54,6 @@ export * from "./UtilsBee"
|
|
|
54
54
|
export * from "./UtilsCognito"
|
|
55
55
|
export * from "./UtilsS3Vectors"
|
|
56
56
|
export * from "./UtilsSES"
|
|
57
|
-
export * from "./
|
|
57
|
+
export * from "./UtilsTwitter"
|
|
58
58
|
export * from "./UtilsXAI"
|
|
59
59
|
export * from "./UtilsYoutube"
|