Dieses Repository gilt für ein RAKU -Paket (Daten), das die Erstellung, Speicherung, Abruf und Kuration großer Sprachmodelle (LLM) erleichtert.
Hier ist ein Beispiel für die Verwendung der prompt domänenspezifischen Sprache (DSL) im Jupyter -Chatbook [AA2, AAP2]:
Aus ZEF 'Ökosystem:
zef install LLM::Prompts
Von Github:
zef install https://github.com/antononcube/Raku-LLM-Prompts.git
Laden Sie die Pakete "LLM :: Eingabeaufforderungen", [AAP1] und "LLM :: Funktionen", [AAP2]:
Verwenden Sie LLM :: Eingabeaufforderungen; Verwenden Sie LLM :: Funktionen;
# (Any)
Zeigen Sie den Rekord der Eingabeaufforderung mit dem Namen "FTFY" an:
.Say für | llm-prompt-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
Hier ist ein Beispiel für das Abrufen von schnellen Daten mit einer Regex, die auf die schnellen Namen angewendet wird:
.Say für LLM-Prompt-Daten (/sc/)
# 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
Weitere Beispiele zur Abrufabnahme finden Sie im Abschnitt "Eingabeaufforderung Daten" unten.
Machen Sie eine LLM -Funktion aus der Eingabeaufforderung mit dem Namen "ftfy":
My & f = LLM-Funktion (LLM-Prompt ('ftfy'));
# -> **@args, *%args { #`(Block|5411904228544) ... }
Verwenden Sie die LLM -Funktion, um die Satz Grammatik zu korrigieren:
& f ('Wo arbeitet er jetzt?')
# Where does he work now?
Generieren Sie den Raku -Code mit der Eingabeaufforderung "Codewriter":
LLM-synthetisiert ([llm-prompt ('codewriter'), "einen zufälligen Spaziergang simulieren."])
RandomWalk [n_]: = akkumulieren [randomChoice [{-1, 1}, n]] ListlinePlot [RandomWalk [1000]]
Die in [SW1] beschriebene Ausdehnung des Chatbook-Eingabeaufforderungsspezifikums kann mit der Funktion llm-prompt-expand
erfolgen:
LLM-Prompt-Expand ('Was ist ein Verbrennungsmotor? #ELI5')
# What is an internal combustion engine? Answer questions as if the listener is a five year old child.
Hier erhalten wir die eigentliche LLM -Antwort:
Verwenden Sie Text :: Utils: Alles; 'Was ist eine Verbrennungsmotor? #Eli5 '==> llm-prompt-expand () ==> llm-synthesize () ==> Wrap-Absatz () ==> 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!
Hier ist ein weiteres Beispiel mit einer Persona und zwei Modifikatoren:
My $ prMt = llm-prompt-expand ("@southernbellespeak Was ist eine leichte Reisestrecke zum 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.
Hier erhalten wir die eigentliche LLM -Antwort:
$ prmt ==> llm-prompt-expand () ==> llm-synthesize () ==> Wrap-Absatz () ==> 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.
Eine formalere Beschreibung der domänenspezifischen Sprache (DSL) zum Angeben von Eingabeaufforderungen enthält die folgenden Elemente:
Schnelle Personas können mit "@" "behandelt" werden. Zum Beispiel:
@Yoda Life can be easy, but some people instist for it to be difficult.
Ein oder mehrere Modifikatoranforderungen können am Ende der Eingabeaufforderungspezifikation angegeben werden. Zum Beispiel:
Summer is over, school is coming soon. #HaikuStyled
Summer is over, school is coming soon. #HaikuStyled #Translated|Russian
Funktionen können so angegeben werden, dass "zellweit" mit "!" und platzieren Sie die Eingabeaufforderungspezifikation zu Beginn der zu erweiterten Eingabeaufforderungspezifikation. Zum Beispiel:
!Translated|Portuguese Summer is over, school is coming soon
Funktionen können so angegeben werden, dass sie auf "vorherige" Nachrichten mit "!" und nur die Eingabeaufforderung mit einem der Zeiger "^" oder "^^" platzieren. Ersteres bedeutet "die letzte Nachricht", letzteres bedeutet "alle Nachrichten".
Die Nachrichten können mit dem Option-Argument angegeben werden :@messages
von llm-prompt-expand
.
Zum Beispiel:
!ShortLineIt^
Hier finden Sie eine Tabelle mit schnellen Expansionsspezifikationen (mehr oder weniger die gleiche wie die in [SW1]):
Spezifikation | Interpretation |
---|---|
@ Name | Direktes Chat mit einer Persona |
# Name | Verwenden Sie Modifikator -Eingabeaufforderungen |
! Name | Verwenden Sie die Funktionsaufforderung mit der Eingabe der Stromzelle |
! Name > | «Wie oben» |
& Name > | «Wie oben» |
! Name ^ | Verwenden Sie die Funktionsaufforderung mit der vorherigen Chat -Nachricht |
! Name ^^ | Verwenden Sie die Funktionsaufforderung mit allen vorherigen Chat -Nachrichten |
! Name │ Param ... | Fügen Sie Parameter für Eingabeaufforderungen hinzu |
Bemerkung: Die Funktionsaufforderungen können beide Sigils haben "!" Und "&".
Bemerkung: Einheitliche Erweiterung erleichtert die Verwendung von LLM-Chatbooks erheblich. Siehe "Jupyter :: Chatbook", [AAP3].
So können die Eingabeaufforderung Daten erhalten werden:
llm-prompt-data.elems
# 222
Hier ist ein Beispiel für das Abrufen von schnellen Daten mit einer Regex, die auf die schnellen Namen angewendet wird:
.Say für LLM-Prompt-Daten (/em/, fields => <Beschreibung Kategorien>)
# 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))
In vielen Fällen ist es besser, die schnellen Daten - oder Daten - im langen Format zu haben. Eingabedaten im Langformformat können mit der Funktion llm-prompt-dataset
erhalten werden:
Verwenden Sie Daten :: Reshaper; Verwenden Sie Daten :: Zusammenfassungen; LLM-Prompt-Datenet.pick (6) ==> to-Pretty-Table (Align => 'L', Feldnames => <Name Beschreibung Variabler Wert>)
# +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+ # | 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 | # +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+
Hier ist eine Aufschlüsselung der Eingabeaufforderungen: Kategorien:
Select-Säulen (LLM-Prompt-Datenet, <variabler Wert>). Grep ({$ _ <Variable> EQ 'Kategorien'}) ==> Datensätze-Summary
#ERROR: Do not know how to summarize the argument. # +-------------------+-------+ # | Variable | Value | # +-------------------+-------+ # | Categories => 225 | | # +-------------------+-------+
Hier werden alle Modifikator -Eingabeaufforderungen im kompakten Format erhalten:
LLM-Prompt-Datenet (): Modifikatoren: Compact ==> to-Pretty-Table (Feldnames => <Name Beschreibung Kategorien>, 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 | # +-----------------------+------------------------------------------------------------------------------+-----------------------------------+
Bemerkung: Die Adverbien :functions
,: :modifiers
und :personas
bedeuten, dass nur die Eingabeaufforderungen mit den entsprechenden Kategorien zurückgegeben werden.
Bemerkung: Die Adverbien :compact
, :functions
,: :modifiers
und :personas
haben die jeweiligen Verknüpfungen :c
,: :f
,: :m
, und :p
.
Die ursprüngliche (für dieses Paket) Sammlung von Eingabeaufforderungen war eine (nicht kleine) Stichprobe der Eingabeaufforderungstexte, die bei Wolfram Prompt Repository (WPR) [SW2] gehostet wurden. Alle Eingabeaufforderungen von WPR im Paket haben die entsprechenden Mitwirkenden und URLs zu den entsprechenden WPR -Seiten.
Beispielaufforderungen von Google/Bard/Palm und OpenAI/CHATGPT werden mit dem Format von WPR hinzugefügt.
Es ist wichtig, programmgesteuert neue Eingabeaufforderungen hinzuzufügen. (Noch nicht implementiert - siehe Abschnitt TODO unten.)
Zunächst wurden die DSL -Grammatik veranlasst und entsprechende Expansionsaktionen wurden implementiert. Eine Grammatik ist jedoch höchstwahrscheinlich nicht benötigt, und es ist besser, "sofortige Expansion" (über Regex-basierte Substitutionen) zu verwenden.
Eingabeaufforderungen können mit dem sub llm-prompt-expand
"nur erweitert" werden.
Hier ist ein Flussdiagramm, das die schnelle Parsen und Ausdehnung in Chat -Zellen von Jupyter -Chatbooks [AAP3] zusammenfasst:
Flussdiagramm LR
Openai {{openai}}
Palm {{palm}}
Llmfunc [[LLM :: Funktionen]]
LLMPROM [[LLM :: Eingabeaufforderungen]]
Codb [(Chat -Objekte)]
PDB [(Eingabeaufforderungen)]
Ccell [/chat cell/]
Crcell [/Chat -Ergebniszelle/]
Cidq {chat id <br> Spezifiziert?}
Cideq {chat id <br> existiert in db?}
RECO [vorhandener <br> Chat -Objekts abrufen]
Coeval [Nachricht <br> Evaluierung]
Promsparse [Eingabeaufforderung <br> DSL Spec Parsing]
KPFQ {bekannt <br> Eingabeaufforderungen <br> gefunden?}
Promexp [Eingabeaufforderung <br> Expansion]
CNCO [Neues Chat -Objekt erstellen]
Cidnone ["Angenommen Chat -ID <br> ist 'keine'"]
Subgraph Chatbook Frontend
Ccell
Crcell
Ende
Subgraph Chatbook Backend
CIDQ
Cideq
Cidnone
Reco
CNCO
Codb
Ende
Subgraph -Eingabeaufforderung
PDB
Llmprom
Promsparse
KPFQ
Promexp
Ende
Subgraph LLM -Interaktion
Coeval
Llmfunc
Palme
Openai
Ende
CCELL -> CIDQ
CIDQ -> | Ja | Cideq
CIDEQ -> | Ja | Reco
RECO -> PRAMPARSE
Coeval -> crcell
CIDEQ -.- CODB
CIDEQ -> | NEIN | CNCO
Llmfunc -.- cnco -.- codb
CNCO -> promparse -> kpfq
KPFQ -> | Ja | Promexp
KPFQ -> | NEIN | Coeval
Promsparse -.- lmprom
Promexp -.- llmprom
Promexp -> Coeval
Llmprom -.- pdb
CIDQ -> | NEIN | Cidnone
Cidnone -> Cideq
Coeval -.- llmfunc
Llmfunc <-.-> openai
Llmfunc <-.-> palm
LadenHier finden Sie ein Beispiel für eine sofortige Erweiterung in einer generischen LLM -Chat -Zelle und Chat -Meta -Zelle, die den Inhalt des entsprechenden Chat -Objekts zeigt:
Das Paket enthält ein CLI -Skript (Befehlszeilenschnittstelle):
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).
Hier ist ein Beispiel mit einem schnellen Namen:
LLM-Prompt Nichtelse 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.
Hier ist ein Beispiel mit einer 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
TODO -Implementierung
Mit dem XDG -Datenverzeichnis erledigt.
Erledigte sofortige Schablone
Erledigte Benutzerumforderungsaufnahme und Ergänzung zu den Hauptaufforderungen
TODO durch Änderung vorhandener Eingabeaufforderungen.
TODO Automatische Eingabeaufforderung Vorlage Ausfüllen.
TODO Guided Template Füllung.
TODO DSL Basis
Todo llm basiert
Erledigte adverbien
Erledigte schnelle DSL -Grammatik und Aktionen
Erledigte Ausdehnung der Spezifikation
Fertig CLI für ein schnelles Abrufen
Vielleicht CLI für einen schnellen Datensatz
TODO -Zugabe von Benutzer/lokalen Eingabeaufforderungen
Fügen Sie mehr Eingabeaufforderungen hinzu
Erledigte Googles Barde -Beispielaufforderungen
Stornierte OpenAIs Chatgpt -Beispielaufforderungen
Profsynapse Eingabeaufforderung
Google oder-Tools Eingabeaufforderung
Todo -Dokumentation
Fertig Chatbook -Nutzung
Typische Verwendung
Abfragen (aufgenommen) Eingabeaufforderungen
Erledigte Eingabeaufforderung DSL
Täglicher Witz über CLI erledigt
TODO PROMPT -Format
Todo bei Entführungsaufforderungen
Todo -Diagramme
[AA1] Anton Antonov, "Workflows mit LLM -Funktionen", (2023), Rakuforprediction bei WordPress.
[SW1] Stephen Wolfram, "Die neue Welt der LLM -Funktionen: Integration der LLM -Technologie in die Wolfram -Sprache", (2023), Stephen Wolfram Schriften.
[SW2] Stephen Wolfram, "Eingabeaufforderungen für Arbeit & Spiel: Starten des Wolfram -Eingabeaufforderungs -Repositorys", (2023), Stephen Wolfram Schriften.
[AAP1] Anton Antonov, LLM :: fordert das Raku -Paket auf, (2023), Github/Antononcube.
[AAP2] Anton Antonov, LLM :: Funktionen Raku Paket, (2023), Github/Antononcube.
[AAP3] Anton Antonov, Jupyter :: Chatbook Raku -Paket, (2023), Github/Antononcube.
[WRIR1] Wolfram Research, Inc., Wolfram -Eingabeaufforderung -Repository