Skip llm doc tests if offline or no API key is set
Change-Id: Icbbae2d52985db2303d6651156c70ae8bb622d33
diff --git a/tests/testthat/test-readme-against-llm.R b/tests/testthat/test-readme-against-llm.R
index b3da59f..fbac04b 100644
--- a/tests/testthat/test-readme-against-llm.R
+++ b/tests/testthat/test-readme-against-llm.R
@@ -1,5 +1,13 @@
library(tidyllm)
+# Helper function to skip if no API keys are available
+skip_if_no_api_key <- function() {
+ skip_if_not(nzchar(Sys.getenv("OPENAI_API_KEY")) ||
+ nzchar(Sys.getenv("ANTHROPIC_API_KEY")) ||
+ nzchar(Sys.getenv("GOOGLE_API_KEY")),
+ "No API keys found (need OPENAI_API_KEY, ANTHROPIC_API_KEY, or GOOGLE_API_KEY)")
+}
+
# Helper function to find README.md file in current or parent directories
find_readme_path <- function() {
readme_paths <- c("Readme.md", "../Readme.md", "../../Readme.md")
@@ -58,7 +66,6 @@
})
}
-
# Configuration variables
#LLM_MODEL <- "gpt-4o-mini" # OpenAI model option
LLM_MODEL <- "claude-3-5-sonnet-latest" # Claude model option
@@ -136,11 +143,15 @@
}
test_that(paste(LLM_MODEL, "can solve frequency query task with README guidance"), {
+ # Skip if offline
+ skip_if_offline()
+
+ # Skip if no API keys are set
+ skip_if_no_api_key()
+
# Check for README file
skip_if_not(!is.null(find_readme_path()), "Readme.md not found in current or parent directories")
- # Note: tidyllm will handle API key checking and give appropriate errors
-
# Create the prompt with README context and task
prompt <- create_readme_prompt(
"write R code to perform a frequency query for the word 'Demokratie' across the past three years. The code should use the RKorAPClient package and return a data frame.",
@@ -179,11 +190,15 @@
test_that(paste(LLM_MODEL, "can solve collocation analysis task with README guidance"), {
+ # Skip if offline
+ skip_if_offline()
+
+ # Skip if no API keys are set
+ skip_if_no_api_key()
+
# Check for README file
skip_if_not(!is.null(find_readme_path()), "Readme.md not found in current or parent directories")
- # Note: tidyllm will handle API key checking and give appropriate errors
-
# Create the prompt for collocation analysis
prompt <- create_readme_prompt(
"write R code to perform a collocation analysis for the lemma 'setzen'. The code should use the RKorAPClient package's collocationAnalysis function.",
@@ -216,11 +231,15 @@
})
test_that(paste(LLM_MODEL, "can solve corpus query task with README guidance"), {
+ # Skip if offline
+ skip_if_offline()
+
+ # Skip if no API keys are set
+ skip_if_no_api_key()
+
# Check for README file
skip_if_not(!is.null(find_readme_path()), "Readme.md not found in current or parent directories")
- # Note: tidyllm will handle API key checking and give appropriate errors
-
# Create the prompt for corpus query
prompt <- create_readme_prompt(
"write R code to perform a simple corpus query for 'Hello world' and fetch all results. The code should use the RKorAPClient package.",