# Getting started -------------------------------------------------------- test_that("can make simple request", { chat <- chat_openai_test() resp <- chat$chat("What is 1 + 1?", echo = FALSE) expect_match(resp, "2") expect_equal(chat$last_turn()@tokens > 0, c(TRUE, TRUE)) }) test_that("can make simple streaming request", { chat <- chat_openai_test() resp <- coro::collect(chat$stream("What is 1 + 1?")) expect_match(paste0(unlist(resp), collapse = ""), "2") }) test_that("can list models", { test_models(models_openai) }) # Common provider interface ----------------------------------------------- test_that("defaults are reported", { expect_snapshot(. <- chat_openai()) }) test_that("supports standard parameters", { chat_fun <- chat_openai_test test_params_stop(chat_fun) }) test_that("all tool variations work", { chat_fun <- chat_openai_test test_tools_simple(chat_fun) test_tools_async(chat_fun) test_tools_parallel(chat_fun) test_tools_sequential(chat_fun, total_calls = 6) }) test_that("can extract data", { chat_fun <- chat_openai_test test_data_extraction(chat_fun) }) test_that("can use images", { # Needs mini to get shape correct chat_fun <- \(...) chat_openai_test(model = "gpt-4.1-mini", ...) test_images_inline(chat_fun) test_images_remote(chat_fun) }) # Custom tests ----------------------------------------------------------------- test_that("can retrieve log_probs (#115)", { chat <- chat_openai_test(params = params(log_probs = TRUE)) pieces <- coro::collect(chat$stream("Hi")) logprobs <- chat$last_turn()@json$choices[[1]]$logprobs$content expect_equal( length(logprobs), length(pieces) - 2 # leading "" + trailing \n ) }) # Custom ----------------------------------------------------------------- test_that("as_json specialised for OpenAI", { stub <- ProviderOpenAI(name = "", base_url = "", api_key = "", model = "") expect_snapshot( as_json(stub, type_object(.additional_properties = TRUE)), error = TRUE ) obj <- type_object(x = type_number(required = FALSE)) expect_equal( as_json(stub, obj), list( type = "object", description = "", properties = list(x = list(type = c("number", "null"), description = "")), required = list("x"), additionalProperties = FALSE ) ) }) test_that("seed is deprecated, but still honored", { expect_snapshot(chat <- chat_openai_test(seed = 1)) expect_equal(chat$get_provider()@params$seed, 1) })