-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.R
54 lines (44 loc) · 1.31 KB
/
utils.R
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
# using some script in https://github.com/irudnyts/openai/blob/main/R/utils-assertions.R
value_between <- function(x, lower, upper) {
x >= lower && x <= upper
}
assertthat::on_failure(value_between) <- function(call, env) {
paste0(
deparse(call$x),
" is not between ",
deparse(call$lower),
" and ",
deparse(call$upper)
)
}
is_false <- function(x) {
!x
}
assertthat::on_failure(is_false) <- function(call, env) {
paste0(deparse(call$x), " is not yet implemented.")
}
is_messages <- function(x) {
x_class <- class(x)[1]
if (x_class %in% "character") {
return(is.character(x) && length(x) == 1)
} else {
return(x_class %in% "messages")
}
}
assertthat::on_failure(is_messages) <- function(call, env) {
paste0(deparse(call$x), " is not a string (a length one character vector) or not a messages object.")
}
is_messages_object <- function(x) {
class(x)[1] %in% "messages"
}
assertthat::on_failure(is_messages_object) <- function(call, env) {
paste0(deparse(call$x), " is not a messages object.")
}
# modufy openai package
verify_mime_type <- function (result) {
if (httr::http_type(result) != "application/json") {
paste("OpenAI API probably has been changed. If you see this, please",
"rise an issue at: https://github.com/bit2r/bitGPT/issues") %>%
stop()
}
}