このリポジトリは、大規模な言語モデル(LLM)プロンプトの作成、ストレージ、検索、キュレーションを促進するRaku(データ)パッケージ用です。
Jupyter Chatbook、[AA2、AAP2]でプロンプトドメイン固有言語(DSL)を使用する例を次に示します。
Zef 'Ecosystemから:
zef install LLM::Prompts
Githubから:
zef install https://github.com/antononcube/Raku-LLM-Prompts.git
パッケージ「LLM :: PROMPTS」、[AAP1]、および「LLM :: functions」、[aap2]をロードします。
LLM ::プロンプトを使用します。LLM:: functionsを使用します。
# (Any)
「ftfy」という名前のプロンプトのレコードを表示します。
.say for | llm-plompt-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
プロンプト名に適用される正規表現を持つ迅速なデータの検索の例を次に示します。
llm-plompt-data(/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
以下の「プロンプトデータ」セクションには、より迅速な検索例が示されています。
「ftfy」という名前のプロンプトからLLM関数を作成します:
my&f = llm-function(llm-prompt( 'ftfy'));
# -> **@args, *%args { #`(Block|5411904228544) ... }
LLM関数を使用して、文の文法を修正します。
&f(「彼は今どこで働いていますか?」)
# Where does he work now?
プロンプト「Codewriter」を使用してRakuコードを生成します。
llm-synthesize([llm-prompt( 'codewriter')、 "ランダムウォークをシミュレートします。"])
randomWalk [n_]:= accumulate [randomChoice [{-1、1}、n]] ListLinePlot [randomWalk [1000]]
[sw1]で説明されているチャットブックプロンプト仕様DSLを使用したプロンプトの拡張は、関数llm-prompt-expand
使用して実行できます。
LLM-PROMPT-EXPAND( '内燃焼エンジンとは?#ELI5')
# What is an internal combustion engine? Answer questions as if the listener is a five year old child.
ここでは、実際のLLMの回答を取得します。
テキスト:: utils:all; '内燃機関とは何ですか? #eli5 '==> llm-prompt-expand()==> llm-synthize()==> 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!
ペルソナと2つの修飾子を使用した別の例を次に示します。
私の$ prmt = llm-prompt-expand( "@sountherbellespeak火星への軽い移動距離は何ですか?#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.
ここでは、実際のLLMの回答を取得します。
$ prmt ==> llm-prompt-expand()==> llm-synthize()==> 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.
プロンプトを指定するためのドメイン固有言語(DSL)のより正式な説明には、次の要素があります。
プロンプトペルソナは、「@」で「アドレス指定」できます。例えば:
@Yoda Life can be easy, but some people instist for it to be difficult.
プロンプト仕様の最後に、1つまたは複数の修飾子プロンプトを指定できます。例えば:
Summer is over, school is coming soon. #HaikuStyled
Summer is over, school is coming soon. #HaikuStyled #Translated|Russian
関数は、「セル全体」を「!」で適用するように指定できます。プロンプトスペックの開始時にプロンプトスペックを拡張するために配置します。例えば:
!Translated|Portuguese Summer is over, school is coming soon
関数は、「以前の」メッセージを「!」で適用するように指定できます。ポインター「^」または「^^」の1つでプロンプトだけを配置します。前者は「最後のメッセージ」を意味し、後者は「すべてのメッセージ」を意味します。
メッセージは、Option引数:@messages
llm-prompt-expand
の@Messagesで提供できます。
例えば:
!ShortLineIt^
これは、迅速な拡張仕様の表です([SW1]の仕様とほぼ同じ):
仕様 | 解釈 |
---|---|
@名前 | ペルソナとの直接チャット |
#名前 | モディファイアプロンプトを使用します |
!名前 | 現在のセルの入力で関数プロンプトを使用します |
!名前> | "同上" |
& name > | "同上" |
!名前^ | 以前のチャットメッセージで関数プロンプトを使用します |
!名前^^ | 以前のすべてのチャットメッセージで関数プロンプトを使用します |
!名前│ param ... | プロンプトのパラメーターを含めます |
注:関数プロンプトには両方のシギル「!」を持つことができます。そして "&"。
注:迅速な拡張LLM-Chatbookの使用がはるかに簡単になります。 「Jupyter :: Chatbook」、[AAP3]を参照してください。
プロンプトデータを取得する方法は次のとおりです。
llm-prompt-data.elems
# 222
プロンプト名に適用される正規表現を持つ迅速なデータの検索の例を次に示します。
.say for llm-plompt-data(/em/、fields => <説明カテゴリ>)
# 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))
多くの場合、長い形式で迅速なデータまたは任意のデータを持っていることをお勧めします。長い形式のプロンプトデータは、関数llm-prompt-dataset
で取得できます。
データを使用:: reshapers; Data :: Summarizersを使用します。 llm-prompt-dataset.pick(6)==> to-pretty-table(align => 'l'、field-names => <name説明変数値>)
# +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+ # | 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 | # +-------------------+-----------------------------------------------------------------------------------------------------------------------------+----------+------------------+
これは、プロンプトカテゴリの内訳です。
select-columns(llm-plompt-dataset、<変動値>)
#ERROR: Do not know how to summarize the argument. # +-------------------+-------+ # | Variable | Value | # +-------------------+-------+ # | Categories => 225 | | # +-------------------+-------+
ここでは、すべての修飾子プロンプトがコンパクトな形式で取得されます。
llm-plompt-dataset():modifiers:compact ==> to-pretty-table(field-names => <name categories>、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 | # +-----------------------+------------------------------------------------------------------------------+-----------------------------------+
注:副詞:functions
、 :modifiers
、および:personas
対応するカテゴリのプロンプトのみが返されることを意味します。
注:副詞:compact
、 :functions
、 :modifiers
、および:personas
それぞれのショートカットがあります:c
、 :f
、 :m
、および:p
。
プロンプトのオリジナル(このパッケージ用)コレクションは、Wolfram Prompt Repository(WPR)、[SW2]でホストされているプロンプトテキストの(小さな)サンプルでした。パッケージ内のWPRからのすべてのプロンプトには、対応するWPRページに対応する貢献者とURLがあります。
Google/Bard/PalmおよびOpenai/ChatGPTからの例のプロンプトは、WPRの形式を使用して追加されます。
新しいプロンプトをプログラム的に追加する機能を持つことが不可欠です。 (まだ実装されていません - 以下のTODOセクションを参照してください。)
最初にDSL文法を促し、対応する拡張アクションが実装されました。ただし、文法を持つことはおそらく必要ない可能性が高く、「迅速な拡張」を使用する方が良い(正規表現ベースの置換を介して)。
サブllm-prompt-expand
使用して、プロンプトを「拡張するだけ」できます。
これは、Jupyterチャットブックのチャットセルの迅速な解析と拡張を要約するフローチャートです[AAP3]:
フローチャートLR
openai {{openai}}
パーム{{palm}}
llmfunc [[llm :: functions]]
llmprom [[llm :: prompts]]
codb [(チャットオブジェクト)]
PDB [(プロンプト)]
ccell [/チャットセル/]
crcell [/チャット結果セル/]
cidq {チャットID <br>指定?}
cideq {チャットID <br>はdb?}に存在します
Reco [既存の<br>チャットオブジェクトを取得]
Coeval [メッセージ<br>評価]
PROMPARSE [プロンプト<br> dsl仕様解析]
kpfq {既知の<br>プロンプト<br> fund?}
promexp [プロンプト<br>拡張]
CNCO [新しい<br>チャットオブジェクトを作成]
cidnone ["チャットIDを想定<br> is 'none'"]
サブグラフチャットブックフロントエンド
ccell
crcell
終わり
サブグラフチャットブックバックエンド
cidq
Cideq
cidnone
Reco
CNCO
codb
終わり
サブグラフプロンプト処理
PDB
llmprom
プロムパース
KPFQ
promexp
終わり
サブグラフLLM相互作用
Coeval
llmfunc
手のひら
Openai
終わり
ccell-> cidq
cidq-> | yes | Cideq
cideq - > | yes | Reco
Reco-> promparse
Coeval-> crcell
Cideq -.- codb
Cideq - > | no | CNCO
llmfunc -.- cnco -.- codb
cnco-> promparse-> kpfq
kpfq-> | yes | promexp
kpfq-> | no | Coeval
promparse -.- llmprom
promexp -.- llmprom
promexp-> coeval
llmprom -.- pdb
cidq-> | no | cidnone
cidnone-> cideq
Coeval -.- llmfunc
llmfunc <-.-> openai
llmfunc <-.-> palm
読み込み一般的なLLMチャットセルとチャットメタセルの迅速な拡張の例を示します。
パッケージは、コマンドラインインターフェイス(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).
ここに迅速な名前の例があります:
LLM-PROMPT NOTEELSE 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.
ここに、正規表現を持つ例があります:
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実装
XDG Data Directoryを使用して完了しました。
プロンプトステンシルを完了しました
完了したユーザープロンプトの摂取とメインプロンプトへの追加
既存のプロンプトを変更してtodo。
TODO自動プロンプトテンプレートの塗りつぶし。
TODOガイド付きテンプレートフィルイン。
Todo DSLベース
Todo LLMベース
迅速な検索副詞を完了しました
迅速なDSL文法とアクションを完了しました
迅速な仕様拡張を完了しました
迅速な検索のためにCLIを完了しました
迅速なデータセットのCLI
ユーザー/ローカルプロンプトの追加
さらにプロンプトを追加します
Googleのバードの例のプロンプトを完了しました
OpenaiのChatGPTの例をキャンセルしました。プロンプト
Profsynapseプロンプト
Googleまたはツールプロンプト
TODOドキュメント
チャットブックの使用を完了しました
典型的な使用法
完了したクエリ(摂取)プロンプト
プロンプトDSLを完了しました
CLI経由で毎日のジョークを完了しました
TODOプロンプト形式
ハイジャックのプロンプトでtodo
Todo図
[AA1] Anton Antonov、「LLM機能を備えたワークフロー」(2023)、WordPressのRakufordiction。
[SW1] Stephen Wolfram、「LLM機能の新世界:LLMテクノロジーをWolfram言語に統合する」(2023)、Stephen Wolframの書物。
[SW2] Stephen Wolfram、「作業とプレイのプロンプト:Wolfram Prompt Repositoryの発売」、(2023)、Stephen Wolframの執筆。
[AAP1] Anton Antonov、LLM :: Prompts 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プロンプトリポジトリ