Comments (10)
The trickiest thing about these templates is their design.
The simplest form of template is some text with a replacement variable where the user's additional input is pasted in - something like this:
Summarize this: {input}
But there are all sorts of other things to consider:
- How should system prompts be handled? I'd much rather write the above template as a system prompt of
Summarize this
with the input being sent as the full regular prompt. - How to support more than one placeholder? Would be neat if you could say
llm -t persona -p name Tom -p age 22
- If a template has both a prompt and a system prompt, how are they both stored?
I'm leaning towards YAML for this, because it has neat support for multi-line text blocks.
from llm.
Templates can go in ~/Library/Application Support/io.datasette.llm/templates
- each one can be a file.
Will I force them to be YAML files, or can you have one that is pure text if it's a really simple one?
from llm.
I think YAML will do. A YAML file can contain just a string, and it will be treated right unless it happens to contain a colon character or similar:
>>> import yaml
>>> yaml.safe_load("this is just a string")
'this is just a string'
>>> yaml.safe_load("this is just a string: hooray")
{'this is just a string': 'hooray'}
>>> yaml.safe_load("\"this is just a string: hooray\"")
'this is just a string: hooray'
I can explain enough of this in the documentation to avoid people getting caught out.
from llm.
What should I use for the actual variable substitution part of this? I'd like to keep that to the Python standard library if possible.
I'm tempted to just use this:
>>> s = "Summarize: {input}"
>>> s.format(blah='foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'input'
>>> s.format(input='foo')
'Summarize: foo'
Another option is Template strings: https://docs.python.org/3/library/string.html#template-strings
Template strings support
$
-based substitutions, using the following rules:
$$
is an escape; it is replaced with a single$
.$identifier
names a substitution placeholder matching a mapping key of"identifier"
. By default,"identifier"
is restricted to any case-insensitive ASCII alphanumeric string (including underscores) that starts with an underscore or ASCII letter. The first non-identifier character after the$
character terminates this placeholder specification.${identifier}
is equivalent to$identifier
. It is required when valid identifier characters follow the placeholder but are not part of the placeholder, such as"${noun}ification"
.
>>> from string import Template
>>> t = Template("Summarize: $input")
>>> t.substitute(input="Hello")
'Summarize: Hello'
>>> t.substitute(input2="Hello")
Traceback (most recent call last):
...
KeyError: 'input'
from llm.
OK, I think I'm going to go with $variable
substitution using string.Template
- and the templates themselves will be YAML files which can contain either a string or a dictionary.
If it's a dictionary it can have prompt:
and system:
keys for prompt + system templates.
If you just have a system
then the prompt will default to $input
.
Any other $name
variables will be treated as required parameters, passed using -p name value
.
from llm.
So a set of commands:
llm templates edit name-of-template # Edit the specified template, using $EDITOR
llm templates list # list available templates
llm templates show name-of-template # show a template
llm templates path # path to the templates directory
from llm.
Templates can also have a model: ...
to set the default model for that template.
from llm.
I can use this: https://click.palletsprojects.com/en/8.1.x/utils/#launching-editors
>>> import click
>>> click.edit(filename='/tmp/hello.txt')
from llm.
Idea from:
Slight twist: what if you want to use another template at the same time?
Might be an argument for supporting combined templates - pass
-t
multiple times and the result is a combination of those templates - the most recent of each of the prompt, system prompt, logit biases etc.
from llm.
It would be amazing if you could install new templates by installing Python packages - using a plugin hook. Could be a neat way to distribute more follows templates, especially ones that include functions.
from llm.
Related Issues (20)
- Mechanism for recording a different model ID from the one requested HOT 1
- How to handle fake messages that were not part of real coversations? HOT 3
- llm-llamafile is missing from plugin directory
- How to cut off the LLM in chat mode
- IndexError on Windows for llm chat HOT 1
- llm-groq does not support llama 3 HOT 2
- some plugins fail to install with "Connection refused" error HOT 1
- UI around chat history HOT 1
- [plugin] add IBM watsonx
- A rapidly convert Files to Prompts Using Rust
- Enhancement idea: implement a self help
- Asynchronous API support HOT 1
- Add API documentation on how to import and use this tool as a Python library HOT 1
- Support for GPT-4o HOT 3
- Fix for latest mypy
- Rename the gpt-4-turbo aliases HOT 1
- All I ever get is "insufficient_quota" HOT 5
- llm 0.14: Can't run <<llm chat>> on Windows 11 HOT 1
- llm keys set openai
- Would you be up for a PR that shows help on no options?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llm.