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

fix: handle long tweet in utils #1520

Merged
merged 20 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
20f2d9d
fix: handle long tweet in utils
oxSaturn Dec 28, 2024
19b9de1
Merge branch 'develop' into fix/long-tweet
odilitime Dec 28, 2024
6d19903
feat: use OPENAI_API_URL from env to support custom OpenAI API endpoint
imtms Dec 28, 2024
39fed59
isFalsish() for parsing environment in a standard way
odilitime Dec 28, 2024
e7f9693
roll isFalsish into parseBooleanFromText
odilitime Dec 28, 2024
d22369c
lint: remove unused error variable
odilitime Dec 28, 2024
a2853fa
lint: fix EmbeddingProvider already defined error (via claude)
odilitime Dec 28, 2024
35d26c6
empty is already mapped to null
odilitime Dec 28, 2024
bdabfbc
move all env parsing here
odilitime Dec 28, 2024
cad36a7
add twitterConfig cstr param and prefer it over getSetting
odilitime Dec 28, 2024
bd78337
prefer this.client.twitterConfig over getSetting
odilitime Dec 28, 2024
ec33a17
prefer client.twitterConfig over getSetting
odilitime Dec 28, 2024
b8bde37
prefer this.client.twitterConfig over getSetting
odilitime Dec 28, 2024
2c57732
prefer this.client.twitterConfig over getSettings
odilitime Dec 28, 2024
68288ad
pass twitterConfig as 2nd parameter to cstr, only start search once
odilitime Dec 28, 2024
4f92818
fix TWITTER_POLL_INTERVAL scale
odilitime Dec 28, 2024
7fce277
make MAX_TWEET_LENGTH integer since that's how it's consomed/compared
odilitime Dec 28, 2024
8b9278e
chore: revert file to match develop branch
shakkernerd Dec 28, 2024
d537154
chore: revert file to match develop branch
shakkernerd Dec 28, 2024
7e6e7a9
Merge branch 'develop' into fix/long-tweet
odilitime Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/client-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ export class GitHubClient {
`Successfully cloned repository from ${repositoryUrl}`
);
return;
} catch (error) {
elizaLogger.error(
`Failed to clone repository from ${repositoryUrl}. Retrying...`,
error
);
} catch {
elizaLogger.error(`Failed to clone repository from ${repositoryUrl}. Retrying...`);
retries++;
if (retries === maxRetries) {
throw new Error(
Expand Down
28 changes: 14 additions & 14 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ export async function sendTweet(
twitterUsername: string,
inReplyTo: string
): Promise<Memory[]> {
const tweetChunks = splitTweetContent(
content.text,
client.twitterConfig.MAX_TWEET_LENGTH
);
const maxTweetLength = client.twitterConfig.MAX_TWEET_LENGTH;
const isLongTweet = maxTweetLength > 280;

const tweetChunks = splitTweetContent(content.text, maxTweetLength);
const sentTweets: Tweet[] = [];
let previousTweetId = inReplyTo;

Expand Down Expand Up @@ -212,20 +212,20 @@ export async function sendTweet(
})
);
}
const result = await client.requestQueue.add(
async () =>
await client.twitterClient.sendTweet(
chunk.trim(),
previousTweetId,
mediaData
)
const result = await client.requestQueue.add(async () =>
isLongTweet
? client.twitterClient.sendLongTweet(chunk.trim(), previousTweetId, mediaData)
: client.twitterClient.sendTweet(chunk.trim(), previousTweetId, mediaData)
);

const body = await result.json();
const tweetResult = isLongTweet
? body.data.notetweet_create.tweet_results.result
: body.data.create_tweet.tweet_results.result;

// if we have a response
if (body?.data?.create_tweet?.tweet_results?.result) {
if (tweetResult) {
// Parse the response
const tweetResult = body.data.create_tweet.tweet_results.result;
const finalTweet: Tweet = {
id: tweetResult.rest_id,
text: tweetResult.legacy.full_text,
Expand All @@ -245,7 +245,7 @@ export async function sendTweet(
sentTweets.push(finalTweet);
previousTweetId = finalTweet.id;
} else {
console.error("Error sending chunk", chunk, "response:", body);
elizaLogger.error("Error sending tweet chunk:", { chunk, response: body });
}

// Wait a bit between tweets to avoid rate limiting issues
Expand Down
Loading