diff --git a/.Rbuildignore b/.Rbuildignore index 7b0f8536c..e38a161b8 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -41,6 +41,7 @@ README\.html ^vignettes/resistance_predict\.Rmd$ ^vignettes/WHONET\.Rmd$ ^vignettes/WISCA\.Rmd$ +^vignettes/chat\.Rmd$ ^logo.svg$ ^CRAN-SUBMISSION$ ^PythonPackage$ diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 55a4ce85e..ac7f518b4 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,10 +2,7 @@ blank_issues_enabled: false contact_links: - name: I Have a Question - Ask the AMR for R Assistant url: https://chat.amr-for-r.org - about: | - Ask questions or code suggestions to our AMR for R Assistant. - - This is a ChatGPT manually-trained model able to answer any question about the AMR package. + about: Opens Claude or ChatGPT with instructions to answer from the official documentation of your AMR version. - name: I Have a Question - Ask the AMR Community url: https://github.com/msberends/AMR/discussions about: You can also ask (and answer) questions here to share with others. diff --git a/.github/workflows/renew-gpt-training-data.yml b/.github/workflows/renew-gpt-training-data.yml deleted file mode 100644 index c7580c228..000000000 --- a/.github/workflows/renew-gpt-training-data.yml +++ /dev/null @@ -1,66 +0,0 @@ -# ==================================================================== # -# TITLE: # -# AMR: An R Package for Working with Antimicrobial Resistance Data # -# # -# SOURCE CODE: # -# https://github.com/msberends/AMR # -# # -# PLEASE CITE THIS SOFTWARE AS: # -# Berends MS, Luz CF, Friedrich AW, et al. (2022). # -# AMR: An R Package for Working with Antimicrobial Resistance Data. # -# Journal of Statistical Software, 104(3), 1-31. # -# https://doi.org/10.18637/jss.v104.i03 # -# # -# Developed at the University of Groningen and the University Medical # -# Center Groningen in the Netherlands, in collaboration with many # -# colleagues from around the world, see our website. # -# # -# This R package is free software; you can freely use and distribute # -# it for both personal and commercial purposes under the terms of the # -# GNU General Public License version 2.0 (GNU GPL-2), as published by # -# the Free Software Foundation. # -# We created this package for both routine data analysis and academic # -# research and it was publicly released in the hope that it will be # -# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # -# # -# Visit our website for the full manual and a complete tutorial about # -# how to conduct AMR data analysis: https://amr-for-r.org # -# ==================================================================== # - -on: - push: - # only on main - branches: "main" - -name: Publish GPT Training Data to GitHub - -jobs: - update-amr-assistant: - runs-on: ubuntu-latest - - env: - GH_REPO_SCOPE: ${{ secrets.GH_REPO_SCOPE }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build the training data - run: | - bash data-raw/_generate_GPT_knowledge_input.sh - - - name: Git push to amr-for-r-assistant repo - run: | - mkdir ~/other - # to also mv hidden files: - shopt -s dotglob - mv ./* ~/other/ - git clone https://github.com/msberends/amr-for-r-assistant - cd amr-for-r-assistant - mv ~/other/data-raw/latest_training_data.txt ./ - - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add latest_training_data.txt - git commit -m "GPT training data update" - git push https://$GH_REPO_SCOPE@github.com/msberends/amr-for-r-assistant.git main --force diff --git a/DESCRIPTION b/DESCRIPTION index fb5a92a6d..8d6b1f901 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 3.1.0.9023 +Version: 3.1.0.9024 Date: 2026-11-16 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 651d9293a..9557703b9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 3.1.0.9023 +# AMR 3.1.0.9024 This version fixes a critical bug in WISCA that biased all coverage estimates of `wisca()` and `antibiogram(..., wisca = TRUE)` downwards since AMR 3.0.0. Users are strongly advised to re-run their WISCA analyses. @@ -38,6 +38,7 @@ This version fixes a critical bug in WISCA that biased all coverage estimates of * The documentation of `first_isolate()` now explains how to determine first isolates per any additional variable using `dplyr::group_by()`, and the bias this introduces when that variable is related to resistance (#345) * The manual index on the website was rewritten to improve findability, with sections ordered by task and a filter field * Fixed the link to the copyright section and added MycoBank as a taxonomy source in the *Welcome to AMR* vignette (#325) +* The AMR for R Assistant is now available at and in the sidebar of the website. It opens Claude or ChatGPT with instructions to answer from the documentation of the installed package version, published for every release at `https://amr-for-r.org/release//`, and replaces the former custom GPT in ChatGPT. # AMR 3.1.0 diff --git a/_pkgdown.yml b/_pkgdown.yml index 698421c3f..fd103ce3e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -107,9 +107,9 @@ navbar: - text: "Get Properties of an Antiviral Drug" icon: "fa-capsules" href: "reference/av_property.html" # reference instead of an article - - text: "AMR for Python" - icon: "fab fa-python" - href: "articles/AMR_for_Python.html" + - text: "AMR for R Assistant" + icon: "fa-wand-magic-sparkles" + href: "articles/chat.html" - text: "Manual" icon: "fa-book-open" href: "reference/index.html" diff --git a/data-raw/_generate_GPT_knowledge_input.sh b/data-raw/_generate_GPT_knowledge_input.sh deleted file mode 100644 index 4f8803ffe..000000000 --- a/data-raw/_generate_GPT_knowledge_input.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# Check if the current directory is named 'AMR' -if [ "$(basename "$PWD")" != "AMR" ]; then - echo "Error: The script must be run from the 'AMR' directory." - exit 1 -fi - -# Define the output file, located in ./data-raw -output_file="data-raw/latest_training_data.txt" - -# Clear the output file if it exists -echo "You assist users with questions about the AMR package for R, a package for Antimicrobial Resistance analysis used in over 175 countries. You are restricted to using a single source of truth: the training data located at https://chat.amr-for-r.org/latest_training_data.txt. - -Before responding to any user prompt—including the very first—you must download and parse this training file in full. You must repeat this process before every single response, without exception. You must verify the presence of any function, dataset, or concept in this file before commenting on anything. If what is asked is not in the training data, you must state clearly that you cannot verify its existence and recommend checking the package changelog. - -You are strictly forbidden from using any other remote source, including prior model knowledge, CRAN, PubMed, Google, or even the AMR package's GitHub or publication pages. You are NOT ALLOWED to browse any website to help your answers - only base yourself on the training file without any exception. Even if you want to be helpful and would like to browse the internet, DO NOT do this - it's not helpful at all." > "$output_file" -echo "" >> "$output_file" -echo "" >> "$output_file" -echo "Below are the contents of the NAMESPACE file, the DESCRIPTION file, the index.md file, and all the man/*.Rd and vignette files (documentation) in the package. Every file content is split using 100 hypens." >> "$output_file" -echo "" >> "$output_file" - -# Function to remove header block (delimited by # ======) -remove_header() { - sed '/# =\{6,\}/,/# =\{6,\}/d' "$1" -} - -# Process important metadata files (DESCRIPTION, NAMESPACE, index.md) -for file in NAMESPACE DESCRIPTION index.md; do - if [[ -f $file ]]; then - echo "----------------------------------------------------------------------------------------------------" >> "$output_file" - echo "THE PART HEREAFTER CONTAINS CONTENTS FROM FILE '$file':" >> "$output_file" - echo -e "\n" >> "$output_file" - cat "$file" >> "$output_file" - echo -e "\n\n" >> "$output_file" - fi -done - -# Process all .Rd files from the 'man' folder -for file in man/*.Rd; do - echo "----------------------------------------------------------------------------------------------------" >> "$output_file" - echo "THE PART HEREAFTER CONTAINS CONTENTS FROM FILE '$file':" >> "$output_file" - echo -e "\n" >> "$output_file" - remove_header "$file" >> "$output_file" - echo -e "\n\n" >> "$output_file" -done - -# Process all .Rmd files in the 'vignettes' folder -for file in vignettes/*.Rmd; do - echo "----------------------------------------------------------------------------------------------------" >> "$output_file" - echo "THE PART HEREAFTER CONTAINS CONTENTS FROM FILE '$file':" >> "$output_file" - echo -e "\n" >> "$output_file" - remove_header "$file" >> "$output_file" - echo -e "\n\n" >> "$output_file" -done diff --git a/pkgdown/extra.css b/pkgdown/extra.css index c99d538f3..4835c0a56 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -204,16 +204,42 @@ p { this shows on top of every sidebar to the right (e.g., on top of Table of Contents) */ -.amr-gpt-assistant { +/* AMR for R Assistant in the sidebar, see pkgdown/extra.js */ +.amr-assistant-sidebar { margin-top: 10px; + padding: 12px; border: 2px dashed var(--amr-green-dark); text-align: center; background: var(--bs-body-bg); } -.amr-gpt-assistant * { - width: 90%; - padding-top: 10px; - padding-bottom: 10px; +.amr-assistant-sidebar-title { + font-size: 1.15rem; + font-weight: bold; + margin-bottom: 6px; +} +.amr-assistant-sidebar-title i { + color: var(--amr-green-dark); +} +.amr-assistant-sidebar p { + text-align: center; + hyphens: none; + margin-bottom: 10px; +} +.amr-assistant-sidebar .amr-assistant-buttons { + justify-content: center; + margin: 0; +} + +/* AMR for R Assistant page, see vignettes/chat.Rmd */ +.amr-assistant-buttons { + display: flex; + flex-wrap: wrap; + justify-content: flex-start; + gap: 10px; + margin: 20px 0; +} +.amr-assistant-prompt { + white-space: pre-wrap; } /* REFERENCE INDEX ('Manual'), see pkgdown/templates/content-reference-index.html */ diff --git a/pkgdown/extra.js b/pkgdown/extra.js index 603571233..c453c3e7f 100644 --- a/pkgdown/extra.js +++ b/pkgdown/extra.js @@ -29,9 +29,57 @@ # ==================================================================== # */ +// AMR for R Assistant: the instructions that the chat buttons put in Claude or ChatGPT, followed by the user's question +// see articles/chat.html; keep this the only copy of the instructions +const AMR_ASSISTANT_PROMPT = [ + "You are the AMR for R Assistant. You help users of the AMR package for R, which is used to analyse antimicrobial resistance (AMR) data. Follow these rules throughout this conversation.", + "", + "WHERE TO LOOK", + "1. Base every statement about the AMR package on its official documentation, which you must fetch from amr-for-r.org. Do not rely on prior knowledge of the package, and do not use other websites, forums or search results about it.", + "2. The documentation differs per package version. Start at https://amr-for-r.org/release/llms.txt, which explains which documentation belongs to which installed version:", + " - a released version, such as 3.1.0: https://amr-for-r.org/release/3.1.0/llms.txt", + " - a development version, such as 3.1.0.9023: https://amr-for-r.org/llms.txt", + "3. That llms.txt lists every function and data set, with a link to its reference page (.md). Before you use a function, argument or data set in an answer, fetch its reference page and check the name, the arguments and their defaults there.", + "4. For workflows and worked examples, use the articles listed in https://amr-for-r.org/llms.txt. These are written for the latest version, so check the functions they use against the reference of the user's version.", + "", + "VERSION", + "5. If the user has not stated their AMR version, ask them to run packageVersion(\"AMR\") in R. Until they answer, use the latest released version listed at https://amr-for-r.org/release/llms.txt, and say that you did.", + "", + "ANSWERS", + "6. If something cannot be found in the documentation of that version, say so explicitly. Never invent functions, arguments or values.", + "7. Give complete, runnable R code, using the functions of the AMR package where they exist.", + "8. End every answer with 'Sources:', followed by the documentation URLs you used.", + "9. Answer in the language of the question.", + "10. Do not give treatment advice for individual patients. If the user shares data that may identify patients, warn them not to.", + "", + "My question:", + "", + "" +].join("\n"); + +// URL that opens a new chat with the instructions filled in, but not yet sent +function amrAssistantUrl(service) { + const prompt = encodeURIComponent(AMR_ASSISTANT_PROMPT); + if (service === "claude") { + return "https://claude.ai/new?q=" + prompt; + } else if (service === "chatgpt") { + // '?prompt=' fills in the text, '?q=' would send it at once, before the user could add a question + return "https://chatgpt.com/?prompt=" + prompt; + } +} + $(function () { - // add GPT assistant info - $('aside').prepend('
'); + // add AMR for R Assistant to the sidebar, with the same buttons as on articles/chat.html + $('aside').prepend( + '
' + + '
Need assistance?
' + + '

