Skip to content

Commit 839dc88

Browse files
authored
Create a dummy data workflow (#66)
* Create a simple pipeline to begin generating dummy data. * Add the ability to limit how many schemas to process. Useful for debugging since the shell script is hard to interrupt. * Switch to opus model for dummy data generation. * Split out generate_multi, and a master generate script. * Remove the ability to process only some lines. * Make it so the prompt to run is a parameter to generate_multi.sh * Make it so generate_multi expects the list of files from stdin * Documented the implementation shape. * Update the priority ordering of inputs and include reasoning. * Add a backstory prompt. * Update the structure of output. * Update backstory prompt * Add a simple python script to execute the items. * Add a TODO list * Update TODO list * out/ to target/ to match pre-existing .gitignore configuration * Factor out the execute_prompt from main. * Create a notion of compiling a prompt and replacing placeholders. * Add an example that uses a placeholder. * Add in placeholder expansion for most recent target output. * If a matching placeholder in the golden directory exists, use that. * Allow named replacement for raw prompt files. * Add an ability to include raw files, and use it. * If a named include is for a prompt file, it executes the file and uses the results. * Tweak TODOS * Allow multiple layers of inclusions. Note that this introduces the possibility for infinite cyles. * Detect and throw for circular dependencies. * Update naming scheme of target cached files. Now they use the name of the placeholder as the filename. This allows the common case of pinning a favorite output into golden to be a cp operation, instead of requiring a rename. * Remove an extra "no dependencies found" message. It only really makes sense to show at the top level. * Update documentation on placeholder precedence * Allow accepting named arguments from the command line. Not yet used in placehodler matching. * Actually use the overrides provided. * --args --> --overrides * Update TODOs * Store the prompt output in target directory * Verify placeholders have legal names. this allows knowing that $output_dir/_prompt.txt will never collide with a legal name. * Add type hints for all methods * Fix a typing warning * Make it so overrides is not a global but passed through. * Generate the files list via a prompt. * Update documentation * Create a notion of special placeholders. They start with _ and are legal to use in templates but not pass as overrides directly. The only legal one currently is _input. When _input is passed, it changes the filenaming convention in output. This will allow a multi-prompt mode. * Add a TODO * Support multi-line mode in generate.py * In multi-mode, use the same timestamp for all runs. This means that all of the different runs will go in the same parent folder. Previously they'd go in separate folders since each run would have a different timestamp. * Change golden to be a files.txt output I like * Update backstory prompt. * Add a helpful error message to multi-line mode output. * Add a few TODOs * Add a _input_contents special input type. * Allow a more complex multi-piping-in example for data.txt The output is a little messy * Update TODOs * When saving a timestamp, include a _latest alias. This makes more complex multi-line flows a bit easier to do without having to constantly select a new savepoint. * Factor out OverridesDict TypeAlias * Factor out PlaceholderValue return type. Will be changed from a simple str later. * execute_prompt learns how to handle variations. The logic for running multiples moves from main to within execute_prompt. * Factor down fetch_golden, fetch_input, and fetch_raw_prompt into one folder getter. * Fix things broken in last commit. The order of parameters to fetch_folder was backward, leading to placeholders never being found. * BIG COMMIT that breaks the multi-edit flow. Switch around so instead of the top-level command knowing about multi-inputs, instead we have a :multi inclusion directive and the whole flow knows how to expand to multiple template instantiations. The previously working flows don't currently work. For example the schema.txt prompt doesn't work, because it can't load up the actual file contents pointed at by files.txt lines. * Update README TODO * Fix some of the flows of multi flows to actually use well-named variations. * Fix a bug where replacmeents with commands wouldn't be replaced. e.g. ${files:multi} would not be replaced with the value for "files". * Create the _latest symlink before outputting. Before for long-running generations, if you peeked at it before it was done you'd see the old folder. * Simplify fetch_most_recent_target to be a thin wrapper around fetch_folder. * Implement multi-mode for placeholders that have multiple outputs. It currently doesn't work for things in target because the folder doesn't have an extra ${name}. * Fix (I think) multi-prompt mode for latest target. * Switch to outputting prompts in _info/prompts so they get in the way less. * Fix a bug when reading files out of a folder. The filename would be something weird about TextIOWrapper. * Remove the '.txt' from the filename when loading files in folder mode. Otherwise you get multiple .txt.txt for each step. * Switch it so we use the proper values in the multi-load. * Fix an error for json schemas with escapes in it. * Hack in a way to keep variation names in the output. Pass around enough information to back out the information later. * Clarify a TODO * Check in a few golden outputs. * Add a TODO * Remove a completed TODO * fetch_placeholder no longer returns a tuple. The directory name is now unused and unnecessary. * Switch to using the new claude model for generation. * Create ExecutionContext that is wired through, so it's easier to wire through more arguments. * Move the logic of when to create _latest symlink. * Allow ignoring certain sources for placeholders. * Allow specifying more complex ignore arguments. For example, `--ignore golden,target:backstory,schema` is now legal. * Allow '.' in filenames. This means that things like addresses.json.txt doesn't get mangled in downstream flwos. * Add a few TODOs * Ask for more and longer data. * Make the backstory prompt have a lot more influences to weave in. * Allow --ignore default to default to everything but overrides and includes. You rarely want to ignore those, because they're fundamental. * Create a pin_golden utility to quickly pin the most recent version of a named item. * Add __pycache__ to .gitignore. * Update the general purpose ignore to 'existing' * Remove 'prompts' as a --ignore value. It doesn't really make sense anyway, because that's recalculating it! With it, if you want to regenerate everything, you get an error. * Add two TODOs. * Pin a new backstory. * Add a couple TODOs. * Check in new goldens for schema * Checking in golden for data * Rename 'target' to 'cache'
1 parent 74a48c1 commit 839dc88

File tree

112 files changed

+16030
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+16030
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ lib
66
*.tsbuildinfo
77
.DS_Store
88
.vscode
9+
__pycache__
10+
cache

scripts/dummy_data/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Running
2+
3+
Follow the instructions on https://simonwillison.net/2024/Jun/17/cli-language-models/ to install the llm tool and configure for Claude use.
4+
5+
Specifically:
6+
7+
```
8+
brew install llm
9+
llm install llm-claude-3
10+
llm keys set claude
11+
```
12+
13+
You can then generate outputs from a prompt via: `python3 generate.py prompts/backstory.txt`
14+
15+
### Design
16+
17+
A generate.py that is passed a prompt (a filename) to execute.
18+
19+
The prompt is executed by using `llm` under the covers and then puts the output in a folder like this: `./cache/${base_filename}/DATESTRING/{base_filename}.txt` . It also adds a symlink in the `./cache/${base_filename}/_latest` that is updated whenever a new item is saved in that directory.
20+
21+
Prompts can also have named references, like `${name}` that need to be expanded before the prompt can be executed.
22+
23+
The rules of a reference like `${name}` is, in priority order:
24+
- An input to generate.py of `--overrides name val`
25+
- A file in `golden/` that has a filname like `$name.*`
26+
- A file in `cache/$name/`, the named directory that is most recent, its `result.txt`
27+
- A file in `includes/` that has a filename like `$name.*`
28+
- A file in `prompts/` that has a filename like `$name.*` which will be executed and use its result
29+
30+
This order means that prompt output will be used if they exist, falling back on generating new output for a prompt as a last resort. The output naming scheme also means that if you find good output you want to pin in place, you can use `cp` to move the file directly into the golden folder.
31+
32+
This process is recursive. When a name is found it is printed out which version it uses.
33+
34+
As a special case, if your include has the `:multi` directive, it says 'load up the named placeholder, and then interpet each line as a separate value and call this template once for each file'. You can see prompts/schema.txt for an example. Instead of outputting one result, it will output as many results as non-empty lines in that file, named for the lines. Later, other templates that load up that named placeholder, if they find multiple outputs (instead of one file) will also go into multi-output mode.
35+
36+
If you want to override which placeholder to use, you can pass the `--ignore` flag. The legal classes of cached values to ignore: 'golden', 'cache', 'includes', 'overrides'. All of the following are valid:
37+
- `cache` - ignores all pre-computed targets for all placeholders
38+
- `cache:*` - the same semantics as the line above
39+
- `cache:files` - ignores the pre-computed target for the placeholder named files
40+
- `cache:files,backstory` - ignore the pre-computed target for the placeholders named files and backstory
41+
- `cache,golden:files,backstory` - ignore the pre-computed target and the golden for the placeholders named files and backstory.
42+
- `existing` - equivalent to 'golden,cache,prompts:*'
43+
44+
## pin_golden.py
45+
46+
It's possible to manually copy over goldens you like. There's also a simple command, `pin_golden.py` that takes a space-delimited list of placeholder names, and then copies over the most recent result from `cache` into the appropriate place in `golden`, overwriting anything that was already there.
47+
48+
Example: `python3 pin_golden.py schema`
49+
50+
### TODO
51+
- Figure out a way to allow prompts to run a for each on output from a file (so no need for a separate multi command)
52+
- Allow a way to specify `{files|multi-load:schema}
53+
- switch ':' in multi directive to '|'
54+
- remove the fetch_placeholder directory and just return the value (we no longer need the directory)
55+
- If a template references the same placeholder that is a multi, only do the multi one time (this might already work). This sets us up for a use case that allows using the name or value of the multi file, so you could say: 'A file named ${schema|name} with content ${schema}' and ahve it replaced.
56+
- Parallelize multi-generation
57+
- Allow pinning a not-most-recent version (perhaps via an interactive UI?)

0 commit comments

Comments
 (0)