Summarize Many Documents
Suppose I have a directory with multiple .pdf
(or other) files and I want to run a GenAIScript over all of them.
In this example, I’m generating a catchy tweet for each document and I want to save the tweet in another file.
Development
Use the
> GenAIScript: Create new script...
command in the command palette to create a new script.This is an easy script. Assuming the script will take the file as an argument, you can refer to that argument in
env.files
and tell the LLM what to do with it:Right click on the document in VS Code Explorer (it can be a
.pdf
, a.docx
, or a.md
file becausedef
knows how to read and parse all these file types). Select Run GenAIScript. Select the scriptgen-tweet
you just wrote.Assuming we give the GenAIScript a paper describing GenAIScript, the Output will be displayed in a new document tab.
Because we didn’t tell the LLM to write the output to a file, it will by default go to standard out.
Automation
We can run the script from the command line:
The output will be displayed in the terminal.
Now that we have the script working for a single file, we can use the command line to apply it to a list of files. Let’s assume you start with a file
ex1.pdf
you want the output in a new fileex1.tweet.md
. How you do this depends on the shell script you prefer. (See batch processing…).This script requires zx.