Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use less brittle test for tokens #308

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-azure.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_azure_test("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_true(all(chat$last_turn()@tokens >= 1))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-bedrock.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("can make simple batch request", {
chat <- chat_bedrock("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(26, 5))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-claude.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("can make simple batch request", {
chat <- chat_claude("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(26, 5))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-provider-databricks.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ test_that("can make simple batch request", {
)
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
# Note: the Databricks models don't seem to take "as terse as possible" very
# seriously, and return more verbose responses than expected.
# expect_equal(chat$last_turn()@tokens, c(26, 5))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-deepseek.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_deepseek("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(20, 1))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-gemini.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_gemini("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(17, 2))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-ollama.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_ollama_test("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens >= 1, c(TRUE, TRUE))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-openai.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_openai("Be as terse as possible; no punctuation", model = "gpt-4o-mini")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(27, 2))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-openrouter.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_openrouter_test("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_true(all(chat$last_turn()@tokens >= 1))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-provider-snowflake.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ test_that("can make simple request", {
# chat <- chat_snowflake("Be as terse as possible; no punctuation")
# resp <- chat$chat("What is 1 + 1?", echo = FALSE)
# expect_match(resp, "2")
# expect_equal(chat$last_turn()@tokens, c(64, 2))
# expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
chat <- chat_snowflake("Be as terse as possible; no punctuation")
resp <- coro::collect(chat$stream("What is 1 + 1?"))
expect_match(paste0(unlist(resp), collapse = ""), "2")
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

# Common provider interface -----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-provider-vllm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can make simple request", {
chat <- chat_vllm_test("Be as terse as possible; no punctuation")
resp <- chat$chat("What is 1 + 1?", echo = FALSE)
expect_match(resp, "2")
expect_equal(chat$last_turn()@tokens, c(64, 2))
expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE))
})

test_that("can make simple streaming request", {
Expand Down
Loading