@@ -60,8 +60,7 @@ build_req <- function(model,
60
60
template = template ) | >
61
61
purrr :: compact() | > # remove NULL values
62
62
make_req(server = sample(server , 1 , prob = as_prob(names(server ))),
63
- endpoint = " /api/chat" ,
64
- perform = FALSE )
63
+ endpoint = " /api/chat" )
65
64
})
66
65
}) | >
67
66
unlist(recursive = FALSE )
@@ -70,21 +69,14 @@ build_req <- function(model,
70
69
}
71
70
72
71
73
- make_req <- function (req_data , server , endpoint , perform = TRUE ) {
72
+ make_req <- function (req_data , server , endpoint ) {
74
73
r <- httr2 :: request(server ) | >
75
74
httr2 :: req_url_path_append(endpoint ) | >
76
75
httr2 :: req_body_json(prep_req_data(req_data ), auto_unbox = FALSE ) | >
77
- # turn off errors since error messages can't be seen in sub-process
78
- httr2 :: req_error(is_error = function (resp ) FALSE ) | >
79
76
# see https://github.com/JBGruber/rollama/issues/23
80
77
httr2 :: req_options(timeout_ms = 1000 * 60 * 60 * 24 ,
81
78
connecttimeout_ms = 1000 * 60 * 60 * 24 ) | >
82
79
httr2 :: req_headers(!!! get_headers())
83
- if (perform ) {
84
- r <- r | >
85
- httr2 :: req_perform() | >
86
- httr2 :: resp_body_json()
87
- }
88
80
return (r )
89
81
}
90
82
@@ -117,17 +109,7 @@ perform_reqs <- function(reqs, verbose) {
117
109
if (length(fails ) == length(reqs )) {
118
110
cli :: cli_abort(fails )
119
111
} else if (length(fails ) < length(reqs ) && length(fails ) > 0 ) {
120
- error_counts <- table(fails )
121
- for (f in names(error_counts )) {
122
- if (error_counts [f ] > 2 ) {
123
- cli :: cli_alert_danger(" error ({error_counts[f]} times): {f}" )
124
- } else {
125
- cli :: cli_alert_danger(" error: {f}" )
126
- }
127
- }
128
- for (f in fails ) {
129
- cli :: cli_alert_danger(f )
130
- }
112
+ throw_error(fails )
131
113
}
132
114
133
115
httr2 :: resps_successes(resps )
@@ -143,15 +125,23 @@ perform_req <- function(reqs, verbose) {
143
125
id <- cli :: cli_progress_bar(format = " {cli::pb_spin} {model} {?is/are} thinking" ,
144
126
clear = TRUE )
145
127
128
+ # turn off errors since error messages can't be seen in sub-process
129
+ req <- httr2 :: req_error(reqs [[1 ]], is_error = function (resp ) FALSE )
130
+
146
131
rp <- callr :: r_bg(httr2 :: req_perform ,
147
- args = list (req = reqs [[ 1 ]] ),
132
+ args = list (req = req ),
148
133
package = TRUE )
149
134
150
135
while (rp $ is_alive()) {
151
136
cli :: cli_progress_update(id = id )
152
137
Sys.sleep(2 / 100 )
153
138
}
154
- return (list (rp $ get_result()))
139
+ resp <- rp $ get_result()
140
+ res <- httr2 :: resp_body_json(resp )
141
+ if (purrr :: pluck_exists(res , " error" )) {
142
+ cli :: cli_abort(purrr :: pluck(res , " error" ))
143
+ }
144
+ return (list (res ))
155
145
}
156
146
157
147
list (httr2 :: req_perform(reqs [[1 ]]))
@@ -207,7 +197,6 @@ pgrs <- function(resp) {
207
197
jsonlite :: stream_in(verbose = FALSE , simplifyVector = FALSE )
208
198
209
199
status <- setdiff(status , the $ str_prgs $ pb_done )
210
-
211
200
for (s in status ) {
212
201
status_message <- purrr :: pluck(s , " status" )
213
202
if (! purrr :: pluck_exists(s , " total" )) {
0 commit comments