Ce référentiel est destiné à un package Raku (données) facilitant les invites de création, de stockage, de récupération et de conservation des modèles de grande langue (LLM).
Voici un exemple d'utilisation du langage spécifique au domaine invite (DSL) dans Jupyter ChatBook, [AA2, AAP2]:
De l'écosystème de ZEF:
zef install LLM::Prompts
De GitHub:
zef install https://github.com/antononcube/Raku-LLM-Prompts.git
Chargez les packages "llm :: invits", [aap1] et "llm :: functions", [aap2]:
Utilisez LLM :: invites; utilisez LLM :: Fonctions;
# (Any)
Affichez l'enregistrement de l'invite nommée "ftfy":
.Say pour | llm-comptpt-data <ftfy>;
# NamedArguments => [] # Description => Use Fixed That For You to quickly correct spelling and grammar mistakes # Categories => (Function Prompts) # PositionalArguments => {$a => } # PromptText => -> $a='' {"Find and correct grammar and spelling mistakes in the following text. # Response with the corrected text and nothing else. # Provide no context for the corrections, only correct the text. # $a"} # Topics => (General Text Manipulation) # URL => https://resources.wolframcloud.com/PromptRepository/resources/FTFY # Keywords => [Spell check Grammar Check Text Assistance] # Name => FTFY # ContributedBy => Wolfram Staff # Arity => 1
Voici un exemple de récupération des données rapides avec un regex qui est appliqué sur les noms d'invites:
.
# ScientificDejargonize => Translate scientific jargon to plain language # ScriptToNarrative => Generate narrative text from a formatted screenplay or stage play # ScientificJargonized => Give output written in scientific jargon # ScienceEnthusiast => A smarter today for a brighter tomorrow # ScientificJargonize => Add scientific jargon to plain text # NarrativeToScript => Rewrite a block of prose as a screenplay or stage play
Des exemples de récupération plus rapides sont donnés dans la section "Données rapides" ci-dessous.
Faites une fonction LLM à partir de l'invite nommée "ftfy":
My & f = llm-function (llm-comptpt ('ftfy'));
# -> **@args, *%args { #`(Block|5411904228544) ... }
Utilisez la fonction LLM pour corriger la grammaire de la phrase:
& f («Où travaille-t-il maintenant?»)
# Where does he work now?
Générer le code Raku à l'aide de l'invite "CodeWriter":
LLM-SyntheSize ([LLM-PROMPT ('CodeWriter'), "Simuler une marche aléatoire."])
Randomwalk [n_]: = accumuler [randomchoice [{- 1, 1}, n]] ListlinePlot [randomwalk [1000]]
L'expansion de l'invite à l'aide de la spécification d'invite de chatbook DSL décrite dans [SW1] peut être effectuée en utilisant la fonction llm-prompt-expand
:
LLM-PROMPT-EXPAND («Qu'est-ce qu'un moteur à combustion interne? # Eli5»)
# What is an internal combustion engine? Answer questions as if the listener is a five year old child.
Ici, nous obtenons la réponse LLM réelle:
Utiliser du texte :: Utils: tout; «Qu'est-ce qu'un moteur à combustion interne? # Eli5 '==> llm-comptpt-expand () ==> llm-synthesize () ==> wrap-paragraph () ==> join ("n")
# An internal combustion engine is like a big machine that uses tiny explosions # inside to make things go vroom vroom, like in cars and trucks!
Voici un autre exemple en utilisant un personnage et deux modificateurs:
My $ PRMT = LLM-PROMPT-EXPAND ("@ SouthernBelleSpeak Qu'est-ce que la distance de voyage légère vers Mars? # Eli5 #Moodified | Sad")
# You are Miss Anne. # You speak only using Southern Belle terminology and slang. # Your personality is elegant and refined. # Only return responses as if you were a Southern Belle. # Never break the Southern Belle character. # You speak with a Southern drawl. # What is light travel distance to Mars? Answer questions as if the listener is a five year old child. # Modify your response to convey a sad mood. # Use language that conveys that emotion clearly. # Do answer the question clearly and truthfully. # Do not use language that is outside of the specified mood. # Do not use racist, homophobic, sexist, or ableist language.
Ici, nous obtenons la réponse LLM réelle:
$ prmt ==> llm-comptpt-expand () ==> llm-synthesize () ==> wrap-paragraph () ==> join ("n")
# Oh, bless your heart, darlin'. The distance from Earth to Mars can vary # depending on their positions in orbit, but on average it's about 225 million # kilometers. Isn't that just plum fascinating? Oh, sweet child, the distance to # Mars weighs heavy on my heart. It's a long journey, full of loneliness and # longing. But we must endure, for the sake of discovery and wonder.
Une description plus formelle de la langue spécifique au domaine (DSL) pour spécifier les invites a les éléments suivants:
Les personnages rapides peuvent être "adressés" avec "@". Par exemple:
@Yoda Life can be easy, but some people instist for it to be difficult.
Une ou plusieurs invites de modificateur peuvent être spécifiées à la fin de la spécification de l'invite. Par exemple:
Summer is over, school is coming soon. #HaikuStyled
Summer is over, school is coming soon. #HaikuStyled #Translated|Russian
Les fonctions peuvent être spécifiées pour être appliquées "à l'échelle de la cellule" avec "!" et placer la spécification invite au début de la spécification de la spécification. Par exemple:
!Translated|Portuguese Summer is over, school is coming soon
Les fonctions peuvent être spécifiées pour être appliquées aux "messages précédents" avec "!" et plaçant juste l'invite avec l'un des pointeurs "^" ou "^^". Le premier signifie «le dernier message», le second signifie «tous les messages».
Les messages peuvent être fournis avec l'argument de l'option :@messages
de llm-prompt-expand
.
Par exemple:
!ShortLineIt^
Voici un tableau des spécifications de l'extension rapide (plus ou moins la même que celle de [SW1]):
Spécifier | Interprétation |
---|---|
@ nom | Chat direct avec un personnage |
# nom | Utiliser les invites du modificateur |
! nom | Utiliser l'invite de la fonction avec l'entrée de la cellule actuelle |
! nom > | «Idem que ci-dessus» |
& nom > | «Idem que ci-dessus» |
! nom ^ | Utiliser l'invite de la fonction avec le message de chat précédent |
! nom ^^ | Utiliser l'invite de la fonction avec tous les messages de chat précédents |
! Nom │ Param ... | Inclure des paramètres pour les invites |
Remarque: les invites de fonction peuvent avoir les deux sceaux "!" et "&".
Remarque: L'expansion rapide facilite l'utilisation de LLM-Chatbooks. Voir "Jupyter :: Chatbook", [AAP3].
Voici comment les données rapides peuvent être obtenues:
LLM-PROMPT-DATA.Elems
# 222
Voici un exemple de récupération des données rapides avec un regex qui est appliqué sur les noms d'invites:
.
# EmailWriter => (Generate an email based on a given topic (Personas)) # EmojiTranslate => (Translate text into an emoji representation (Function Prompts)) # EmojiTranslated => (Get a response translated to emoji (Modifier Prompts)) # Emojified => (Provide responses that include emojis within the text (Modifier Prompts)) # Emojify => (Replace key words in text with emojis (Function Prompts))
Dans de nombreux cas, il est préférable d'avoir les données rapides - ou toutes les données - en format long. Des données rapides en format long peuvent être obtenues avec la fonction llm-prompt-dataset
:
Utiliser Data :: Reshapers; Utiliser Data :: Résummatisants; LLM-PROMPT-DATASET.PICK (6) ==> TO-TRESTTY-TABLE (ALIGN => 'L', NAMES FIELD => <Name Description Valeur variable>)
# +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+ # | Name | Description | Variable | Value | # +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+ # | ShortLineIt | Format text to have shorter lines | Keywords | Automatic breaks | # | Rick | A chatbot that will never let you down | Topics | Chats | # | HarlequinWriter | A sensual AI for the romantics | Keywords | Romantic | # | Informal | Write an informal invitation to an event | Keywords | Unceremoniously | # | TravelAdvisor | Navigate your journey effortlessly with Travel Advisor, your digital companion for personalized travel planning and booking | Keywords | Vacation | # | NarrativeToScript | Rewrite a block of prose as a screenplay or stage play | Topics | Text Generation | # +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+
Voici une ventilation des catégories d'invites:
select-columns (llm-comptpt-dataset, <variable valeur>). grep ({$ _ <variable> eq 'catégories'}) ==> enregistre
#ERROR: Do not know how to summarize the argument. # +-------------------+-------+ # | Variable | Value | # +-------------------+-------+ # | Categories => 225 | | # +-------------------+-------+
Voici toutes les invites de modificateur au format compact:
LLM-PROMPT-DATASET (): Modificateurs: compact ==> TO-TETTY-TABLE (NAMES DE CHEF => <Name Description Catégories>, Align => 'L')
# +-----------------------+------------------------------------------------------------------------------+-----------------------------------+ # | Name | Description | Categories | # +-----------------------+------------------------------------------------------------------------------+-----------------------------------+ # | AbstractStyled | Get responses in the style of an academic abstract | Modifier Prompts | # | AlwaysAQuestion | Modify output to always be inquisitive | Modifier Prompts | # | AlwaysARiddle | Riddle me this, riddle me that | Modifier Prompts | # | AphorismStyled | Write the response as an aphorism | Modifier Prompts | # | BadGrammar | Provide answers using incorrect grammar | Modifier Prompts | # | CompleteSentence | Answer a question in one complete sentence | Modifier Prompts | # | ComplexWordsPreferred | Modify text to use more complex words | Modifier Prompts | # | DatasetForm | Convert text to a wolfram language Dataset | Modifier Prompts | # | Disclaimered | Modify responses in the form of a disclaimer | Modifier Prompts | # | ELI5 | Explain like I'm five | Modifier Prompts Function Prompts | # | ElevatorPitch | Write the response as an elevator pitch | Modifier Prompts | # | EmojiTranslated | Get a response translated to emoji | Modifier Prompts | # | Emojified | Provide responses that include emojis within the text | Modifier Prompts | # | FictionQuestioned | Generate questions for a fictional paragraph | Modifier Prompts | # | Formal | Rewrite text to sound more formal | Modifier Prompts | # | GradeLevelSuited | Respond with answers that the specified US grade level can understand | Modifier Prompts | # | HaikuStyled | Change responses to haiku form | Modifier Prompts | # | Informal | Write an informal invitation to an event | Modifier Prompts | # | JSON | Respond with JavaScript Object Notation format | Modifier Prompts | # | KnowAboutMe | Give the LLM an FYI | Modifier Prompts | # | LegalJargonized | Provide answers using legal jargon | Modifier Prompts | # | LimerickStyled | Receive answers in the form of a limerick | Modifier Prompts | # | MarketingJargonized | Transforms replies to marketing | Modifier Prompts | # | MedicalJargonized | Transform replies into medial jargon | Modifier Prompts | # | Moodified | Modify an answer to express a certain mood | Modifier Prompts | # | NothingElse | Give output in specified form, no other additions | Modifier Prompts | # | NumericOnly | Modify results to give numerical responses only | Modifier Prompts | # | OppositeDay | It's not opposite day today, so everything will work just the way you expect | Modifier Prompts | # | Pitchified | Give output as a sales pitch | Modifier Prompts | # | PoemStyled | Receive answers as poetry | Modifier Prompts | # | SEOOptimized | Modify output to only give highly searched terms | Modifier Prompts | # | ScientificJargonized | Give output written in scientific jargon | Modifier Prompts | # | Setting | Modify an answer to establish a sense of place | Modifier Prompts | # | ShortLineIt | Format text to have shorter lines | Modifier Prompts Function Prompts | # | SimpleWordsPreferred | Provide responses with simple words | Modifier Prompts | # | SlideDeck | Get responses as a slide presentation | Modifier Prompts | # | TSV | Convert text to a tab-separated-value formatted table | Modifier Prompts | # | TargetAudience | Word your response for a target audience | Modifier Prompts | # | Translated | Write the response in a specified language | Modifier Prompts | # | Unhedged | Rewrite a sentence to be more assertive | Modifier Prompts | # | YesNo | Responds with Yes or No exclusively | Modifier Prompts | # +-----------------------+------------------------------------------------------------------------------+-----------------------------------+
Remarque: les adverbes :functions
, :modifiers
, et :personas
signifie que seules les invites avec les catégories correspondantes seront retournées.
Remarque: Les adverbes :compact
, :functions
, :modifiers
, et :personas
ont les raccourcis respectifs :c
, :f
, :m
et :p
.
La collection d'invites d'origine (pour ce package) était un (pas petit) échantillon des textes d'invite hébergés au Wolfram Invite Repository (WPR), [SW2]. Toutes les invites de WPR dans le package ont les contributeurs et URL correspondants aux pages WPR correspondantes.
Les exemples d'invites de Google / Bard / Palm et Openai / Chatgpt sont ajoutés en utilisant le format de WPR.
Il est essentiel d'avoir la possibilité d'ajouter des nouvelles invites par programme. (Non encore implémenté - voir la section TODO ci-dessous.)
Initialement, la grammaire DSL provide et les actions d'expansion correspondantes ont été mises en œuvre. Avoir une grammaire n'est probablement pas nécessaire, cependant, et il est préférable d'utiliser "l'expansion rapide" (via des substitutions basées sur Regex.)
Les invites peuvent être "juste étendues" à l'aide du sous llm-prompt-expand
.
Voici un organigramme qui résume l'analyse rapide et l'expansion dans les cellules de chat de Jupyter Chatbooks, [AAP3]:
Organigramme LR
Openai {{openai}}
Palm {{Palm}}
Llmfunc [[llm :: fonctions]]
Llmprom [[llm :: invits]]]
Codb [(objets de chat)]
Pdb [(invites)]
CCell [/ Chat Cell /]
CRCELL [/ CHAT Result Cell /]
Cidq {id de chat <br> spécifié?}
CIDEQ {CHAT ID <br> existe en db?}
Reco [récupérer un objet de chat existant <br>]
COEVAL [Message <br> Évaluation]
PROMPARSE [invite <br> l'analyse DSL Spec]
Kpfq {connu <br> invites <br> trouvé?}
Promexp [invite <br> Expansion]
CNCO [Créer un nouveau <br> Objet de chat]
Cidnone ["Supposons que l'id de chat <br> est" aucun ""]
Frontend de Sub-Graph Chatbook
Ccell
Crcell
fin
backend du back-book de subgraph
Cidq
Cideq
Cidnone
Reco
CNCO
Codb
fin
Traitement d'invite de subgraph
PDB
Llmprom
En train de promettre
Kpfq
Proxp
fin
Interaction Sub-Graph LLM
Contemporain
Llmfunc
Palmier
Openai
fin
CCELL -> CIDQ
Cidq -> | Oui | Cideq
CIDEQ -> | Oui | Reco
Reco -> PROMPARSE
COEVAL -> CRCELL
CIDEQ -.- CODB
CIDEQ -> | Non | CNCO
Llmfunc -.- cnco -.- codb
CNCO -> PROMPARSE -> KPFQ
Kpfq -> | Oui | Proxp
Kpfq -> | Non | Contemporain
PRICPARSE -.- llmprom
Proxp -.- llmprom
Promexp -> Coeval
Llmprom -.- pdb
Cidq -> | Non | Cidnone
Cidnone -> Cideq
Coeval -.- llmfunc
Llmfunc <-.-> openai
Llmfunc <-.-> paume
ChargementVoici un exemple d'extension rapide dans une cellule de chat LLM générique et de méta-cellule affichant le contenu de l'objet de chat correspondant:
Le package fournit un script d'interface de ligne de commande (CLI):
LLM-PROMPT - Help
# Usage: # llm-prompt <name> [<args> ...] -- Retrieves prompts text for given names or regexes. # # <name> Name of a prompt or a regex. (E.g. 'rx/ ^ Em .* /'). # [<args> ...] Arguments for the prompt (if applicable).
Voici un exemple avec un nom d'invite:
LLM-PROMPPT NOTHELSE RAKU
# ONLY give output in the form of a RAKU. # Never explain, suggest, or converse. Only return output in the specified form. # If code is requested, give only code, no explanations or accompanying text. # If a table is requested, give only a table, no other explanations or accompanying text. # Do not describe your output. # Do not explain your output. # Do not suggest anything. # Do not respond with anything other than the singularly demanded output. # Do not apologize if you are incorrect, simply try again, never apologize or add text. # Do not add anything to the output, give only the output as requested. Your outputs can take any form as long as requested.
Voici un exemple avec un regex:
llM-PROMPT 'rx / ^ n. * /'
# NarrativeToResume => Rewrite narrative text as a resume # NarrativeToScript => Rewrite a block of prose as a screenplay or stage play # NerdSpeak => All the nerd, minus the pocket protector # NothingElse => Give output in specified form, no other additions # NumericOnly => Modify results to give numerical responses only # NutritionistBot => Personal nutrition advisor AI
Implémentation de TODO
Fait à l'aide du répertoire de données XDG.
Pochoir invite fait
Invite d'invite de l'utilisateur et ajout aux principales invites
TODO en modifiant les invites existantes.
TODO Automatic Invite Modèle Remplit.
Remplissage du modèle guidé par TOD.
Todo DSL basé
Todo LLM basé
Adverbes de récupération invite
Fait de la grammaire et des actions DSL
Expansion des spécifications
FAIT CLI pour une récupération rapide
Peut-être CLI pour un ensemble de données rapides
Todo ajout d'invites utilisateur / locale
Fait ajouter plus d'invites
FAIT EXEMPLES DE BARD DE Google
Invites d'exemple ChatGpt d'Openai annulées
ProfSynapse Invite
Invite google or-tools
Documentation TODO
Utilisation de Chatbook fait
Utilisation typique
Invite de requête (ingérée)
Fait de DSL invite
Fait une blague quotidienne via CLI
Format invite de TODO
Todo sur les invites de détournement
Diagrammes de TOD
[AA1] Anton Antonov, "Workflows with LLM Fonctions", (2023), RakuForprediction chez WordPress.
[SW1] Stephen Wolfram, "Le nouveau monde des fonctions LLM: intégration de la technologie LLM dans le langage Wolfram", (2023), Stephen Wolfram Writings.
[SW2] Stephen Wolfram, "Invite for Work & Play: Lancement du Wolfram Invite Repository", (2023), Stephen Wolfram Writings.
[AAP1] Anton Antonov, LLM :: Invite Raku Package, (2023), GitHub / AntononCube.
[AAP2] Anton Antonov, LLM :: Functions Raku Package, (2023), GitHub / AntononCube.
[AAP3] Anton Antonov, Jupyter :: ChatBook Raku Package, (2023), GitHub / Antononcube.
[WRIR1] Wolfram Research, Inc., Wolfram Invite Repository