-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: templates #30
WIP: templates #30
Conversation
Docs preview here: https://llm--30.org.readthedocs.build/en/30/templates.html |
Well this is fun...
And then:
|
Templates are really useful, yes. For now, I use scripts for this purpose, which reduce the amount of typing at its minimum via autocompletion, and make it even easier to call in vim with a shebang command ( Some examples of what I use: a thesaurus and a dictionary. Very short template, but also very useful. Thesaurus% thesaurus an old car
Synonyms: vintage car, classic car, antique car, retro car, dated car, ancient car
Antonyms: new car, modern car, contemporary car, state-of-the-art car, cutting-edge car, advanced car Script: #! /usr/bin/bash
# Check if any arguments were passed to the script
if [[ -n "$@" ]]; then
# Combine all arguments into a single string
input="$*"
else
# Read input from stdin
read input
fi
# Call the `llm` command with the modified input
llm --system "You are a multilingual thesaurus. You give synonyms and antonyms for words in the language they are provided in." "$input" --stream Dictionary% define nimbleness
Definition: the quality of moving quickly and lightly; agility
Example sentence: The gymnast's nimbleness allowed her to perform the complicated routine with ease. Script: #! /usr/bin/bash
# Check if any arguments were passed to the script
if [[ -n "$@" ]]; then
# Combine all arguments into a single string
input="$*"
else
# Read input from stdin
read input
fi
# Call the `llm` command with the modified input
llm --system "You are a multilingual dictionary. Define the given word and create an example sentence using it, ensuring that both are in the language the word is most commonly used. If the language isn't clear, use English." "$input" --stream Following the same idea, I also use |
Those examples are great, thanks for that! Would you be OK with me including those prompts as examples in the documentation? Will credit you in the release notes. |
Sure, go ahead! I appreciate being credited :) Another one I use a lot is this one: % proofread "Who's book is this?"
This sentence should be written as "Whose book is this?" The contraction "who's" is a combination of "who" and "is" and does not fit in this sentence. "Whose" is the correct possessive form of "who", indicating that this book belongs to someone and asking for the owner's identity. The syntax and overall structure of the sentence are correct. Script: #! /usr/bin/bash
# Check if any arguments were passed to the script
if [[ -n "$@" ]]; then
# Combine all arguments into a single string
input="$*"
else
# Read input from stdin
read input
fi
# Call the `llm` command with the modified input
llm --system "You are an expert English writer and grammarian. Review the following English sentence for grammatical correctness, syntax, and overall structure, and provide feedback as necessary." "$input" --stream |
I created a repo to host some of my tools and the scripts I built from It can be found here: https://github.com/sderev/llm-toolbox |
Here's how to detect the named variables in a >>> from string import Template
>>> t = Template("$foo and $bar")
>>> t.pattern
re.compile('\n \\$(?:\n (?P<escaped>\\$) | # Escape sequence of two delimiters\n (?P<named>(?a:[_a-z][_a-z0-9]*)) | # delimiter and a Python identifier\n , re.IGNORECASE|re.VERBOSE)
>>> list(t.pattern.finditer(t.template))
[<re.Match object; span=(0, 4), match='$foo'>, <re.Match object; span=(9, 13), match='$bar'>]
>>> matches = list(t.pattern.finditer(t.template))
>>> matches
[<re.Match object; span=(0, 4), match='$foo'>, <re.Match object; span=(9, 13), match='$bar'>]
>>> matches[0]
<re.Match object; span=(0, 4), match='$foo'>
>>> matches[0][1]
>>> matches[0][0]
'$foo'
>>> matches[1][0]
'$bar'
>>> matches[0].groups()
(None, 'foo', None, None)
>>> matches[1].groups()
(None, 'bar', None, None)
>>> matches[1].groupdict()
{'escaped': None, 'named': 'bar', 'braced': None, 'invalid': None}
|
Here's a problem: thanks to this code it isn't currently possible to pipe content to the tool AND specify extra params: Lines 71 to 73 in 0fc51f4
So this doesn't work:
|
I can use |
Documentation: https://llm--30.org.readthedocs.build/en/30/templates.html |
Refs:
TODO:
llm -t name-of-template
bitllm -t name-of-template -p name value
prompt: that-string
llm templates list