* * 1. unpack request * 2. forward http request * 3. receive http answer * 4. start downloading http answer payload * */
| 57 | * |
| 58 | */ |
| 59 | void WorkerRunningRequest::start_request() { |
| 60 | LOG(INFO) << "worker request " << proxy_request_id_.to_hex() << ": received"; |
| 61 | stats()->requests_received++; |
| 62 | |
| 63 | auto R = cocoon::fetch_tl_object<cocoon_api::http_request>(std::move(data_), true); |
| 64 | if (R.is_error()) { |
| 65 | send_error(R.move_as_error_prefix("worker: invalid http request: ")); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | auto req = R.move_as_ok(); |
| 70 | |
| 71 | // we count only bytes in payload |
| 72 | stats()->request_bytes_received += (double)req->payload_.size(); |
| 73 | |
| 74 | static const std::string v_stream = "stream"; |
| 75 | static const std::string v_stream_options = "stream_options"; |
| 76 | static const std::string v_include_usage = "include_usage"; |
| 77 | |
| 78 | td::BufferSlice new_payload; |
| 79 | |
| 80 | std::unique_ptr<ton::http::HttpRequest> request; |
| 81 | http::HttpCallback::RequestType request_type; |
| 82 | std::string url; |
| 83 | std::vector<std::pair<std::string, std::string>> headers; |
| 84 | auto S = [&]() { |
| 85 | if (req->method_ == "POST" || req->method_ == "post" || req->payload_.size() > 0) { |
| 86 | request_type = http::HttpCallback::RequestType::Post; |
| 87 | } else { |
| 88 | request_type = http::HttpCallback::RequestType::Get; |
| 89 | } |
| 90 | |
| 91 | url = req->url_; |
| 92 | |
| 93 | std::string content_type; |
| 94 | for (auto &h : req->headers_) { |
| 95 | auto name_copy = h->name_; |
| 96 | std::transform(name_copy.begin(), name_copy.end(), name_copy.begin(), |
| 97 | [](unsigned char c) { return std::tolower(c); }); |
| 98 | if (name_copy == "content-type") { |
| 99 | content_type = h->value_; |
| 100 | } |
| 101 | if (name_copy == "content-length" || name_copy == "transfer-encoding" || name_copy == "connection") { |
| 102 | continue; |
| 103 | } |
| 104 | headers.emplace_back(h->name_, h->value_); |
| 105 | } |
| 106 | std::string model; |
| 107 | TRY_RESULT_ASSIGN(new_payload, validate_decrypt_request(req->url_, content_type, std::move(req->payload_), &model, |
| 108 | nullptr, worker_private_key_, &client_public_key_)); |
| 109 | if (model != model_base_name_) { |
| 110 | return td::Status::Error(ton::ErrorCode::protoviolation, "model name mismatch"); |
| 111 | } |
| 112 | postprocessor_ = std::make_unique<AnswerPostprocessor>( |
| 113 | coefficient_, runner_config_->root_contract_config->prompt_tokens_price_multiplier(), |
| 114 | runner_config_->root_contract_config->cached_tokens_price_multiplier(), |
| 115 | runner_config_->root_contract_config->completion_tokens_price_multiplier(), |
| 116 | runner_config_->root_contract_config->reasoning_tokens_price_multiplier(), |
nothing calls this directly
no test coverage detected