MCPcopy Create free account
hub / github.com/ClickHouse/ai-sdk-cpp / post

Method post

src/http/http_request_handler.cpp:45–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45GenerateResult HttpRequestHandler::post(const std::string& path,
46 const httplib::Headers& headers,
47 const std::string& body,
48 const std::string& content_type) {
49 // Create a retry policy with the configured settings
50 retry::RetryPolicy retry_policy(config_.retry_config);
51
52 // Define the function to execute with retry
53 auto execute_request = [this, &path, &headers, &body,
54 &content_type]() -> GenerateResult {
55 return execute_single_request(path, headers, body, content_type);
56 };
57
58 // Define the function to check if a result is retryable
59 std::function<bool(const GenerateResult&)> is_retryable =
60 [](const GenerateResult& result) -> bool {
61 return result.is_retryable.value_or(false);
62 };
63
64 try {
65 return retry_policy.execute_with_retry(execute_request, is_retryable);
66 } catch (const retry::RetryError& e) {
67 ai::logger::log_error("Request failed after retries: {}", e.what());
68 GenerateResult error_result(e.what());
69 error_result.is_retryable = false; // Already retried
70 return error_result;
71 }
72}
73
74GenerateResult HttpRequestHandler::execute_single_request(
75 const std::string& path,

Callers 2

embeddingsMethod · 0.80

Calls 2

log_errorFunction · 0.85
execute_with_retryMethod · 0.80

Tested by

no test coverage detected