21 std::string responseString;
23 curl_global_init(CURL_GLOBAL_ALL);
24 curl = curl_easy_init();
27 const char* url =
"http://localhost:8080/v1/chat/completions";
28 std::cout <<
"Sending request to: " << url << std::endl;
29 std::cout <<
"JSON data: " << jsonData << std::endl;
31 curl_easy_setopt(curl, CURLOPT_URL, url);
32 curl_easy_setopt(curl, CURLOPT_POST, 1);
33 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonData.c_str());
35 struct curl_slist *headers = NULL;
36 headers = curl_slist_append(headers,
"Content-Type: application/json");
37 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
40 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseString);
42 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
44 res = curl_easy_perform(curl);
46 if (res != CURLE_OK) {
47 std::cerr <<
"Error in the request: " << curl_easy_strerror(res) << std::endl;
51 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
52 std::cout <<
"HTTP response code: " << response_code << std::endl;
54 curl_easy_cleanup(curl);
55 curl_global_cleanup();
58 return responseString;