- 2 Posts
- 3 Comments
Joined 3 months ago
Cake day: December 29th, 2025
You are not logged in. If you use a Fediverse account that is able to follow users, you can follow this user.
iglais@lemmy.worldto
Perchance - Create a Random Text Generator@lemmy.world•AI text bug "〖"English
2·3 months agoi noticed that this morning, it’s add that glyph or a zero length character. breaks a lot of things. i had to update the JSON parser i use to try and accommodate those additions. works, some of the time.
parseJSON: (input) => { if (!input) return null;
// 1. OBJECT HANDLING (Already parsed) if (typeof input === 'object') { if (typeof input.text === 'string') return Utils.parseJSON(input.text); if (typeof input.generatedText === 'string') return Utils.parseJSON(input.generatedText); return input; } // 2. STRING HANDLING (The Toughened Shield) if (typeof input === 'string') { let clean = input.trim(); // A. Strip Markdown Code Blocks clean = clean.replace(/```json/gi, "").replace(/```/g, ""); // B. REINFORCED EXTRACTION // We find the FIRST occurrence of an opening bracket/brace // and the LAST occurrence of the matching closing bracket/brace. const firstObj = clean.indexOf('{'); const firstArr = clean.indexOf('['); let firstOpen = -1; let lastClose = -1; if (firstObj !== -1 && (firstArr === -1 || firstObj < firstArr)) { firstOpen = firstObj; lastClose = clean.lastIndexOf('}'); } else if (firstArr !== -1) { firstOpen = firstArr; lastClose = clean.lastIndexOf(']'); } if (firstOpen !== -1 && lastClose !== -1 && lastClose > firstOpen) { // C. HARD TRUNCATION // We extract ONLY what is between the brackets. // This kills the trailing "〖" and any other AI rambling. clean = clean.substring(firstOpen, lastClose + 1); // D. Post-Extraction Cleanup clean = clean.replace(/,(\s*[}\]])/g, '$1'); // Remove trailing commas try { return JSON.parse(clean); } catch (e) { // LAST DITCH: If it still fails, it's usually unescaped newlines in a string try { // Replace literal newlines inside JSON strings with escaped \n const escaped = clean.replace(/\n/g, "\\n").replace(/\r/g, "\\r"); return JSON.parse(escaped); } catch (e2) { console.warn("[Utils] JSON Parse Failed despite extraction:", e.message); } } } } console.warn("[Utils] JSON Parse Total Failure. Input sample:", input.substring(0, 100)); return null; }
iglais@lemmy.worldOPto
Perchance - Create a Random Text Generator@lemmy.world•Disreality: Warped Creation ― Perchance GeneratorEnglish
1·3 months agoi have no idea how to go about doing that. i haven’t done serious coding in 3 decades and never in html/css or js. i’m using this project to help me get back into the mold of coding and to learn how to do html/css and js. so far, i’ve been relying pretty heavily on ai support to learn how to do this, slowly getting better at making my own edits.
this elf ear thing, that completely baffles me. maybe it’s a flavor text thing? who knows.
thank you. i’m just trying to figure this all out.