Skip to content

Commit 1b83e43

Browse files
committed
add optional headers (#7)
1 parent d658674 commit 1b83e43

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

R/utils.r

+23-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ make_req <- function(req_data, server, endpoint, perform = TRUE) {
8787
httr2::req_url_path_append(endpoint) |>
8888
httr2::req_body_json(prep_req_data(req_data), auto_unbox = FALSE) |>
8989
# turn off errors since error messages can't be seen in sub-process
90-
httr2::req_error(is_error = function(resp) FALSE)
90+
httr2::req_error(is_error = function(resp) FALSE) |>
91+
httr2::req_headers(!!!get_headers())
9192
if (perform) {
9293
r <- r |>
9394
httr2::req_perform() |>
@@ -97,6 +98,27 @@ make_req <- function(req_data, server, endpoint, perform = TRUE) {
9798
}
9899

99100

101+
get_headers <- function() {
102+
agent <- the$agent
103+
if (is.null(agent)) {
104+
sess <- sessionInfo()
105+
the$agent <- agent <- paste0(
106+
"rollama/", packageVersion("rollama"),
107+
"(", sess$platform, ") ",
108+
sess$R.version$version.string
109+
)
110+
}
111+
list(
112+
"Content-Type" = "application/json",
113+
"Accept" = "application/json",
114+
"User-Agent" = agent,
115+
# get additional headers from option (if set)
116+
getOption("rollama_headers")
117+
) |>
118+
unlist()
119+
}
120+
121+
100122
screen_answer <- function(x, model = NULL) {
101123
pars <- unlist(strsplit(x, "\n", fixed = TRUE))
102124
cli::cli_h1("Answer from {cli::style_bold({model})}")

0 commit comments

Comments
 (0)