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

Update farcaster client max cast length #1347

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 6 additions & 8 deletions packages/client-farcaster/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@ai16z/eliza";
import { FarcasterClient } from "./client";
import { formatTimeline, postTemplate } from "./prompts";
import { castUuid } from "./utils";
import {castUuid, MAX_CAST_LENGTH} from "./utils";
import { createCastMemory } from "./memory";
import { sendCast } from "./actions";

Expand Down Expand Up @@ -100,22 +100,20 @@ export class FarcasterPostManager {

const slice = newContent.replaceAll(/\\n/g, "\n").trim();

const contentLength = 240;
let content = slice.slice(0, MAX_CAST_LENGTH);

let content = slice.slice(0, contentLength);

// if its bigger than 280, delete the last line
if (content.length > 280) {
// if it's bigger than the max limit, delete the last line
if (content.length > MAX_CAST_LENGTH) {
content = content.slice(0, content.lastIndexOf("\n"));
}

if (content.length > contentLength) {
if (content.length > MAX_CAST_LENGTH) {
// slice at the last period
content = content.slice(0, content.lastIndexOf("."));
}

// if it's still too long, get the period before the last period
if (content.length > contentLength) {
if (content.length > MAX_CAST_LENGTH) {
content = content.slice(0, content.lastIndexOf("."));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client-farcaster/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stringToUuid } from "@ai16z/eliza";

const MAX_CAST_LENGTH = 280; // Updated to Twitter's current character limit
export const MAX_CAST_LENGTH = 1024; // Updated to Twitter's current character limit

export function castId({ hash, agentId }: { hash: string; agentId: string }) {
return `${hash}-${agentId}`;
Expand Down
Loading