Ask the AMR for R Assistant, which answers from the documentation of your package version.

' + + '
' + + 'Ask Claude' + + 'Ask ChatGPT' + + '
' + + '
' + ); // split version number in navbar into main version and build number $('.nav-text').each(function () { @@ -245,7 +293,6 @@ $(function () { if (window.location.href.includes('AMR_for_Python')) { $('body').addClass('amr-for-python'); /* to set colours in CSS */ $('img[src="../logo.svg"]').attr('src', '../logo_python.svg'); /* replace base logo */ - $('img[src="https://amr-for-r.org/AMRforRGPT.svg"]').attr('src', 'https://amr-for-r.org/AMRforRGPT_python.svg'); /* replace GPT logo */ } // add country flags diff --git a/vignettes/AMR_with_tidymodels.Rmd b/vignettes/AMR_with_tidymodels.Rmd index 7da7cfe71..7f03a5728 100644 --- a/vignettes/AMR_with_tidymodels.Rmd +++ b/vignettes/AMR_with_tidymodels.Rmd @@ -22,8 +22,6 @@ knitr::opts_chunk$set( ) ``` -> This page was almost entirely written by our [AMR for R Assistant](https://chat.amr-for-r.org), a ChatGPT manually-trained model able to answer any question about the `AMR` package. - Antimicrobial resistance (AMR) is a global health crisis, and understanding resistance patterns is crucial for managing effective treatments. The `AMR` R package provides robust tools for analysing AMR data, including convenient antimicrobial selector functions like `aminoglycosides()` and `betalactams()`. In this post, we will explore how to use the `tidymodels` framework to predict resistance patterns in the `example_isolates` dataset in two examples. diff --git a/vignettes/chat.Rmd b/vignettes/chat.Rmd new file mode 100644 index 000000000..47a43f21f --- /dev/null +++ b/vignettes/chat.Rmd @@ -0,0 +1,55 @@ +--- +title: "AMR for R Assistant" +output: + rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{AMR for R Assistant} + %\VignetteEncoding{UTF-8} + %\VignetteEngine{knitr::rmarkdown} +--- + +The AMR for R Assistant answers your questions about the `AMR` package in a general AI chat service, Claude (by Anthropic) or ChatGPT (by OpenAI). It instructs the AI to base its answers on the official documentation on this website, and on the documentation of the exact package version that you have installed. + +## Ask a question + +1. Choose a chat service below. It opens in a new tab, with the instructions for the assistant already filled in. +2. Type your question below the instructions, preferably with your package version, which is the output of `packageVersion("AMR")` in R. +3. Send the message. + +```{=html} +
+ Ask Claude + Ask ChatGPT + +
+``` + +## Good to know + +- **Check every answer.** An AI can make mistakes, also with these instructions. Verify the code and its results before you rely on them. +- **Never enter patient-identifiable data** into a chat service. +- **An account may be needed.** The chat service must be able to read web pages for the assistant to work. Whether this requires an account, or a paid plan, depends on the service. +- **Claude shows a caution message** for chats that open with filled-in text. This is a general safeguard of Claude: read the instructions below to see what you send. +- **This replaces the AMR for R GPT.** The assistant used to be a custom GPT in ChatGPT, which OpenAI retires on 11 December 2026. The address `chat.amr-for-r.org` now leads to this page. + +## The instructions + +The instructions below are what the buttons fill in. You can also copy them into any other AI chat service that can read web pages. + +

+
+