{"id":14965985,"url":"https://github.com/antononcube/raku-llm-prompts","last_synced_at":"2026-01-20T22:36:28.757Z","repository":{"id":193067469,"uuid":"687772830","full_name":"antononcube/Raku-LLM-Prompts","owner":"antononcube","description":"Raku package facilitating the creation, storage, retrieval, and curation of LLM prompts.","archived":false,"fork":false,"pushed_at":"2024-04-17T07:25:35.000Z","size":1011,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-19T04:50:40.828Z","etag":null,"topics":["database","dsl","large-language-models","llm","prompt-engineering","raku","rakulang"],"latest_commit_sha":null,"homepage":"https://raku.land/zef:antononcube/LLM::Prompts","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antononcube.png","metadata":{"files":{"readme":"README-work.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-06T01:21:46.000Z","updated_at":"2024-05-11T15:29:19.303Z","dependencies_parsed_at":"2023-12-20T14:05:57.171Z","dependency_job_id":"27807b14-c975-4ce7-b1dd-ad40d81f5c55","html_url":"https://github.com/antononcube/Raku-LLM-Prompts","commit_stats":{"total_commits":109,"total_committers":1,"mean_commits":109.0,"dds":0.0,"last_synced_commit":"c37c3ab32fb2b6338851346ecf7b94a9fd1b4a3a"},"previous_names":["antononcube/raku-llm-prompts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-LLM-Prompts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-LLM-Prompts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-LLM-Prompts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-LLM-Prompts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antononcube","download_url":"https://codeload.github.com/antononcube/Raku-LLM-Prompts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248059044,"owners_count":21040877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dsl","large-language-models","llm","prompt-engineering","raku","rakulang"],"created_at":"2024-09-24T13:35:39.270Z","updated_at":"2026-01-20T22:36:28.751Z","avatar_url":"https://github.com/antononcube.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLM::Prompts\n\n## In brief\n\nThis repository is for a Raku (data) package facilitating the creation, storage, retrieval, and curation of \n[Large Language Models (LLM) prompts](https://en.wikipedia.org/wiki/Prompt_engineering).\n\nHere is an example of using the prompt Domain Specific Language (DSL) in Jupyter chatbook, [AA2, AAp2]:\n\n![](https://raw.githubusercontent.com/antononcube/Raku-LLM-Prompts/main/docs/Raku-LLM-Prompt-demo-Yoda-1.png)\n\n----\n\n## Installation\n\nFrom Zef' ecosystem:\n\n```\nzef install LLM::Prompts\n```\n\nFrom GitHub:\n\n```\nzef install https://github.com/antononcube/Raku-LLM-Prompts.git\n```\n\n-----\n\n## Usage examples\n\n### Retrieval\n\nLoad the packages \"LLM::Prompts\", [AAp1], and \"LLM::Functions\", [AAp2]:\n\n```perl6\nuse LLM::Prompts;\nuse LLM::Functions;\n```\n\nShow the record of the prompt named \"FTFY\":\n\n```perl6\n.say for |llm-prompt-data\u003cFTFY\u003e;\n```\n\nHere is an example of retrieval of prompt data with a regex that is applied over the prompt names:\n\n```perl6\n.say for llm-prompt-data(/Sc/)\n```\n\nMore prompt retrieval examples are given in the section \"Prompt data\" below.\n\n### LLM functions based on prompts\n\nMake an LLM function from the prompt named \"FTFY\":\n\n```perl6\nmy \u0026f = llm-function(llm-prompt('FTFY'));\n```\n\nUse the LLM function to correct the grammar of sentence:\n\n```perl6\n\u0026f('Where does he works now?')\n```\n\nGenerate Raku code using the prompt \"CodeWriter\":\n\n```perl6, output-lang=perl6, output-prompt=NONE\nllm-synthesize([llm-prompt('CodeWriter'), \"Simulate a random walk.\"])\n```\n\n### Prompt expansion\n\nPrompt expansion using the chatbook prompt spec DSL described in [SW1] \ncan be done using the function `llm-prompt-expand`:  \n\n```perl6\nllm-prompt-expand('What is an internal combustion engine? #ELI5')\n```\n\nHere we get the actual LLM answer:\n\n```perl6\nuse Text::Utils :ALL;\n\n'What is an internal combustion engine? #ELI5' \n        ==\u003e llm-prompt-expand() \n        ==\u003e llm-synthesize() \n        ==\u003e wrap-paragraph() \n        ==\u003e join(\"\\n\") \n```\n\nHere is another example using a persona and two modifiers:\n\n```perl6\nmy $prmt = llm-prompt-expand(\"@SouthernBelleSpeak What is light travel distance to Mars? #ELI5 #Moodified|sad\")\n```\n\nHere we get the actual LLM answer:\n\n```perl6\n$prmt \n        ==\u003e llm-prompt-expand() \n        ==\u003e llm-synthesize()\n        ==\u003e wrap-paragraph()\n        ==\u003e join(\"\\n\") \n```\n\n-----\n\n## Prompt spec DSL\n\nA more formal description of the Domain Specific Language (DSL) for specifying prompts\nhas the following elements: \n\n- Prompt personas can be \"addressed\" with \"@\". For example:\n\n```\n@Yoda Life can be easy, but some people instist for it to be difficult.\n```\n\n- One or several modifier prompts can be specified at the end of the prompt spec. For example:\n\n```\nSummer is over, school is coming soon. #HaikuStyled\n```\n\n```\nSummer is over, school is coming soon. #HaikuStyled #Translated|Russian\n```\n\n- Functions can be specified to be applied \"cell-wide\" with \"!\" and placing the prompt spec at\n  the start of the prompt spec to be expanded. For example:\n\n```\n!Translated|Portuguese Summer is over, school is coming soon\n```\n\n- Functions can be specified to be applied to \"previous\" messages with \"!\" and \n  placing just the prompt with one of the pointers \"^\" or \"^^\". \n  The former means \"the last message\", the latter means \"all messages.\"\n    - The messages can be provided with the option argument `:@messages` of `llm-prompt-expand`.\n- For example:\n\n```\n!ShortLineIt^\n```\n\n- Here is a table of prompt expansion specs (more or less the same as the one in [SW1]):\n\n| Spec               | Interpretation                                      |\n|:-------------------|:----------------------------------------------------|\n| @*name*            | Direct chat to a persona                            |\n| #*name*            | Use modifier prompts                                |\n| !*name*            | Use function prompt with the input of current cell  |\n| !*name*\u003e           | *«same as above»*                                   |\n| \u0026*name*\u003e           | *«same as above»*                                   |\n| !*name*^           | Use function prompt with previous chat message      |\n| !*name*^^          | Use function prompt with all previous chat messages |\n| !*name*￨*param*... | Include parameters for prompts                      |\n\n**Remark:** The function prompts can have both sigils \"!\" and \"\u0026\".\n\n**Remark:** Prompt expansion make the usage of LLM-chatbooks much easier.\nSee \"Jupyter::Chatbook\", [AAp3].\n\n-----\n\n## Prompt data\n\nHere is how the prompt data can be obtained:\n\n```perl6\nllm-prompt-data.elems\n```\n\nHere is an example of retrieval of prompt data with a regex that is applied over the prompt names:\n\n```perl6\n.say for llm-prompt-data(/Em/, fields =\u003e \u003cDescription Categories\u003e)\n```\n\nIn many cases it is better to have the prompt data -- or any data -- in long format.\nPrompt data in long format can be obtained with the function `llm-prompt-dataset`:\n\n```perl6\nuse Data::Reshapers;\nuse Data::Summarizers;\n\nllm-prompt-dataset.pick(6)\n        ==\u003e to-pretty-table(align =\u003e 'l', field-names =\u003e \u003cName Description Variable Value\u003e)\n```\n\nHere is a breakdown of the prompts categories:\n\n```perl6\nselect-columns(llm-prompt-dataset, \u003cVariable Value\u003e).grep({ $_\u003cVariable\u003e eq 'Categories' })».deepmap(*.Str)\n==\u003e records-summary\n```\n\nHere are obtained all modifier prompts in compact format:\n\n```perl6\nllm-prompt-dataset():modifiers:compact ==\u003e to-pretty-table(field-names =\u003e \u003cName Description Categories\u003e, align =\u003e 'l')\n```\n\n**Remark:** The adverbs `:functions`, `:modifiers`, and `:personas` mean \nthat *only* the prompts with the corresponding categories will be returned.\n\n**Remark:** The adverbs `:compact`, `:functions`, `:modifiers`, and `:personas` \nhave the respective shortcuts `:c`, `:f`, `:m`, and `:p`.\n\n\n-----\n\n## Implementation notes\n\n### Prompt collection\n\nThe original (for this package) collection of prompts was a (not small) sample of the prompt texts\nhosted at [Wolfram Prompt Repository](https://resources.wolframcloud.com/PromptRepository/) (WPR), [SW2].\nAll prompts from WPR in the package have the corresponding contributors and URLs to the corresponding WPR pages.  \n\nExample prompts from Google/Bard/PaLM and ~~OpenAI/ChatGPT~~ are added using the format of WPR. \n\n### Extending the prompt collection\n\nIt is essential to have the ability to programmatically add new prompts.\n(Not implemented yet -- see the TODO section below.)\n\n### Prompt expansion\n\nInitially prompt DSL grammar and corresponding expansion actions were implemented.\nHaving a grammar is most likely not needed, though, and it is better to use \"prompt expansion\" (via regex-based substitutions.)\n\nPrompts can be \"just expanded\" using the sub `llm-prompt-expand`. \n\n### Usage in chatbooks\n\nHere is a flowchart that summarizes prompt parsing and expansion in chat cells of Jupyter chatbooks, [AAp3]:\n\n```mermaid\nflowchart LR\n    OpenAI{{OpenAI}}\n    PaLM{{PaLM}}\n    LLMFunc[[LLM::Functions]]\n    LLMProm[[LLM::Prompts]]\n    CODB[(Chat objects)]\n    PDB[(Prompts)]\n    CCell[/Chat cell/]\n    CRCell[/Chat result cell/]\n    CIDQ{Chat ID\u003cbr\u003especified?}\n    CIDEQ{Chat ID\u003cbr\u003eexists in DB?}\n    RECO[Retrieve existing\u003cbr\u003echat object]\n    COEval[Message\u003cbr\u003eevaluation]\n    PromParse[Prompt\u003cbr\u003eDSL spec parsing]\n    KPFQ{Known\u003cbr\u003eprompts\u003cbr\u003efound?}\n    PromExp[Prompt\u003cbr\u003eexpansion]\n    CNCO[Create new\u003cbr\u003echat object]\n    CIDNone[\"Assume chat ID\u003cbr\u003eis 'NONE'\"] \n    subgraph Chatbook frontend    \n        CCell\n        CRCell\n    end\n    subgraph Chatbook backend\n        CIDQ\n        CIDEQ\n        CIDNone\n        RECO\n        CNCO\n        CODB\n    end\n    subgraph Prompt processing\n        PDB\n        LLMProm\n        PromParse\n        KPFQ\n        PromExp \n    end\n    subgraph LLM interaction\n      COEval\n      LLMFunc\n      PaLM\n      OpenAI\n    end\n    CCell --\u003e CIDQ\n    CIDQ --\u003e |yes| CIDEQ\n    CIDEQ --\u003e |yes| RECO\n    RECO --\u003e PromParse\n    COEval --\u003e CRCell\n    CIDEQ -.- CODB\n    CIDEQ --\u003e |no| CNCO\n    LLMFunc -.- CNCO -.- CODB\n    CNCO --\u003e PromParse --\u003e KPFQ\n    KPFQ --\u003e |yes| PromExp\n    KPFQ --\u003e |no| COEval\n    PromParse -.- LLMProm \n    PromExp -.- LLMProm\n    PromExp --\u003e COEval \n    LLMProm -.- PDB\n    CIDQ --\u003e |no| CIDNone\n    CIDNone --\u003e CIDEQ\n    COEval -.- LLMFunc\n    LLMFunc \u003c-.-\u003e OpenAI\n    LLMFunc \u003c-.-\u003e PaLM\n```\n\nHere is an example of prompt expansion in a generic LLM chat cell and chat meta cell \nshowing the content of the corresponding chat object:\n\n![](https://raw.githubusercontent.com/antononcube/Raku-LLM-Prompts/main/docs/Raku-LLM-Prompt-demo-Yoda-2.png)\n\n\n-------\n\n## Command Line Interface\n\n### Playground access\n\nThe package provides a Command Line Interface (CLI) script:\n\n```shell\nllm-prompt --help\n```\n\nHere is an example with a prompt name:\n\n```shell\nllm-prompt NothingElse RAKU\n```\n\n\nHere is an example with a regex:\n\n```shell\nllm-prompt 'rx/ ^ N .* /'\n```\n\n\n-----\n\n## TODO\n\n- [ ] TODO Implementation\n  - [X] DONE Prompt retrieval adverbs\n  - [X] DONE Prompt DSL grammar and actions\n  - [X] DONE Prompt spec expansion\n  - [X] DONE CLI for prompt retrieval\n  - [ ] MAYBE CLI for prompt dataset\n  - [ ] TODO Addition of user/local prompts \n    - [X] DONE Using XDG data directory.\n    - [X] DONE Prompt stencil\n    - [X] DONE User prompt ingestion and addition to the main prompts\n    - [ ] TODO By modifying existing prompts.\n    - [ ] TODO Automatic prompt template fill-in.\n    - [ ] TODO Guided template fill-in.\n      - [ ] TODO DSL based\n      - [ ] TODO LLM based\n- [X] DONE Add more prompts\n  - [X] DONE Google's Bard example prompts\n  - [X] CANCELED OpenAI's ChatGPT example prompts\n  - [X] [ProfSynapse prompt](https://github.com/ProfSynapse/Synapse_CoR)\n  - [X] Google [OR-Tools](https://developers.google.com/optimization) prompt\n- [ ] TODO Documentation\n  - [X] DONE Querying (ingested) prompts\n  - [X] DONE Prompt DSL\n  - [X] DONE Daily joke via CLI\n  - [ ] TODO Prompt format\n  - [ ] TODO On hijacking prompts\n  - [ ] TODO Diagrams\n    - [X] DONE Chatbook usage \n    - [ ] Typical usage\n\n\n-----\n\n## References\n\n### Articles\n\n[AA1] Anton Antonov,\n[\"Workflows with LLM functions\"](https://rakuforprediction.wordpress.com/2023/08/01/workflows-with-llm-functions/),\n(2023),\n[RakuForPrediction at WordPress](https://rakuforprediction.wordpress.com).\n\n[SW1] Stephen Wolfram,\n[\"The New World of LLM Functions: Integrating LLM Technology into the Wolfram Language\"](https://writings.stephenwolfram.com/2023/05/the-new-world-of-llm-functions-integrating-llm-technology-into-the-wolfram-language/),\n(2023),\n[Stephen Wolfram Writings](https://writings.stephenwolfram.com).\n\n[SW2] Stephen Wolfram,\n[\"Prompts for Work \u0026 Play: Launching the Wolfram Prompt Repository\"](https://writings.stephenwolfram.com/2023/06/prompts-for-work-play-launching-the-wolfram-prompt-repository/),\n(2023),\n[Stephen Wolfram Writings](https://writings.stephenwolfram.com).\n\n### Packages, paclets, repositories\n\n[AAp1] Anton Antonov,\n[LLM::Prompts Raku package](https://github.com/antononcube/Raku-LLM-Prompts),\n(2023),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[AAp2] Anton Antonov,\n[LLM::Functions Raku package](https://github.com/antononcube/Raku-LLM-Functions),\n(2023),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[AAp3] Anton Antonov,\n[Jupyter::Chatbook Raku package](https://github.com/antononcube/Raku-Jupyter-Chatbook),\n(2023),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[WRIr1] Wolfram Research, Inc.,\n[Wolfram Prompt Repository](https://resources.wolframcloud.com/PromptRepository)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-llm-prompts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantononcube%2Fraku-llm-prompts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-llm-prompts/lists"}