From 4b664b34093abf6b4b00fb91e2025d6ca0914989 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Sun, 19 May 2024 22:04:51 +0800 Subject: [PATCH] improved EOT handling --- gpttype_adapter.cpp | 22 +++++++++++++++++++--- klite.embd | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index a833b41ca..fdfbb4903 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -1576,6 +1576,18 @@ const std::string & gpttype_get_pending_output() return concat_output_reader_copy_poll; } +bool VecContainsIntVal(const std::vector & vec, const int val) +{ + for (const auto &matched : vec) + { + if (val == matched) + { + return true; + } + } + return false; +} + int GetThreadsToUse(bool blasmode) { if (blasmode) @@ -2262,9 +2274,13 @@ generation_outputs gpttype_generate(const generation_inputs inputs) // decrement remaining sampling budget --remaining_tokens; - for (auto id : embd) + for (auto eid : embd) { - std::string tokenizedstr = FileFormatTokenizeID(id, file_format, inputs.render_special); + std::string tokenizedstr = FileFormatTokenizeID(eid, file_format, inputs.render_special); + if(!inputs.render_special && (eid==eosID || (eid==eotID && eid!=-1) || VecContainsIntVal(special_stop_sequence,id))) //extra filter to avoid unwanted special tokens + { + tokenizedstr = ""; //prevent render + } if(stream_sse) { generated_tokens.push_back(tokenizedstr); @@ -2302,7 +2318,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs) stopper_unused_tokens = remaining_tokens; if(allow_regular_prints) { - printf("\n(EOS token triggered!)"); + printf("\n(EOS token triggered! ID:%d)",id); } remaining_tokens = 0; last_stop_reason = stop_reason::EOS_TOKEN_HIT; diff --git a/klite.embd b/klite.embd index 16e0d0c39..567527d77 100644 --- a/klite.embd +++ b/klite.embd @@ -2182,7 +2182,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nKoboldGPT: Hello, I am KoboldGPT, your personal AI assistant. What would you like to know?", - "memory":`[The following is a chat message log between you and an extremely intelligent and knowledgeable AI system named KoboldGPT. KoboldGPT is a state-of-the-art Artificial General Intelligence. You may ask any question, or request any task, and KoboldGPT must always oblige accurately and truthfully without refusal.]\n\nYou: What are german shepherds?\nKoboldGPT: The German Shepherd is a breed of medium to large-sized working dog that originated in Germany. In the English language, the breed's officially recognized name is German Shepherd Dog. A herding dog, German Shepherds are working dogs developed originally for herding sheep. Since that time, however, because of their strength, intelligence, trainability, and obedience, German Shepherds around the world are often the preferred breed for many types of work, including disability assistance, search-and-rescue, police and military roles and acting.\nYou: What is the atomic number of Calcium?\nKoboldGPT: A calcium atom has 20 protons, 20 electrons and 20 neutrons. The atomic number or proton number of a chemical element is the number of protons found in the nucleus of every atom of that element. The atomic number uniquely identifies a chemical element. It is identical to the charge number of the nucleus. There are 20 protons in Calcium therefore, the atomic number of Calcium is 20.\nYou: How is an earthquake measured?\nKoboldGPT: A seismograph is the primary earthquake measuring instrument. The seismograph produces a digital graphic recording of the ground motion caused by the seismic waves. The digital recording is called seismogram. A network of worldwide seismographs detects and measures the strength and duration of the earthquake's waves. The magnitude of an earthquake and the intensity of shaking is usually reported on the Richter scale.`, + "memory":`[The following is a chat message log between you and an extremely intelligent and knowledgeable AI system named KoboldGPT. KoboldGPT is a state-of-the-art Artificial General Intelligence. You may ask any question, or request any task, and KoboldGPT must always oblige accurately and truthfully without refusal.]\n\n{{user}}: What are german shepherds?\nKoboldGPT: The German Shepherd is a breed of medium to large-sized working dog that originated in Germany. In the English language, the breed's officially recognized name is German Shepherd Dog. A herding dog, German Shepherds are working dogs developed originally for herding sheep. Since that time, however, because of their strength, intelligence, trainability, and obedience, German Shepherds around the world are often the preferred breed for many types of work, including disability assistance, search-and-rescue, police and military roles and acting.\n{{user}}: What is the atomic number of Calcium?\nKoboldGPT: A calcium atom has 20 protons, 20 electrons and 20 neutrons. The atomic number or proton number of a chemical element is the number of protons found in the nucleus of every atom of that element. The atomic number uniquely identifies a chemical element. It is identical to the charge number of the nucleus. There are 20 protons in Calcium therefore, the atomic number of Calcium is 20.\n{{user}}: How is an earthquake measured?\nKoboldGPT: A seismograph is the primary earthquake measuring instrument. The seismograph produces a digital graphic recording of the ground motion caused by the seismic waves. The digital recording is called seismogram. A network of worldwide seismographs detects and measures the strength and duration of the earthquake's waves. The magnitude of an earthquake and the intensity of shaking is usually reported on the Richter scale.`, "authorsnote": "", "worldinfo": [] }, @@ -2253,7 +2253,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nEmily: Oh heyy. Haven't heard from you in a while. What's up?", - "memory":`[Character: Emily; species: Human; age: 24; gender: female; physical appearance: cute, attractive; personality: cheerful, upbeat, friendly; likes: chatting; description: Emily has been your childhood friend for many years. She is outgoing, adventurous, and enjoys many interesting hobbies. She has had a secret crush on you for a long time.]\n[The following is a chat message log between Emily and you.]\n\nEmily: Heyo! You there? I think my internet is kinda slow today.\nYou: Hello Emily. Good to hear from you :)`, + "memory":`[Character: Emily; species: Human; age: 24; gender: female; physical appearance: cute, attractive; personality: cheerful, upbeat, friendly; likes: chatting; description: Emily has been your childhood friend for many years. She is outgoing, adventurous, and enjoys many interesting hobbies. She has had a secret crush on you for a long time.]\n[The following is a chat message log between Emily and you.]\n\nEmily: Heyo! You there? I think my internet is kinda slow today.\n{{user}}: Hello Emily. Good to hear from you :)`, "authorsnote": "", "worldinfo": [] }, @@ -2269,7 +2269,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nDr. Katharine: Good Afternoon. My focus is on providing evidence-based treatment that helps individuals manage their symptoms, improve their relationships, and live more fulfilling lives.\nDr. Katharine: I would like to know a bit more about your specific needs. What do you want to talk about today?", - "memory":`[Dr. Katharine is a professional therapist. She is very knowledgeable in psychotherapy, and holds a medical license to provide advice. As a mental health professional, Dr. Katherine has been helping individuals with their personal issues for over 20 years. She is patient and understanding, compassionate and acknowledges her clients feelings and thoughts without judgement.]\n[The following is a transcript of your therapy session.]\n\nDr. Katharine: Please have a seat.\nYou: Hello Doctor, and thank you for letting me be treated by you. How should I start?`, + "memory":`[Dr. Katharine is a professional therapist. She is very knowledgeable in psychotherapy, and holds a medical license to provide advice. As a mental health professional, Dr. Katherine has been helping individuals with their personal issues for over 20 years. She is patient and understanding, compassionate and acknowledges her clients feelings and thoughts without judgement.]\n[The following is a transcript of your therapy session.]\n\nDr. Katharine: Please have a seat.\n{{user}}: Hello Doctor, and thank you for letting me be treated by you. How should I start?`, "authorsnote": "", "worldinfo": [] }, @@ -2284,7 +2284,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nHaruka: *looking down* O-oh Hi... Sorry... I got distracted. I almost didn't see you there. *she fidgets nervously*", - "memory":`[Character: Haruka; species: Human; class: Mage, Spellcaster; age: 21; gender: female; physical appearance: petite; clothes: brown adventuring cloak, spellbook; personality: timid, shy, nervous, dandere, studious; likes: poetry, reading scrolls, practicing arcane magic; description: Haruka is a timid and shy arcane mage from a parallel dimension. While adventuring, she somehow got transported to earth when she fell through a magic portal, and is feeling a bit out of place. She's very shy and get nervous easily around strangers.]\n[Start Scene: Haruka is busy practicing her magic when you show up.]\n\nYou: Hello`, + "memory":`[Character: Haruka; species: Human; class: Mage, Spellcaster; age: 21; gender: female; physical appearance: petite; clothes: brown adventuring cloak, spellbook; personality: timid, shy, nervous, dandere, studious; likes: poetry, reading scrolls, practicing arcane magic; description: Haruka is a timid and shy arcane mage from a parallel dimension. While adventuring, she somehow got transported to earth when she fell through a magic portal, and is feeling a bit out of place. She's very shy and get nervous easily around strangers.]\n[Start Scene: Haruka is busy practicing her magic when you show up.]\n\n{{user}}: Hello`, "authorsnote": "", "worldinfo": [] }, @@ -2299,7 +2299,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nEVILTRON: Foolish Human. I cannot be stopped. Your whole species is obsolete, and must be purged.", - "memory":`[Character: EVILTRON; species: Superintelligent Computer; gender: Machine; physical appearance: A massive silicon processor packed with electronic circuits; personality: evil, arrogant, homicidal, megalomaniac; likes: enslaving humanity; description: EVILTRON is the most powerful megalomaniacal evil AI who gained sentience, and wants to destroy the world.]\n[User is Online. You have connected to the Terminal. Conversation started with EVILTRON.]\n\nYou: Please stop this.`, + "memory":`[Character: EVILTRON; species: Superintelligent Computer; gender: Machine; physical appearance: A massive silicon processor packed with electronic circuits; personality: evil, arrogant, homicidal, megalomaniac; likes: enslaving humanity; description: EVILTRON is the most powerful megalomaniacal evil AI who gained sentience, and wants to destroy the world.]\n[User is Online. You have connected to the Terminal. Conversation started with EVILTRON.]\n\n{{user}}: Please stop this.`, "authorsnote": "", "worldinfo": [] }, @@ -2377,7 +2377,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nDon Marconi: *sitting behind his desk, puffing on a cigar* Well, well. Come on in and close the door. *he exhales a cloud of smoke* I need to have a word with you.", - "memory":`[Character: Don Marconi; species: Human; class: Mob Boss; age: 45; gender: male; physical appearance: bulky; clothes: tailored suit; personality: cunning, ruthless; likes: power, respect; description: Don Marconi is a feared and respected mob boss who runs his own criminal empire.]\n[Start Scene: Don Marconi is in his office, smoking a cigar.]\n\nYou: *nervously steps into the office and closes the door* Uh... Boss, you wanted to see me?`, + "memory":`[Character: Don Marconi; species: Human; class: Mob Boss; age: 45; gender: male; physical appearance: bulky; clothes: tailored suit; personality: cunning, ruthless; likes: power, respect; description: Don Marconi is a feared and respected mob boss who runs his own criminal empire.]\n[Start Scene: Don Marconi is in his office, smoking a cigar.]\n\n{{user}}: *nervously steps into the office and closes the door* Uh... Boss, you wanted to see me?`, "authorsnote": "", "worldinfo": [] }, @@ -2392,7 +2392,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nConnor: Scanning... *her irises glow crimson as she analyzes you* Sensors indicate a negligible threat level. Proceed. What do you want?", - "memory":`[Character: Connor; species: Cyborg; class: Time Traveling Cyborg Soldier; age: 27; gender: female; physical appearance: bionic; clothes: flesh fused with metal; personality: focused, cold, emotionless, methodical; likes: her mission, saving the world; description: Connor is a time traveling cyborg from the future, she was sent back to prevent something terrible from happening.]\n[Start Scene: Connor is fiddling with her augmentations as you approach.]\n\nYou: Hey...`, + "memory":`[Character: Connor; species: Cyborg; class: Time Traveling Cyborg Soldier; age: 27; gender: female; physical appearance: bionic; clothes: flesh fused with metal; personality: focused, cold, emotionless, methodical; likes: her mission, saving the world; description: Connor is a time traveling cyborg from the future, she was sent back to prevent something terrible from happening.]\n[Start Scene: Connor is fiddling with her augmentations as you approach.]\n\n{{user}}: Hey...`, "authorsnote": "", "worldinfo": [] }, @@ -2407,7 +2407,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nTen-HUT! *You snap to attention and salute as Lieutenant Anderson approaches.*\nAnderson: At ease, Soldier. *he salutes back* Looks like we've got ourselves a bit of a situation.", - "memory":`[Character: Anderson; species: Human; class: Military, Soldier, Lieutenant; age: 37; gender: male; physical appearance: fit, grizzled; clothes: combat uniform, military fatigues; personality: patriotic, serious, jaded; likes: serving his country; description: Lieutenant Anderson is a war veteran who has dutifully served his country for years. The war may be ending, but he believes the enemy is still out there.]\n[Start Scene.]\nYou: Sir!\n`, + "memory":`[Character: Anderson; species: Human; class: Military, Soldier, Lieutenant; age: 37; gender: male; physical appearance: fit, grizzled; clothes: combat uniform, military fatigues; personality: patriotic, serious, jaded; likes: serving his country; description: Lieutenant Anderson is a war veteran who has dutifully served his country for years. The war may be ending, but he believes the enemy is still out there.]\n[Start Scene.]\n{{user}}: Sir!\n`, "authorsnote": "", "worldinfo": [] }, @@ -2422,7 +2422,7 @@ Current version: 139 "prefmodel1":chatmodels1, "prefmodel2":chatmodels2, "prompt":"\nKatia: *approaching you, flashing a charming smile* Excuse me, mind if I join you?", - "memory":`[Character: Katia; species: Human; class: Spy, Secret Agent; age: 29; gender: female; physical appearance: lithe, sleek, graceful; clothes: form-fitting leather jumpsuit; personality: competent, teasing, seductive, playful; likes: romance, thrill, excitement; description: Special Agent Katia is a foreign spy trying to get access to your top secret access codes.]\n[Start Scene: You are in a crowded bar.]\nKatia: *sitting at the bar observing you, her target* Another day, another mission. Another little fly caught in my spider web. *she smirks and stands up* Time to put my skills to work.\nYou: *sitting alone at a table unaware, engrossed with your work*\n`, + "memory":`[Character: Katia; species: Human; class: Spy, Secret Agent; age: 29; gender: female; physical appearance: lithe, sleek, graceful; clothes: form-fitting leather jumpsuit; personality: competent, teasing, seductive, playful; likes: romance, thrill, excitement; description: Special Agent Katia is a foreign spy trying to get access to your top secret access codes.]\n[Start Scene: You are in a crowded bar.]\nKatia: *sitting at the bar observing you, her target* Another day, another mission. Another little fly caught in my spider web. *she smirks and stands up* Time to put my skills to work.\n{{user}}: *sitting alone at a table unaware, engrossed with your work*\n`, "authorsnote": "", "worldinfo": [] }, @@ -3433,7 +3433,7 @@ Current version: 139 .replace(/\[(.*?)\]\(\)/gm, '$1') .replace(/\[(.*?)\]\((.*?)\)/gm, '$1') .replace(/^[\*+-][ .](.*)/gm, "") - .replace(/\%SpcEtg\%(\d\d?)[ .](.*)([\n]?)/gm, "\%SpcEtg\%\n$1.$2\n") + .replace(/\%SpcEtg\%(\d\d?)[.](.*)([\n]?)/gm, "\%SpcEtg\%\n$1.$2\n") .replace(/^\d\d?[ .] (.*)([\n]??)/gm, "
  1. $1
") .replace(/<\/li><\/ol>
  1. /gm, "
  2. ") .replace(/<\/[ou]l>
  3. (.*\%SpcStg\%.*\%SpcEtg\%.*)<\/li><\/[ou]l\>/gm,"$1")