Opinionated articles based on the latest news, a churnalist's wet dream.
sycophant
is a tool that generates articles based on the latest news, utilizing OpenAI's APIs,
for text completion and image generation.
Sycophants in ancient Greece were slanderers, revealing petty crimes such as stealing figs.
In English, the word has come to mean a person who tells others what they want to hear, to gain some advantage.
sycophant
will generate an article based on the latest news, on the subject of your choosing.
However, since you are in control of the exact prompt that will be used for the generation,
it may be telling you what you want to hear. Does it have an advantage to gain? You decide. 😏
To be honest, sycophant
is more of a gimmick at this point, or at least that's how I am personallyusing it.
As the proud owner of the domain name robots.army, I always wanted to have some sort of
news aggregator on the theme of robots.
At first I started with the @RobotsArmy Twitter bot, but it got banned. 🤣
Now that OpenAI have opened up so many possibilities, what better way to create a fully autonomous news aggregator,
that generates its own, relatively authentic, content?
sycophant
is a Python script that does the following:
- Fetches the latest news on a subject, using the News API (free tier)
- The user selects the subject and how old the news should be
- Summarizes the top news, using OpenAI's completion API
- The user selects how many articles to summmarize, the model to use, the prompt and the temperature
- Generates an article based on the summaries, using OpenAI's completion API
- The user selects the prompt
- Generates tags for the article, using OpenAI's completion API
- Generates a prompt, based on the article, to be used for image generation, using OpenAI's completion API
- The user selects the prompt to generate... the prompt
- Generates an image based on the prompt, using OpenAI's image API
- Creates a markdown file with the article, the image and the tags
- The user provides a Jinja template for the markdown file
sycophant
assumes Jekyll is used for static site generation.
You can see an example of a website automatically generated by sycophant
at platisd/robots.army.
sycophant
can also be used to generate an article based on specific news, by providing a list of the news' URLs as an argument.
The URLs must be separated by new lines. You can see how this is used in the
.github/workflows/write-article.yml workflow.
sycophant
is triggered when the maintainer creates an issue with the title Write new article
and the
body containing the URLs.
If something goes wrong, e.g. one of the URLs is not reachable, a comment will be left on the issue with a link to the error.
sycophant
can also be used to rewrite an existing article, by providing the article's filename and a prompt to use as additional arguments.
While this is not the main use case, the LLM models will not always generate a good-enough article, so it's good to have the option to rewrite it.
Take a look at the .github/workflows/rewrite-article.yml
workflow which allows new issues with the right syntax to trigger the rewrite-feature of sycophant
.
Specifically, the workflow will be initiated when a new issue is opened with the title Rewrite: <filename>
,
while the body of the issue shall be used as the prompt.
The most difficult part of starting to use sycophant
is -surprise, surprise- figuring out the optimum prompts.
That and possibly making some adjustments to the script if you use a different setup than the one described above.
Your best bet is to get inspired from platisd/robots.army but, nonetheless,
let's go over the different things you would need to do.
Before running sycophant
you need the following:
- Install Python dependencies
pip install -r requirements.txt
- Get an API key for the News API
- Get an API key for the OpenAI API
Aside of the API keys which need to be provided as arguments to the script, the rest of the configuration is done
through a YAML file. You can see an example of such a file at sycophant-config.yaml.
The path to the configuration file is also provided as an argument to the script.
Let's take a look at the configuration file's compulsory fields:
Field | Details | Notes |
---|---|---|
openai/model |
The model to use for all text completion queries | Models overview |
openai/max_tokens |
The maximum number of tokens for each prompt, controls the length | Varies by the model |
openai/temperature |
The temperature to use for all text completion queries | Value between 0-2 |
openai/article_summary_prompt |
The prompt to use for summarizing the different articles | |
openai/final_article_prompt |
The prompt to use for generating the final (published) article | |
openai/final_title_prompt |
The prompt to use for generating the final article's title | |
openai/dalle_model |
The model to use for image generation | Models overview |
openai/dalle_prompt |
The prompt to use for generating the image with Dall-E | |
news/topic |
The topic to use for fetching the latest news | Advanced queries supported |
news/max_age_in_days |
The maximum age of the news to fetch | Free-tier has limits on age |
news/max_articles |
The maximum number of articles to fetch and summarize | More articles, larger GPT prompts |
blog/assets |
The path to where you want your images to be placed | |
blog/attribution |
Whether to mention the source of the generated text | true if not otherwise specified |
blog/posts |
The path to where you want your markdown files to be placed | |
blog/post_template |
The path to the Jinja template to use for the markdown files |
Careful tuning of the prompts will give you seamless operation (i.e. no failure because of too large prompts) and better results when it comes to the generated text and images. You can start from the sample ones and iterate from there. Don't forget to catch up on GPT best practices.
Once you are able to run sycophant
and generate articles locally, you may automate the process and create
a website such as robots.army.
If you use Jekyll and GitHub Actions you can refer to the setup at
platisd/robots.army.
You will need at least two workflows/pipelines:
- The deployment pipeline which runs every time new articles are generated (e.g. by
git push
) and deploys the website to GitHub Pages. Check pages-deploy.yml. - The "build" pipeline which periodically runs
sycophant
and generates articles. Refer to sycophant.yml.
Remember that using sycophant
is not free, as you need to pay for the OpenAI API.
Text completion is rather cheap, but not necessarily the image generation.
After all, it doesn't make sense to generate articles very frequently, unless you pick a topic where news are
constantly being published. Choose the frequency of your cron job wisely.
The News API is free for developer usage but has limits on the number of requests per day and the age of the news.