MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / start_up

Method start_up

runners/client/ClientRunningRequest.cpp:27–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace cocoon {
26
27void ClientRunningRequest::start_up() {
28 LOG(INFO) << "client request " << request_id_.to_hex() << ": starting";
29
30 std::string content_type;
31 for (auto &h : in_request_headers_) {
32 auto name_copy = h.first;
33 std::transform(name_copy.begin(), name_copy.end(), name_copy.begin(),
34 [](unsigned char c) { return std::tolower(c); });
35 if (name_copy == "content-type") {
36 content_type = h.second;
37 }
38 }
39
40 stats()->requests_received++;
41 stats()->request_bytes_received += (double)in_payload_.size();
42 std::string model = "test1";
43 td::int32 max_coefficient = 4000;
44 td::int64 max_tokens = 10000;
45 //max_tokens = 0;
46 //max_coefficient = 0;
47 double timeout = 120.0;
48
49 td::Bits256 encrypted_with = td::Bits256::zero();
50
51 auto S = [&]() -> td::Status {
52 TRY_RESULT(new_payload,
53 validate_client_request(in_request_path_, content_type, in_payload_, &model, &max_tokens,
54 &max_coefficient, &timeout, &enable_debug_, &ext_request_id_, &encrypted_with));
55 in_payload_ = std::move(new_payload);
56 return td::Status::OK();
57 }();
58
59 if (S.is_error()) {
60 return return_error(S.move_as_error_prefix("failed to parse request: "), nullptr);
61 }
62
63 encrypted_with_ = encrypted_with;
64
65 auto req = cocoon::cocoon_api::make_object<cocoon_api::http_request>(
66 "POST", in_request_path_, "HTTP/1.0", std::vector<ton::tl_object_ptr<cocoon_api::http_header>>(),
67 td::BufferSlice(in_payload_));
68 for (auto &h : in_request_headers_) {
69 req->headers_.push_back(cocoon::cocoon_api::make_object<cocoon_api::http_header>(h.first, h.second));
70 }
71 if (req->payload_.size()) {
72 req->headers_.push_back(
73 cocoon::cocoon_api::make_object<cocoon_api::http_header>("Content-Length", PSTRING() << req->payload_.size()));
74 }
75
76 auto request_data = cocoon::serialize_tl_object(req, true);
77
78 td::BufferSlice request_data_wrapped;
79 if (proto_version_ == 0) {
80 request_data_wrapped = cocoon::create_serialize_tl_object<cocoon_api::client_runQuery>(
81 model, std::move(request_data), max_coefficient, (int)max_tokens, timeout * 0.95, request_id_,
82 min_config_version_);
83 } else {
84 request_data_wrapped = cocoon::create_serialize_tl_object<cocoon_api::client_runQueryEx>(

Callers

nothing calls this directly

Calls 3

validate_client_requestFunction · 0.85
serialize_tl_objectFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected