Skip to content

Commit

Permalink
Merge pull request #169 from matthewturk/rootstock-2024-12-17
Browse files Browse the repository at this point in the history
rootstock 2024 12 17
  • Loading branch information
matthewturk authored Dec 17, 2024
2 parents 2ab710c + f13d9c1 commit eefd5eb
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 48 deletions.
84 changes: 84 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# See https://www.appveyor.com/docs/getting-started-with-appveyor-for-linux/
# Don't build branches with a PR, since their build will be created with the PR itself.
# Otherwise there would be two builds -- one for the PR and one for the branch.
# If you're having issues with getting your PR to build, make sure there are no merge conflicts.
skip_branch_with_pr: true

# Enable 'Do not build on "Push" events' in the AppVeyor project settings
# to only build commits from pull requests
branches:
only:
- main
- master

# Only run AppVeyor on commits that modify at least one of the following files
# Delete these lines to run AppVeyor on all main/master branch commits
only_commits:
files:
- .appveyor.yml
- build/
- ci/install.sh
- content/

image: ubuntu2204
services:
- docker

# Set SPELLCHECK to true to enable Pandoc spellchecking
environment:
SPELLCHECK: true

install:
# Create the message with the triggering commit before install so it is
# available if the build fails
- TRIGGERING_COMMIT=${APPVEYOR_PULL_REQUEST_HEAD_COMMIT:-APPVEYOR_REPO_COMMIT}
- JOB_MESSAGE=" for commit $TRIGGERING_COMMIT "
- source ci/install.sh

test_script:
- bash build/build.sh
- MANUSCRIPT_FILENAME=manuscript-$APPVEYOR_BUILD_VERSION-${TRIGGERING_COMMIT:0:7}
- cp output/manuscript.html $MANUSCRIPT_FILENAME.html
- cp output/manuscript.pdf $MANUSCRIPT_FILENAME.pdf
- appveyor PushArtifact $MANUSCRIPT_FILENAME.html
- appveyor PushArtifact $MANUSCRIPT_FILENAME.pdf
- |
if [ "${SPELLCHECK:-}" = "true" ]; then
SPELLING_ERRORS_FILENAME=spelling-errors-$APPVEYOR_BUILD_VERSION-${TRIGGERING_COMMIT:0:7}.txt
cp output/spelling-errors.txt $SPELLING_ERRORS_FILENAME
appveyor PushArtifact $SPELLING_ERRORS_FILENAME
SPELLING_ERROR_LOCATIONS_FILENAME=spelling-error-locations-$APPVEYOR_BUILD_VERSION-${TRIGGERING_COMMIT:0:7}.txt
cp output/spelling-error-locations.txt $SPELLING_ERROR_LOCATIONS_FILENAME
appveyor PushArtifact $SPELLING_ERROR_LOCATIONS_FILENAME
fi
build: off

cache:
- ci/cache

on_success:
- echo "Artifacts available from $APPVEYOR_URL/project/$APPVEYOR_ACCOUNT_NAME/$APPVEYOR_PROJECT_SLUG/builds/$APPVEYOR_BUILD_ID/artifacts"
- echo "Updated PDF available from $APPVEYOR_URL/api/buildjobs/$APPVEYOR_JOB_ID/artifacts/$MANUSCRIPT_FILENAME.pdf"
- appveyor AddMessage "$JOB_MESSAGE is now complete."
- |
if [ "${SPELLCHECK:-}" = "true" ]; then
SPELLING_ERROR_COUNT=($(wc -l $SPELLING_ERROR_LOCATIONS_FILENAME))
appveyor AddMessage " <details><summary>Found $SPELLING_ERROR_COUNT potential spelling error(s). Preview:</summary>$(head -n 100 $SPELLING_ERROR_LOCATIONS_FILENAME)"
appveyor AddMessage "... </details>"
fi
on_failure:
- appveyor AddMessage "$JOB_MESSAGE failed."

# The following lines can be safely deleted, which will disable AppVeyorBot
# notifications in GitHub pull requests
# Notifications use Mustache templates http://mustache.github.io/mustache.5.html
# See https://www.appveyor.com/docs/notifications/#customizing-message-template
# for available variables
notifications:
- provider: GitHubPullRequest
template: "AppVeyor [build {{buildVersion}}]({{buildUrl}})
{{#jobs}}{{#messages}}{{{message}}}{{/messages}}{{/jobs}}
{{#passed}}The rendered manuscript from this build is temporarily available for download at:\n\n
{{#jobs}}{{#artifacts}}- [`{{fileName}}`]({{permalink}})\n{{/artifacts}}{{/jobs}}{{/passed}}"
18 changes: 12 additions & 6 deletions .github/workflows/ai-revision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ on:
description: 'Language model'
required: true
type: string
default: 'text-davinci-003'
default: 'gpt-4-turbo'
custom_prompt:
description: 'Custom prompt'
required: false
type: string
default: ''
branch_name:
description: 'Output branch'
required: true
type: string
default: 'ai-revision-davinci'
default: 'ai-revision-gpt4turbo'

jobs:
ai-revise:
Expand All @@ -35,11 +40,11 @@ jobs:
shell: bash --login {0}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Install environment
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Manubot AI revision dependencies
Expand All @@ -54,11 +59,12 @@ jobs:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AI_EDITOR_LANGUAGE_MODEL: ${{ inputs.model }}
AI_EDITOR_FILENAMES_TO_REVISE: ${{ inputs.file_names }}
AI_EDITOR_CUSTOM_PROMPT: ${{ inputs.custom_prompt }}
# More variables can be specified to control the behavior of the model:
# https://github.com/manubot/manubot-ai-editor/blob/main/libs/manubot_ai_editor/env_vars.py
run: manubot ai-revision --content-directory content/
run: manubot ai-revision --content-directory content/ --config-directory ci/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
uses: peter-evans/create-pull-request@v6
with:
commit-message: 'revise using AI model\n\nUsing the OpenAI model ${{ inputs.model }}'
title: 'AI-based revision using ${{ inputs.model }}'
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/manubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
shell: bash --login {0}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# fetch entire commit history to support get_rootstock_commit
fetch-depth: 0
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
echo "DEFAULT_BRANCH_REF=refs/heads/$DEFAULT_BRANCH" >> $GITHUB_ENV
echo "DEFAULT_BRANCH=$DEFAULT_BRANCH"
- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ci/cache
key: ci-cache-${{ github.ref }}
Expand All @@ -93,12 +93,11 @@ jobs:
path: ~/conda_pkgs_dir
key: conda-cache-${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('build/environment.yml') }}
- name: Install Environment
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: manubot
environment-file: build/environment.yml
auto-activate-base: false
miniforge-version: 'latest'
- name: Install Spellcheck
if: env.SPELLCHECK == 'true'
run: bash ci/install-spellcheck.sh
Expand All @@ -112,7 +111,7 @@ jobs:
- name: Build Manuscript
run: bash build/build.sh
- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: manuscript-${{ github.run_id }}-${{ env.TRIGGERING_SHA_7 }}
path: output
Expand Down
42 changes: 15 additions & 27 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ metadata:
csl: https://github.com/citation-style-language/styles/raw/906cd6d43d0c136190ecfbb12f6af0ca794e3c5b/peerj.csl
```

Instructions for generating additional manuscript output formats such as DOCX can be found in [`build/README.md`](build/README.md).

## Spellchecking

When the `SPELLCHECK` environment variable is `true`, the pandoc [spellcheck filter](https://github.com/pandoc/lua-filters/tree/master/spellcheck) is run.
Expand All @@ -331,29 +333,15 @@ Spellchecking is currently only supported for English language manuscripts.

## AI-assisted authoring

The workflow [`ai-revision`](.github/workflows/ai-revision.yaml) is available to assist authors in writing their manuscripts.
It uses large language models to revise the manuscript text, fixing spelling and grammar errors, and improving the sentence structure and the writing style with section-specific prompts.
It is manually triggered by the user (it never runs automatically), and it generates a pull request with suggested revisions.
Then the user can review these changes and merge the pull request if they are acceptable.
More information about this tool is available in [this manuscript](https://greenelab.github.io/manubot-gpt-manuscript/).

You need to change your repository settings to 1) provide a secret with name `OPENAI_API_KEY` containing your OpenAI API token, and 2) allow workflows to create pull requests.
For 1), go to the settings page and, within "Secrets and variables," select "Actions."
Next, create a repository secret with the name `OPENAI_API_KEY` and the value of the API token (you can also do this using "Organization secrets" if available).
For 2), go to "Actions", "General", "Workflow permissions", and activate the checkbox "Allow GitHub Actions to create and approve pull requests."

By default, the tool uses the model `text-davinci-003`.
Make sure to check the [pricing](https://openai.com/api/pricing/) of the OpenAI API.
With $0.02 per 1000 tokens using the most powerful AI models, the cost for a revision of a standard manuscript (around 35 paragraphs) should be around $0.50.
The workflow allows specifying the branch and file names (in the `content/` directory) to revise, the language model to use, and the output branch name.
Internally, the workflow uses the tool [Manubot AI Editor](https://github.com/manubot/manubot-ai-editor) to revise the manuscript.
For more advanced users, the behavior of the Manubot AI Editor or the parameters used for the language model can be changed using environment variables.
These variables can be changed in the workflow file (`ai-revision.yaml`).

It is important to note that using language models in scientific writing is a matter of debate among researchers and journal editors.
Therefore, it's advisable to follow the guidelines that journals and the research community propose.
For example, the *Nature* journal has published [rules about using language models in scholarly writing](https://www.nature.com/articles/d41586-023-00191-1), such as not listing the tools as authors and documenting how they were used.
Since a Manubot-based manuscript uses GitHub, one approach consists of linking the AI-generated pull request, which will transparently show the changes suggested by the AI tool.
Manubot features a powerful integrated _AI Editor_ that can proofread and revise your manuscript.
It can fix lower-level issues such as spelling and grammar errors, but can also make higher-level improvements like simplifying sentence structure, increasing clarity, refining writing style, and more.
You can also customize how it revises your writing in different sections of your manuscript.

Running the AI Editor is _fully in your control_.
It will only run if you manually trigger the workflow [`ai-revision`](.github/workflows/ai-revision.yaml).
The workflow will generate a pull request with suggested revisions for you to review and either accept or reject.

For _full documentation and support_, see the separate [`manubot-ai-editor` repo](https://github.com/manubot/manubot-ai-editor) and [our manuscript](https://doi.org/10.1093/jamia/ocae139).

## Manubot feedback

Expand All @@ -370,12 +358,12 @@ DOI: [10.1371/journal.pcbi.1007128](https://doi.org/10.1371/journal.pcbi.1007128

The Manubot version of this manuscript is available at <https://greenelab.github.io/meta-review/>.

To cite the Manubot AI Editor or for more information on its design, see `@doi:10.1101/2023.01.21.525030`:
To cite the Manubot AI Editor or for more information on its design, see `@doi:10.1093/jamia/ocae139`:

> **A publishing infrastructure for AI-assisted academic authoring**<br>
> **A publishing infrastructure for Artificial Intelligence (AI)-assisted academic authoring**<br>
Milton Pividori, Casey S. Greene<br>
*bioRxiv* (2023) <https://doi.org/grpf8m><br>
DOI: [10.1101/2023.01.21.525030](https://doi.org/10.1101/2023.01.21.525030)
*Journal of the American Medical Informatics Association* (2024) <https://doi.org/gtw9d3><br>
DOI: [10.1093/jamia/ocae139](https://doi.org/10.1093/jamia/ocae139)


## Acknowledgments
Expand Down
27 changes: 23 additions & 4 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ However, setting the `BUILD_PDF` environment variable to `false` will suppress P
For example, run local builds using the command `BUILD_PDF=false bash build/build.sh`.

To build a DOCX file of the manuscript, set the `BUILD_DOCX` environment variable to `true`.
For example, use the command `BUILD_DOCX=true bash build/build.sh`.
To export DOCX for all CI builds, set an environment variable (see docs for [GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables)).
For example, use the command `BUILD_DOCX=true bash build/build.sh` locally.
To export DOCX for all CI builds, set an environment variable in the CI configuration file.
For GitHub Actions, set the variable in `.github\workflows\manubot.yaml` (see [docs](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables)):

```yaml
name: Manubot
env:
BUILD_DOCX: true
```
To generate a single DOCX output of the latest manuscript with GitHub Actions, click the "Actions" tab at the top of the repository.
Select the "Manubot" workflow, then the "Run workflow" button and check "generate DOCX output" before clicking the green "Run workflow" button.
Currently, equation numbers via `pandoc-eqnos` are not supported for DOCX output.

Format conversion is done using [Pandoc](https://pandoc.org/MANUAL.html).
Expand All @@ -20,12 +31,17 @@ To change the options, either edit the YAML files directly or add additional `--

Note: currently, **Windows is not supported**.

Install the [conda](https://conda.io) environment specified in [`environment.yml`](environment.yml) by running the following commands
The Manubot environment is managed with [conda](https://conda.io).
If you do not have `conda` installed, we recommend using the Miniforge3 (includes `conda`) or Mambaforge (includes `conda` and `mamba`) installers from [miniforge](https://github.com/conda-forge/miniforge).
Install the environment from [`environment.yml`](environment.yml) by running one of following commands
(from the repository's root directory):

```sh
# Install the environment
# Install the environment using conda
conda env create --file build/environment.yml
# Install the environment using mamba (faster)
mamba env create --file build/environment.yml
```

If the `manubot` environment is already installed, but needs to be updated to reflect changes to `environment.yml`, use one of the following options:
Expand All @@ -38,6 +54,9 @@ conda env update --file build/environment.yml
# Slower than option 1, but guarantees a fresh environment.
conda env remove --name manubot
conda env create --file build/environment.yml
# option 3: reinstall the manubot environment faster using mamba.
mamba env create --force --file build/environment.yml
```

Activate with `conda activate manubot` (assumes `conda` version of [at least](https://github.com/conda/conda/blob/9d759d8edeb86569c25f6eb82053f09581013a2a/CHANGELOG.md#440-2017-12-20) 4.4).
Expand Down
5 changes: 2 additions & 3 deletions build/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ dependencies:
- pip:
- cffi==1.15.0
- errorhandler==2.0.1
#- git+https://github.com/manubot/manubot@90925eeff90e3aaacaa504fc9a47107609cffc17
#- git+https://github.com/matthewturk/manubot@5ab91d2c90a1fa60e1b78d2658c6bcf35389e249
- git+https://github.com/manubot/manubot@d4242ffa4194e4a13a68c5f6466feff559d3f9d5
- git+https://github.com/manubot/manubot@2914d720dfe02d2bda8781f8f784bc14d461e2e3
#- git+https://github.com/matthewturk/manubot@5af1ed2c790924190597683da5f58646c0740f72
- isbnlib==3.10.10
- opentimestamps-client==0.7.1
- opentimestamps==0.4.3
Expand Down
8 changes: 8 additions & 0 deletions ci/ai-revision-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
files:
ignore:
- front\-matter
- back\-matter
matchings:
- files:
- .*\.md$
prompt: default
Loading

0 comments on commit eefd5eb

Please sign in to comment.