MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / to_response

Function to_response

examples/server_theme/then_upon.cpp:148–165  ·  view source on GitHub ↗

Convert the classification result into an HTTP response

Source from the content-addressed store, hash-verified

146
147// Convert the classification result into an HTTP response
148auto to_response(classification_result res) -> http_response
149{
150 if (res.type_ == obj_type::general_error)
151 // Send a 500 response back if we have a general error
152 return {.status_code_ = 500, .body_ = res.details_};
153 else if (res.type_ == obj_type::cancelled)
154 {
155 // Send a 503 response back if the computation is cancelled
156 return {.status_code_ = 503, .body_ = "cancelled"};
157 }
158 else
159 {
160 // Send a success response back, with the object type, accuracy and details
161 std::ostringstream oss;
162 oss << as_string(res.type_) << " (" << res.accuracy_ << ")\n" << res.details_;
163 return {.status_code_ = 200, .body_ = oss.str()};
164 }
165}
166
167// Handler for the "classify" request type
168auto handle_classify_request(http_request const & req) -> ex::sender auto

Callers

nothing calls this directly

Calls 1

as_stringFunction · 0.85

Tested by

no test coverage detected