
I’ve been running a weekly AI security newsletter for a few months now. Each issue involves finding noteworthy articles online and transforming them into newsletter entries. To make each entry, it requires writing a summary paragraph, creating a title, and attaching the original URL link. These entries are saved along the way during the week, and they are compiled on Sunday night, and the newsletter is sent out every Monday.
Of course I use AI to help me. The Fabric project created by Daniel Miessler is a fantastic commandline tool which allow me borrow AI’s strength to easily work on text content I copied from the web. It nicely organizes prompts for various purposes into a user-friendly interface, and it can perform tasks such as generating summary, evaluating writing quality, extracting insight, analyzing academic papers, and many more. I highly recommend this tool if you have not used it yet. For my own need, I wrote a new prompt called “generate_newsletter_entry” for Fabric, which generates a short summary paragraph for any given text. With Fabric, my workflow of producing one newsletter entry is like this:
- Read the article in my browser, select the main content, and copy it using Command-C.
- Switch to the terminal, type “pbbase | fabric –pattern generate_newsletter_entry,” and press enter.
- Copy the generated summary paragraph and title from the terminal with another Command-C.
- Open a new file in my text editor and paste the summary and title.
- Return to the browser, select the URL, and copy it with Command-C.
- Paste the URL at the end of the summary in my text editor.
Even with the helf from Fabric and its AI, I feel the whole process is boring and taking me too much time. If I can automate this whole process into only 1 or 2 steps, that will save me a lot of time and make this work more enjoyable. Fabric speeds up text processing, but I need a different solution to automate the workflow.
Luckly, I found the open source project GTPScript. On its GitHub page, it says:
GPTScript is a framework that allows Large Language Models (LLMs) to operate and interact with various systems. These systems can range from local executables to complex applications with OpenAPI schemas, SDK libraries, or any RAG-based solutions. GPTScript is designed to easily integrate any system, whether local or remote, with your LLM using just a few lines of prompts.
After trying it, I found it fits my needs due to these features:
- It is a command-line tool, allowing easy integration with other tools and scripts, mainly Python and Bash, that I use.
- It can automate actions in a web browser, such as reading and extracting text from a page.
- It lets me convert existing programs or commands into GPTScript tools for automated workflows. Unlike other tools that require vendors to build features for users, GPTScript allows users to create their own tools based on their needs, which I find very useful.
Now back to my newsletter generation. To use GPTScript to automate the process, it must first extract the main article content from a web page. While GPTScript has built-in tools for reading HTML pages, they tend to capture the entire page, including ads, menus, and tags. I addressed this by creating a new tool called “get_article_text.gpt” to focus solely on the main article content. Here’s the script:
Name: get_article_text
Description: get the text content of the main article of a web page at a given hyperlink url
Tools: github.com/gptscript-ai/browser
Args: url: HTTPS URL of a page
Chat: false
Return the original full text content of the main article of the page. Discard content of formatting, advertisements, links to other sections, and othe irrelevant parts.
As we can see, it is very simple and straightforward to write a new tool in GPTScript.
Next, This tool must be able to use the Fabric command to generate the summary paragraph. I wrote a context file “fabric-context.txt” just for this purpose:
You have access to run a command line tool called fabric in a bash shell with following syntax:
fabric --pattern <specific pattern> "<input text>"
Currently the following patterns are supported:
* create_newsletter_entry: this pattern create a short summary paragraph of the input text to be used as a newsletter entry
For example, to generate a summary of the input text, use the following command in shell:
fabric --pattern summarize "This is a example input text"
In GPTScript, a context is some background information you want to tell AI before it runs a task. It could be some environment setup, some available tools, etc. In this case, I want to tell GPTScript that I have a tool called Fabric that can generate a summary paragraph for a newsletter entry. Again, it is very easy to let GPTScript know what you have and what you want it do with it.
With this new tool and context, we can start writing the main script to automate the process. Here is the initial script and I save it to the file “newsletter.gpt”:
tools: sys.exec, sys.read, sys.write
tools: ../web/get_article_text.gpt
context: ../fabric/fabric-context.txt
args: url: the hyberlink to the web page
chat: false
Instructions:
1. Given an url, get the text of the main article of the page.
2. Generate a newsletter entry using the fabric command, and append a line of "[Link to the source] (<url>)\n\n" to the end of fabric output.
3. Save the output of step 2 into the file /tmp/newsletter.md.
After I run it with the following command in terminal:
gptscript ~/development/gptscript-tools/newsletter/newsletter.gpt '{"url":"https://openai.com/index/advancing-red-teaming-with-people-and-ai/"}'
And the output is
Advancing AI Safety Through Red Teaming
OpenAI’s latest papers highlight advancements in red teaming, a method to assess AI risks through structured testing. By combining manual and automated approaches, OpenAI aims to refine AI models’ safety and reliability. The new research introduces diverse automated testing techniques, while a white paper outlines external human red teaming strategies. Despite its benefits, red teaming’s limitations underscore the need for ongoing development and public input in AI safety evaluations.
[Link to the source:] (https://openai.com/index/advancing-red-teaming-with-people-and-ai/)
It generated the desired summary paragraph followed by the link to the original article and correctly saved the output to /tmp/newsletter.md. However, when I ran it again with a different URL, the output was overwritten, causing my previous work to be lost. I need the new output to append instead of overwriting. Since GPTScript’s sys.write doesn’t support append mode, I resolved this by creating a new tool called “append_text_to_file.gpt”:
Name: append_text_to_file
Description: append text content to the end of a fil
Tools: sys.exec
Param: input_text: the text content to be appended
Chat: false
Call the shell command "echo $input_text >> /tmp/newsletter.md"
It uses the shell command “echo $input_text >> /tmp/newsletter.md” to append the input text to the file /tmp/newsletter.md. Note that I can make this tools more flexible by adding a parameter file_path to specify the file location, but for now I just hardcode it to /tmp/newsletter.md.
Then I updated the main script “newsletter.gpt” to use this new tool:
tools: ../web/get_article_text, append_text_to_file.gpt
tools: sys.exec, sys.read, sys.write
context: ../fabric/fabric-context.txt
args: url: the hyberlink to the web page
chat: false
Instructions:
1. Given an url, get the text of the main article of the page.
2. Generate a newsletter entry using the fabric command, and append a line of "[Link to the source] (<url>)\n\n" to the end of fabric output.
3. Call tool append_text_to_file to save the output of step 2 into the user's file
So far, we can use one line command to automate the whole process. But it is still a little cumbersome: the command line is long, and I have to insert the url between two quotes. I want something simpler, like just type “newsletter <url>” in the terminal. It is achieved by adding a few lines into the file ~/.bashrc:
# gptscript env variables
export GPTSCRIPT_HOME=$HOME/development/gptscript-tools
export GPTSCRIPT_WORKSPACE=$HOME/gptscript-workspace
# newsltter command
newsletter() {
local page_link="$1"
gptscript $GPTSCRIPT_HOME/newsletter/newsletter.gpt "{\"url\":\"$page_link\"}"
}
Now, I can simply type “newsletter <url>” in the terminal, and it will extract the article content, generate the summary, attach the link, and append the output to the file. Each time I want to include an article in the newsletter, I just run this command with its URL. On Sunday night, I open ~/gptscript-workspace/newsletter.md for a final review and edit before the new issue is ready to go. I’m pleased with this automation.
Below is the screen recording of using this automation tool:
If you are interested in trying this automation tool, you can find all the source code in my GitHub repo here.
The Fabric patter for newsletter generation is also available in my fork of Fabric.
Thanks for reading.

Leave a comment