triggerdotdev / blog

Trigger.dev blog articles
https://avatar-generator-psi.vercel.app
29 stars 4 forks source link

help-wanted #1

Open mainak0907 opened 11 months ago

mainak0907 commented 11 months ago

Greetings @nevo-david , I was implementing the Resume maker with ChatGPT and encountered this error.

image
WillKirkmanM commented 10 months ago

Hey Mainak,

As shown in the error, the issue is that the message must be shorter than 262144 bytes, to solve this, split your message into sections split by 262144. Here's how you would do it in TypeScript

function splitStringByBytes(str: string, byteSize: number): string[] {
    const buffer = Buffer.from(str, 'utf-8');
    let start = 0;
    const result = [];

    while (start < buffer.length) {
        let end = start + byteSize;
        if (end > buffer.length) {
            end = buffer.length;
        }
        result.push(buffer.slice(start, end).toString('utf-8'));
        start = end;
    }

    return result;
}

const chunks = splitStringByBytes('The Resume Message', 262144);

Kind Regards, WillKirkmanM