Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Twitter search switch #1003

Merged
merged 8 commits into from
Dec 12, 2024
1 change: 1 addition & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export async function initializeClients(
}

if (clientTypes.includes("twitter")) {
TwitterClientInterface.enableSearch = getSecret(character, "TWITTER_SEARCH_ENABLE");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this to the .env.example? TWITTER_SEARCH_ENABLE

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

const twitterClients = await TwitterClientInterface.start(runtime);
clients.push(twitterClients);
}
Expand Down
20 changes: 14 additions & 6 deletions packages/client-twitter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ class TwitterManager {
post: TwitterPostClient;
search: TwitterSearchClient;
interaction: TwitterInteractionClient;
constructor(runtime: IAgentRuntime) {
constructor(runtime: IAgentRuntime, enableSearch:boolean) {
this.client = new ClientBase(runtime);
this.post = new TwitterPostClient(this.client, runtime);
//this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default
// this searches topics from character file, but kind of violates consent of random users
// burns your rate limit and can get your account banned
// use at your own risk

if (enableSearch) {
// this searches topics from character file
elizaLogger.warn('Twitter/X client running in a mode that violates consent of random users')
elizaLogger.warn('burns your rate limit and can get your account banned')
elizaLogger.warn('use at your own risk')
this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default
}
this.interaction = new TwitterInteractionClient(this.client, runtime);
}
}

export const TwitterClientInterface: Client = {

async start(runtime: IAgentRuntime) {
await validateTwitterConfig(runtime);

elizaLogger.log("Twitter client started");

const manager = new TwitterManager(runtime);
// enableSearch is just set previous to this call
// so enableSearch can change over time
// and changing it won't stop the SearchClient in the existing instance
const manager = new TwitterManager(runtime, this.enableSearch);

await manager.client.init();

Expand Down
Loading