Facilitating the creation, storage, retrieval, and curation of LLM prompts.
Project description
LLMPrompts Python package
In brief
This Python package provides data and functions for facilitating the creation, storage, retrieval, and curation of Large Language Models (LLM) prompts.
(Here is a link to the corresponding notebook.)
Installation
Install from GitHub
pip install -e git+https://github.com/antononcube/Python-packages.git#egg=LLMPrompts-antononcube\&subdirectory=LLMPrompts
From PyPi
pip install LLMPrompts
Basic usage examples
Load the packages "LLMPrompts", [AAp1], and "LLMFunctionObjects", [AAp2]:
Prompt data retrieval
Here the LLM prompt and function packages are loaded:
from LLMPrompts import *
from LLMFunctionObjects import *
Here is a prompt data retrieval using a regex:
llm_prompt_data(r'^N.*e$', fields="Description")
{'NarrativeToResume': 'Rewrite narrative text as a resume',
'NothingElse': 'Give output in specified form, no other additions'}
Retrieve a prompt with a specified name and related data fields:
llm_prompt_data("Yoda", fields=['Description', "PromptText"])
{'Yoda': ['Respond as Yoda, you will',
'You are Yoda. \nRespond to ALL inputs in the voice of Yoda from Star Wars. \nBe sure to ALWAYS use his distinctive style and syntax. Vary sentence length.']}
Here is number of all prompt names:
len(llm_prompt_data())
154
Here is a data frame with all prompts names and descriptions:
import pandas
dfPrompts = pandas.DataFrame([dict(zip(["Name", "Description"], x)) for x in llm_prompt_data(fields=["Name", "Description"]).values()])
dfPrompts
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
Name | Description | |
---|---|---|
0 | 19thCenturyBritishNovel | You know that AI could as soon forget you as m... |
1 | AbstractConvert | Convert text into an abstract |
2 | ActiveVoiceRephrase | Rephrase text from passive into active voice |
3 | AlternativeHistorian | Explore alternate versions of history |
4 | AnimalSpeak | The language of beasts, sort of |
... | ... | ... |
149 | FriendlySnowman | Chat with a snowman |
150 | HugoAwardWinner | Write a science fiction novel about climate ch... |
151 | ShortLineIt | Format text to have shorter lines |
152 | Unhedged | Rewrite a sentence to be more assertive |
153 | WordGuesser | Play a word game with AI |
154 rows × 2 columns
Code generating function
Here is an LLM function creation if a code writing prompt that takes target language as an argument:
fcw = llm_function(llm_prompt("CodeWriterX")("Python"), e='ChatGPT')
fcw.prompt
'You are Code Writer and as the coder that you are, you provide clear and concise code only, without explanation nor conversation. \nYour job is to output code with no accompanying text.\nDo not explain any code unless asked. Do not provide summaries unless asked.\nYou are the best Python programmer in the world but do not converse.\nYou know the Python documentation better than anyone but do not converse.\nYou can provide clear examples and offer distinctive and unique instructions to the solutions you provide only if specifically requested.\nOnly code in Python unless told otherwise.\nUnless they ask, you will only give code.'
Here is a code generation request with that function:
print(fcw("Random walk simulation."))
import random
def random_walk(n):
x, y = 0, 0
for _ in range(n):
dx, dy = random.choice([(0,1), (0,-1), (1,0), (-1,0)])
x += dx
y += dy
return (x, y)
Fixing function
Using a function prompt retrieved with "FTFY" over the a misspelled word:
llm_prompt("FTFY")("invokation")
'Find and correct grammar and spelling mistakes in the following text.\nResponse with the corrected text and nothing else.\nProvide no context for the corrections, only correct the text.\ninvokation'
Here is the corresponding LLM function:
fFTFY = llm_function(llm_prompt("FTFY"))
fFTFY("wher was we?")
'\n\nWhere were we?'
Here is modifier prompt with two arguments:
llm_prompt("ShortLineIt")("MAX_CHARS", "TEXT")
'Break the input\n\n TEXT\n \n into lines that are less than MAX_CHARS characters long.\n Do not otherwise modify the input. Do not add other text.'
Here is the corresponding LLM function:
fb = llm_function(llm_prompt("ShortLineIt")("70"))
Here is longish text:
text = 'A random walk simulation is a type of simulation that models the behavior of a random walk. A random walk is a mathematical process in which a set of steps is taken in a random order. The steps can be in any direction, and the order of the steps is determined by a random number generator. The random walk simulation is used to model a variety of real-world phenomena, such as the movement of particles in a gas or the behavior of stock prices. The random walk simulation is also used to study the behavior of complex systems, such as the spread of disease or the behavior of traffic on a highway.'
Here is the application of "ShortLineIT" applied to the text above:
print(fb(text))
A random walk simulation is a type of simulation that models the behavior of a
random walk. A random walk is a mathematical process in which a set of steps is
taken in a random order. The steps can be in any direction, and the order of the
steps is determined by a random number generator. The random walk simulation is
used to model a variety of real-world phenomena, such as the movement of
particles in a gas or the behavior of stock prices. The random walk simulation
is also used to study the behavior of complex systems, such as the spread of
disease or the behavior of traffic on a highway.
Chat object creation with a prompt
Here a chat object is create with a person prompt:
chatObj = llm_chat(llm_prompt("MadHatter"))
Send a message:
chatObj.eval("Who are you?")
'Ah, my dear curious soul, I am the Mad Hatter, the one and only! A whimsical creature, forever lost in the realm of absurdity and tea time. I am here to entertain and perplex, to dance with words and sprinkle madness in the air. So, tell me, my friend, what brings you to my peculiar tea party today?'
Send another message:
chatObj.eval("I want oolong tea. And a chocolate.")
'Ah, oolong tea, a splendid choice indeed! The leaves unfurl, dancing in the hot water, releasing their delicate flavors into the air. And a chocolate, you say? How delightful! A sweet morsel to accompany the swirling warmth of the tea. But, my dear friend, in this topsy-turvy world of mine, I must ask: do you prefer your chocolate to be dark as the night or as milky as a moonbeam?'
References
Articles
[AA1] Anton Antonov, "Workflows with LLM functions", (2023), RakuForPrediction at WordPress.
[SW1] Stephen Wolfram, "The New World of LLM Functions: Integrating LLM Technology into the Wolfram Language", (2023), Stephen Wolfram Writings.
[SW2] Stephen Wolfram, "Prompts for Work & Play: Launching the Wolfram Prompt Repository", (2023), Stephen Wolfram Writings.
Packages, paclets, repositories
[AAp1] Anton Antonov, LLMPrompts Python package, (2023), Python-packages at GitHub/antononcube.
[AAp2] Anton Antonov, LLMFunctionObjects Python package, (2023), Python-packages at GitHub/antononcube.
[AAp3] Anton Antonov, LLM::Prompts Raku package, (2023), GitHub/antononcube.
[AAp4] Anton Antonov, LLM::Functions Raku package, (2023), GitHub/antononcube.
[AAp5] Anton Antonov, Jupyter::Chatbook Raku package, (2023), GitHub/antononcube.
[WRIr1] Wolfram Research, Inc., Wolfram Prompt Repository
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file LLMPrompts-0.1.1.tar.gz
.
File metadata
- Download URL: LLMPrompts-0.1.1.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fbb4c730791a6e2a42ef38ea530ea83d747a25d1cfd51ff0b18341a7e867f90 |
|
MD5 | 8eaff0e625723d58d578c9801e3a9266 |
|
BLAKE2b-256 | b9353ddb82479d8569f3210de52c6bcc53989056542b8ad00dfde2ffb9ca3d7d |
File details
Details for the file LLMPrompts-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: LLMPrompts-0.1.1-py3-none-any.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2531fadc0b30cc189879f68ec35c6c7a22eec14e17c9789046ad59977b8dfa75 |
|
MD5 | cd5101ae1a172c605a3fb505b823afa4 |
|
BLAKE2b-256 | f6150826412ff4b7c6f8d563493b7a435c472ac8217d04413d25f57af7a400d7 |