tests/testthat/test-gpt_api_calls.R

sample_key <- "4f9bb533-c0ac-4fef-9f7a-9eabe1afcc24"

test_that("OpenAI create completion fails with bad key", {
  expect_error(openai_create_completion(
    model = "text-davinci-003",
    prompt = "a test prompt",
    openai_api_key = sample_key
  ))
})

test_that("OpenAI create edit fails with bad key", {
  expect_error(openai_create_edit(
    model = "text-davinci-edit-001",
    input = "I is a human.",
    temperature = 1,
    instruction = "fix the grammar",
    openai_api_key = sample_key
  ))

  expect_error(openai_create_edit(
    model = "text-davinci-edit-001",
    input = "I is a human.",
    temperature = 1,
    instruction = "fix the grammar",
    top_p = 1,
    openai_api_key = sample_key
  ))
})

test_that("OpenAI create chat completion fails with bad key", {
  expect_error(
    openai_create_chat_completion(
      prompt = "What is your name?",
      openai_api_key = sample_key
    )
  )
})

Try the gptstudio package in your browser

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

gptstudio documentation built on May 29, 2024, 12:30 p.m.