tests/testthat/test-answer_as_integer.R

test_that("answer_as_int returns int", {
  skip_test_if_no_ollama()

  ollama <- llm_provider_ollama()

  response <- "How much is 2+2?" |>
    answer_as_integer() |>
    send_prompt(ollama, verbose = FALSE)

  expect_true(is.numeric(response))
})

test_that("answer_as_integer adds instruction", {
  prompt <- "What is 5+5?" |>
    answer_as_integer() |>
    construct_prompt_text()

  expect_true(
    grepl(
      "You must answer with only an integer (use no other characters).", prompt,
      fixed = TRUE
    )
  )
})

Try the tidyprompt package in your browser

Any scripts or data that you put into this service are public.

tidyprompt documentation built on April 4, 2025, 12:24 a.m.