tests/testthat/test-tokens.R

test_that("useful message if no tokens", {
  tokens_reset()
  expect_snapshot(token_usage())
})

test_that("can retrieve and log tokens", {
  defer(tokens_reset())

  tokens_log("testing", c(10, 50))
  tokens_log("testing", c(0, 10))

  df <- token_usage()
  expect_equal(df$input[df$name == "testing"], 10)
  expect_equal(df$output[df$name == "testing"], 60)
})

Try the ellmer package in your browser

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

ellmer documentation built on April 4, 2025, 3:53 a.m.