From 140698655417d59d3fee06f580d38aeaf1171ebd Mon Sep 17 00:00:00 2001 From: David Wilkins Date: Tue, 19 Mar 2024 13:47:42 +1030 Subject: [PATCH] Use httptest package, remove .dry_run arguments --- DESCRIPTION | 3 +- NEWS.md | 2 + R/screen.R | 36 ++++++------------ man/screen_source.Rd | 10 +---- man/screen_sources.Rd | 5 +-- .../v1/chat/completions-1d7d6c-POST.json | 23 +++++++++++ .../v1/chat/completions-3a0bf8-POST.json | 23 +++++++++++ .../v1/chat/completions-514df9-POST.json | 23 +++++++++++ .../v1/chat/completions-6bebc8-POST.json | 23 +++++++++++ .../v1/chat/completions-6d6d70-POST.json | 23 +++++++++++ .../v1/chat/completions-c593d1-POST.json | 23 +++++++++++ .../v1/chat/completions-ce1e77-POST.json | 23 +++++++++++ .../v1/chat/completions-cfc308-POST.json | 23 +++++++++++ .../v1/chat/completions-dd5499-POST.json | 23 +++++++++++ .../v1/chat/completions-ee1a79-POST.json | 23 +++++++++++ .../v1/chat/completions-f66a42-POST.json | 23 +++++++++++ .../v1/chat/completions-fd9d36-POST.json | 23 +++++++++++ tests/testthat/setup.R | 1 + tests/testthat/sources_cache.rds | Bin 0 -> 2272 bytes tests/testthat/test-screen.R | 28 ++++++-------- 20 files changed, 305 insertions(+), 56 deletions(-) create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-1d7d6c-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-3a0bf8-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-514df9-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-6bebc8-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-6d6d70-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-c593d1-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-ce1e77-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-cfc308-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-dd5499-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-ee1a79-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-f66a42-POST.json create mode 100644 tests/testthat/api.openai.com/v1/chat/completions-fd9d36-POST.json create mode 100644 tests/testthat/setup.R create mode 100644 tests/testthat/sources_cache.rds diff --git a/DESCRIPTION b/DESCRIPTION index 053e371..320c310 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GPTscreenR Title: GPT-assisted source screening for scoping reviews -Version: 0.0.3.9002 +Version: 0.0.3.9003 Authors@R: person("David", "Wilkins", , "david@wilkox.org", role = c("aut", "cre")) Description: GPT-assisted source screening for scoping reviews. @@ -11,6 +11,7 @@ RoxygenNote: 7.3.1 URL: https://github.com/wilkox/GPTscreenR BugReports: https://github.com/wilkox/GPTscreenR/issues Suggests: + httptest, knitr, rmarkdown, testthat (>= 3.0.0) diff --git a/NEWS.md b/NEWS.md index c1fc0d7..a4ac4f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ - Users can now set the model to use with the `OPENAI_MODEL` environmental variable +- Now using the httptest package for testing, all `.dry_run` arguments have + been removed # GPTscreenR 0.0.3 diff --git a/R/screen.R b/R/screen.R index 7b64634..7b29249 100644 --- a/R/screen.R +++ b/R/screen.R @@ -7,10 +7,9 @@ #' @param abstract The abstract of the article to be screened, a character #' vector of length 1 #' @param .verbose If FALSE, progress messages will be suppressed -#' @param .dry_run If TRUE, calls to the GPT API will be skipped #' #' @export -screen_source <- function(review_description, title, abstract, .verbose = TRUE, .dry_run = FALSE) { +screen_source <- function(review_description, title, abstract, .verbose = TRUE) { # Validate arguments validate_screening_param <- function(param, name) { @@ -49,10 +48,7 @@ screen_source <- function(review_description, title, abstract, .verbose = TRUE, role = "system", content = "You must work step by step. FIRST, generate a numbered list of criteria that must be met for a source to be included." ) - if (! .dry_run) conversation <- complete_GPT_tryCatch( - conversation, - .dry_run = .dry_run - ) + conversation <- complete_GPT_tryCatch(conversation) # Instruct GPT to compare source against criteria if (.verbose) { cli::cli_progress_step("GPT comparing source against criteria") } @@ -61,10 +57,7 @@ screen_source <- function(review_description, title, abstract, .verbose = TRUE, role = "system", content = "NEXT, for each numbered criterion, decide whether the criterion is TRUE or FALSE for the source. It is normal for the title and abstract to not have enough information to make a clear decision for every statement. For these situations, give your best guess. After giving your response of TRUE or FALSE, give a one sentence explanation for your response." ) - if (! .dry_run) conversation <- complete_GPT_tryCatch( - conversation, - .dry_run = .dry_run - ) + conversation <- complete_GPT_tryCatch(conversation) # Instruct GPT to give its final response if (.verbose) { cli::cli_progress_step("GPT giving its final recommendation") } @@ -73,15 +66,10 @@ screen_source <- function(review_description, title, abstract, .verbose = TRUE, role = "system", content = "FINALLY, consider your decisions on whether the source meets the conclusion criteria. Respond with a single word, either INCLUDE or EXCLUDE, representing your recommendation on whether the source meets the inclusion criteria. Do not write anything other than INCLUDE or EXCLUDE." ) - if (! .dry_run) conversation <- complete_GPT_tryCatch( - conversation, - .dry_run = .dry_run - ) + conversation <- complete_GPT_tryCatch(conversation) # Check recommendation is in required format - if (.dry_run) { - GPT_includes <- NA - } else if (! stringr::str_detect(last_message(conversation), + if (! stringr::str_detect(last_message(conversation), "(INCLUDE|EXCLUDE)")) { if (.verbose) cli::cli_alert_warning(c("GPT's recommendation could not be parsed")) GPT_includes <- NA @@ -146,10 +134,9 @@ review_description <- function(objective = NULL, population = NULL, concept = NU #' @param cache_file A file in which the sources list cache is kept (as RDS), #' either fs::path() or character vector of length 1 #' @param .verbose If FALSE, progress messages will be suppressed -#' @param .dry_run If TRUE, calls to the GPT API will be skipped #' #' @export -screen_sources <- function(sources, review_description, n = NULL, random = TRUE, cache_file = fs::path("sources_cache.rds"), .verbose = TRUE, .dry_run = FALSE) { +screen_sources <- function(sources, review_description, n = NULL, random = TRUE, cache_file = fs::path("sources_cache.rds"), .verbose = TRUE) { if (.verbose) cli::cli_h1("Preparing to screen sources") @@ -194,7 +181,7 @@ screen_sources <- function(sources, review_description, n = NULL, random = TRUE, # If cache file already exists, load and use it cache_file <- fs::path(cache_file) - if (fs::file_exists(cache_file) & ! .dry_run) { + if (fs::file_exists(cache_file)) { if (.verbose) cli::cli_alert_info("Loading cached results from {cache_file}") cached_sources <- readRDS(cache_file) sources <- dplyr::left_join(sources, cached_sources) @@ -218,7 +205,7 @@ screen_sources <- function(sources, review_description, n = NULL, random = TRUE, } if (.verbose) cli::cli_alert_info("Creating cache file {cache_file}") - if (! .dry_run) saveRDS(sources, cache_file) + saveRDS(sources, cache_file) } @@ -249,13 +236,12 @@ screen_sources <- function(sources, review_description, n = NULL, random = TRUE, # Screen the source and parse the response response <- screen_source(review_description, title = sources$title[next_i], abstract = sources$abstract[next_i], - .verbose = .verbose, .dry_run = .dry_run) - if (is.na(response$GPT_includes) & ! .dry_run & .verbose) { + .verbose = .verbose) + if (is.na(response$GPT_includes) & .verbose) { cli::cli_alert_warning(c("GPT's recommendation could not be parsed. Discarding this response.")) next } sources$conversation[[next_i]] <- response$conversation - if (.dry_run) response$GPT_includes <- TRUE sources$GPT_includes[next_i] <- response$GPT_includes if (.verbose) cli::cli_alert_info(stringr::str_c( "GPT recommends ", @@ -263,7 +249,7 @@ screen_sources <- function(sources, review_description, n = NULL, random = TRUE, )) # Sync the sources list to the cache file - if (! .dry_run) saveRDS(sources, cache_file) + saveRDS(sources, cache_file) } # Report on current state diff --git a/man/screen_source.Rd b/man/screen_source.Rd index a635e6a..12e1fcf 100644 --- a/man/screen_source.Rd +++ b/man/screen_source.Rd @@ -4,13 +4,7 @@ \alias{screen_source} \title{Screen a source against review inclusion criteria} \usage{ -screen_source( - review_description, - title, - abstract, - .verbose = TRUE, - .dry_run = FALSE -) +screen_source(review_description, title, abstract, .verbose = TRUE) } \arguments{ \item{review_description}{A description of the review, including objective @@ -23,8 +17,6 @@ length 1} vector of length 1} \item{.verbose}{If FALSE, progress messages will be suppressed} - -\item{.dry_run}{If TRUE, calls to the GPT API will be skipped} } \description{ Screen a source against review inclusion criteria diff --git a/man/screen_sources.Rd b/man/screen_sources.Rd index e8bead8..fb5357b 100644 --- a/man/screen_sources.Rd +++ b/man/screen_sources.Rd @@ -10,8 +10,7 @@ screen_sources( n = NULL, random = TRUE, cache_file = fs::path("sources_cache.rds"), - .verbose = TRUE, - .dry_run = FALSE + .verbose = TRUE ) } \arguments{ @@ -30,8 +29,6 @@ which sources are screened, defaults to TRUE} either fs::path() or character vector of length 1} \item{.verbose}{If FALSE, progress messages will be suppressed} - -\item{.dry_run}{If TRUE, calls to the GPT API will be skipped} } \description{ To support multiple screening sessions, a cache of the sources list is diff --git a/tests/testthat/api.openai.com/v1/chat/completions-1d7d6c-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-1d7d6c-POST.json new file mode 100644 index 0000000..5fd9b8d --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-1d7d6c-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDWKpIsk9bftjZN7dpypNY1MtBv", + "object": "chat.completion", + "created": 1710818054, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. TRUE: The study involves nursing home residents, who by definition are likely to be aged 65 or older. The abstract does not specify the age of participants, but usually, nursing homes are inhabited by elderly individuals.\n2. TRUE: The study's population are residents of nursing homes which fit the definition of residential aged care facility provided in the criteria.\n3. TRUE: Alpaca therapy is the central focus of the study conducted in these nursing homes and is evaluated in comparison to a control condition (television viewing lounge).\n4. TRUE: The study evaluates the impact of therapy alpaca program on depression, anxiety, and stress which are aspects of mental health and emotional well-being.\n5. TRUE: This study is a primary research project based on a randomized control trial intended to evaluate the role of therapy alpacas in enhancing mental health and emotional well-being in nursing home residents." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 813, + "completion_tokens": 180, + "total_tokens": 993 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-3a0bf8-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-3a0bf8-POST.json new file mode 100644 index 0000000..3914860 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-3a0bf8-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDdjGJG4lDyNeXDWI8WShICmx7n", + "object": "chat.completion", + "created": 1710818061, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "INCLUDE" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 1051, + "completion_tokens": 1, + "total_tokens": 1052 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-514df9-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-514df9-POST.json new file mode 100644 index 0000000..489b5a0 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-514df9-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KEmrrYlksj7lcvjxzNZNxjy9Pjl", + "object": "chat.completion", + "created": 1710818132, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. TRUE - The study focuses on nursing home residents who are presumably over the age of 65.\n2. TRUE - The study population lives in nursing homes, which are a type of residential aged care facility that provides care and supports daily living activities, as well as nursing services.\n3. TRUE - It is implied by \"nursing home\" that the care delivered is long-term and based on support for daily living and nursing services. The abstract doesn't directly state that the setting is not a hospital, hospice, or independent living village, but these are usually distinct from nursing homes.\n4. TRUE - The study clearly states that therapy alpacas were used as an intervention in the study.\n5. TRUE - The abstract clearly states that the impact on depression, anxiety, and stress (which are aspects of mental health and emotional well-being) was evaluated." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 796, + "completion_tokens": 175, + "total_tokens": 971 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-6bebc8-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-6bebc8-POST.json new file mode 100644 index 0000000..c1d0305 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-6bebc8-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDiAiHIlHBb8HWuTGwCv1hgr14g", + "object": "chat.completion", + "created": 1710818066, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. True - Although the abstract does not explicitly state the age of the nursing home residents, we can reasonably infer that the elderly living in such facilities are predominantly 65 years and older.\n \n2. True - The research is conducted within nursing homes which, per the study description, could be classified as residential aged care facilities as they provide support for activities of daily living and nursing support.\n\n3. True - The abstract clearly mentions the utilization of therapy alpacas in the residential programme.\n \n4. True - Outcomes observed in this study involve reduction in depression, anxiety, and stress, which are aspects of mental health and emotional well-being as required by the criteria.\n \n5. True - This publication refers to a randomized control trial, which classifies it as a primary research source." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 804, + "completion_tokens": 159, + "total_tokens": 963 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-6d6d70-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-6d6d70-POST.json new file mode 100644 index 0000000..ca6fabb --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-6d6d70-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDxxfEmaBdFXWbxT8wcoJWeGGkh", + "object": "chat.completion", + "created": 1710818081, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. TRUE - The source focuses on using therapy alpacas as a non-pharmacological intervention to manage depression, anxiety, and stress.\n2. TRUE - The population targeted for this study are nursing home residents.\n3. TRUE - The source presents original research in the form of a randomized control trial.\n4. TRUE - The study design reported in the source is a randomized control trial.\n5. UNKNOWN - The abstract does not provide information on where the source was published.\n6. TRUE - The source discusses its findings and provides substantial data for the same.\n7. TRUE - The intervention of therapy alpacas appears to be feasible in a nursing home environment, as suggested by the successful implementation in the study.\n8. TRUE - The source provides a clear account of the effectiveness of therapy alpacas in reducing depression, anxiety, and stress.\n9. TRUE - The source includes quantitative data on the reduction of depression, anxiety, and stress as measured by the mean DASS-21 scores.\n10. TRUE - The source is written in English." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 644, + "completion_tokens": 212, + "total_tokens": 856 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-c593d1-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-c593d1-POST.json new file mode 100644 index 0000000..5bb0c09 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-c593d1-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KEglysgX08fJxdjQcK8B02gEPG1", + "object": "chat.completion", + "created": 1710818126, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "INCLUDE" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 994, + "completion_tokens": 1, + "total_tokens": 995 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-ce1e77-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-ce1e77-POST.json new file mode 100644 index 0000000..5e237ac --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-ce1e77-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDn7YOcBAV2efEf2Muk2el7iTaE", + "object": "chat.completion", + "created": 1710818071, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "INCLUDE" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 1021, + "completion_tokens": 1, + "total_tokens": 1022 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-cfc308-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-cfc308-POST.json new file mode 100644 index 0000000..d69c70e --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-cfc308-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KE4MrXRhZVPz67xVRayXBr2cK1t", + "object": "chat.completion", + "created": 1710818088, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "INCLUDE" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 914, + "completion_tokens": 1, + "total_tokens": 915 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-dd5499-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-dd5499-POST.json new file mode 100644 index 0000000..4c05031 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-dd5499-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KEYOaSri7y3wzXVWwrPY6lsGMe8", + "object": "chat.completion", + "created": 1710818118, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. TRUE - The abstract describes a randomized control trial which qualifies as primary research.\n2. TRUE - Though the term \"elderly\" is not explicitly used, it is mentioned that the participants are nursing home residents, a population where the majority are usually over 65.\n3. TRUE - The abstract mentions nursing homes, which fall into the definition of residential-aged care facilities providing daily living and nursing support.\n4. TRUE - The study revolves around the introduction of therapy alpacas for residents, which directly addresses the concept outlined in the inclusion criteria.\n5. TRUE - The abstract states that depression, anxiety, and stress levels of nursing home residents were evaluated and significantly reduced through therapy with alpacas, thus focusing on emotional well-being and mental health." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 784, + "completion_tokens": 152, + "total_tokens": 936 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-ee1a79-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-ee1a79-POST.json new file mode 100644 index 0000000..c5e5a09 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-ee1a79-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KEs1qSHBpNDGQG8uMCVgorzHdbz", + "object": "chat.completion", + "created": 1710818138, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "INCLUDE" + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 1029, + "completion_tokens": 1, + "total_tokens": 1030 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-f66a42-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-f66a42-POST.json new file mode 100644 index 0000000..8f62367 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-f66a42-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KEgIR9m9E5m6EJ2F9LYroH36hYZ", + "object": "chat.completion", + "created": 1710818126, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "1. The study population must be elderly people over the age of 65.\n2. The elderly people in the study must be living in residential aged care facilities that provide care and support for daily living activities and nursing services.\n3. Residential care in this context does not include independent living villages, hospitals, or hospices. It should be long-term.\n4. The study should have integrated therapy alpacas into their program of care for the residents.\n5. The study should be focused on examining the impact of therapy alpaca programs on stress reduction, emotional well-being, mental health, overall life satisfaction, or similar outcomes for residents." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 591, + "completion_tokens": 129, + "total_tokens": 720 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/api.openai.com/v1/chat/completions-fd9d36-POST.json b/tests/testthat/api.openai.com/v1/chat/completions-fd9d36-POST.json new file mode 100644 index 0000000..0c846b6 --- /dev/null +++ b/tests/testthat/api.openai.com/v1/chat/completions-fd9d36-POST.json @@ -0,0 +1,23 @@ +{ + "id": "chatcmpl-94KDomZIpwwzfNWYBqF5Jw56bRQb8", + "object": "chat.completion", + "created": 1710818072, + "model": "gpt-4-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Review Objective: To review sources that focus on non-pharmacological interventions for reducing depression, anxiety and stress in nursing home residents.\n\nFor a source to be included, it must meet the following criteria:\n\n1. The source must focus specifically on non-pharmacological interventions for addressing depression, anxiety, and stress.\n2. The population targeted in the study must be nursing home residents.\n3. The source must present original research, not a review or opinion piece.\n4. The study presented in the source must use randomized trials or experiment.\n5. The source must be published in a reputable scholarly journal or by a respected research institution.\n6. The source must provide significant findings and substantial evidence to back up their conclusions.\n7. The intervention addressed in the study must be feasible and practical for implementation within the nursing home environment.\n8. The source must provide objective and reliable information on the effectiveness of the non-pharmacological intervention.\n9. The source must include quantitative data on the reduction of depression, anxiety, and stress in nursing home residents.\n10. The source must be written in English." + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 350, + "completion_tokens": 218, + "total_tokens": 568 + }, + "system_fingerprint": null +} diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..07b642c --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1 @@ +library(httptest) diff --git a/tests/testthat/sources_cache.rds b/tests/testthat/sources_cache.rds new file mode 100644 index 0000000000000000000000000000000000000000..db444f34bbeff43b8f65879ae3d57c189fff7667 GIT binary patch literal 2272 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 literal 0 HcmV?d00001 diff --git a/tests/testthat/test-screen.R b/tests/testthat/test-screen.R index 1bad2cf..8486a2d 100644 --- a/tests/testthat/test-screen.R +++ b/tests/testthat/test-screen.R @@ -19,56 +19,50 @@ test_that("review_description() works", { }) -test_that("screen_source() inputs are correctly validated", { +with_mock_api({ test_that("screen_source() inputs are correctly validated", { expect_no_error(screen_source( review_description = review_description, title = title, abstract = abstract, - .verbose = FALSE, - .dry_run = TRUE + .verbose = FALSE )) expect_no_warning(screen_source( review_description = review_description, title = title, abstract = abstract, - .verbose = FALSE, - .dry_run = TRUE + .verbose = FALSE )) expect_error(screen_source( review_description = FALSE, title = title, abstract = abstract, - .verbose = FALSE, - .dry_run = TRUE + .verbose = FALSE )) expect_error(screen_source( title = title, abstract = abstract, - .verbose = FALSE, - .dry_run = TRUE + .verbose = FALSE )) expect_warning(screen_source( review_description = "", title = title, abstract = abstract, - .verbose = FALSE, - .dry_run = TRUE + .verbose = FALSE )) -}) +}) }) -test_that("Screening works", { +with_mock_api({ test_that("Screening works", { expect_no_error(screen_source(review_description = review_description, title = title, - abstract = abstract, .verbose = FALSE, .dry_run = TRUE)) + abstract = abstract, .verbose = FALSE)) expect_no_error( - screen_sources(sources = sources, review_description = review_description, .dry_run = TRUE, + screen_sources(sources = sources, review_description = review_description, .verbose = FALSE) ) - -}) +}) })