-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-llm_api_server.R
More file actions
55 lines (51 loc) · 2.26 KB
/
test-llm_api_server.R
File metadata and controls
55 lines (51 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
testthat::test_that("Test llm_api_server with too short OpenAI key", {
shiny::testServer(llm_api_server,
args = list(no_internet = NULL, exclude_pattern = ""),
{
# Arrange
print("test llm_api_server: OpenAI provider with valid key file")
# Act
session$setInputs(
provider = "OpenAI",
api_key_file = structure(
list(
name = "test-key",
size = 10L,
type = "text/plain",
datapath = testthat::test_path("test-gpt_key_too_short.txt")
),
class = "data.frame",
row.names = c(NA, -1L)
)
)
testthat::expect_length(api(), 0)
testthat::expect_equal(attr(api(), "error"), "API key appears too short.")
})
})
testthat::test_that("Test llm_api_server with OpenAI key", {
shiny::testServer(llm_api_server,
args = list(no_internet = NULL, exclude_pattern = ""),
{
# Arrange
print("test llm_api_server: OpenAI provider with invalid key file")
# Act
session$setInputs(
provider = "OpenAI",
api_key_file = structure(
list(
name = "test-key",
size = 10L,
type = "text/plain",
datapath = testthat::test_path("test-gpt_key_invalid.txt")
),
class = "data.frame",
row.names = c(NA, -1L)
)
)
testthat::expect_length(api(), 0)
testthat::expect_equal(
substr(attr(api(), "error"), 1, 64),
"API request failed: Unauthorized: API key is invalid or expired."
)
})
})