Skip to content

Commit

Permalink
Merge pull request #1931 from elizaOS/tcm-limit-fetchingTimelines
Browse files Browse the repository at this point in the history
fix: Limit the number of timelines fetched
  • Loading branch information
shakkernerd authored Jan 7, 2025
2 parents a54246e + 872fd0f commit cddc8d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ export class ClientBase extends EventEmitter {
return processedTimeline;
}

async fetchTimelineForActions(): Promise<Tweet[]> {
async fetchTimelineForActions(count: number): Promise<Tweet[]> {
elizaLogger.debug("fetching timeline for actions");

const agentUsername = this.twitterConfig.TWITTER_USERNAME;

const homeTimeline =
this.twitterConfig.ACTION_TIMELINE_TYPE ===
ActionTimelineType.Following
? await this.twitterClient.fetchFollowingTimeline(20, [])
: await this.twitterClient.fetchHomeTimeline(20, []);
? await this.twitterClient.fetchFollowingTimeline(count, [])
: await this.twitterClient.fetchHomeTimeline(count, []);

return homeTimeline
.map((tweet) => ({
Expand Down Expand Up @@ -357,7 +357,11 @@ export class ClientBase extends EventEmitter {
(media) => media.type === "video"
) || [],
}))
.filter((tweet) => tweet.username !== agentUsername); // do not perform action on self-tweets
.filter((tweet) => tweet.username !== agentUsername) // do not perform action on self-tweets
.slice(0, count);
// TODO: Once the 'count' parameter is fixed in the 'fetchTimeline' method of the 'agent-twitter-client',
// this workaround can be removed.
// Related issue: https://github.com/elizaOS/agent-twitter-client/issues/43
}

async fetchSearchTweets(
Expand Down
9 changes: 5 additions & 4 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { DEFAULT_MAX_TWEET_LENGTH } from "./environment.ts";
import { State } from "@elizaos/core";
import { ActionResponse } from "@elizaos/core";

const MAX_TIMELINES_TO_FETCH = 15;

const twitterPostTemplate = `
# Areas of Expertise
{{knowledge}}
Expand Down Expand Up @@ -627,10 +629,9 @@ export class TwitterPostClient {
"twitter"
);

// TODO: Once the 'count' parameter is fixed in the 'fetchTimeline' method of the 'agent-twitter-client',
// we should enable the ability to control the number of items fetched here.
// Related issue: https://github.com/elizaOS/agent-twitter-client/issues/43
const homeTimeline = await this.client.fetchTimelineForActions();
const homeTimeline = await this.client.fetchTimelineForActions(
MAX_TIMELINES_TO_FETCH
);
const maxActionsProcessing =
this.client.twitterConfig.MAX_ACTIONS_PROCESSING;
const processedTimelines = [];
Expand Down

0 comments on commit cddc8d0

Please sign in to comment.