common, server : use the same User-Agent by default (#18957)
This commit also ensures that if a custom User-Agent is used, it will be the only one sent. Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
@@ -57,6 +57,8 @@ extern const char * LLAMA_COMMIT;
|
|||||||
extern const char * LLAMA_COMPILER;
|
extern const char * LLAMA_COMPILER;
|
||||||
extern const char * LLAMA_BUILD_TARGET;
|
extern const char * LLAMA_BUILD_TARGET;
|
||||||
|
|
||||||
|
const static std::string build_info("b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT);
|
||||||
|
|
||||||
struct common_control_vector_load_info;
|
struct common_control_vector_load_info;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
+15
-10
@@ -323,14 +323,17 @@ static int common_download_file_single_online(const std::string & url,
|
|||||||
|
|
||||||
auto [cli, parts] = common_http_client(url);
|
auto [cli, parts] = common_http_client(url);
|
||||||
|
|
||||||
httplib::Headers default_headers = {{"User-Agent", "llama-cpp"}};
|
httplib::Headers headers;
|
||||||
if (!bearer_token.empty()) {
|
|
||||||
default_headers.insert({"Authorization", "Bearer " + bearer_token});
|
|
||||||
}
|
|
||||||
for (const auto & h : custom_headers) {
|
for (const auto & h : custom_headers) {
|
||||||
default_headers.emplace(h.first, h.second);
|
headers.emplace(h.first, h.second);
|
||||||
}
|
}
|
||||||
cli.set_default_headers(default_headers);
|
if (headers.find("User-Agent") == headers.end()) {
|
||||||
|
headers.emplace("User-Agent", "llama-cpp/" + build_info);
|
||||||
|
}
|
||||||
|
if (!bearer_token.empty()) {
|
||||||
|
headers.emplace("Authorization", "Bearer " + bearer_token);
|
||||||
|
}
|
||||||
|
cli.set_default_headers(headers);
|
||||||
|
|
||||||
const bool file_exists = std::filesystem::exists(path);
|
const bool file_exists = std::filesystem::exists(path);
|
||||||
|
|
||||||
@@ -437,10 +440,12 @@ std::pair<long, std::vector<char>> common_remote_get_content(const std::string
|
|||||||
const common_remote_params & params) {
|
const common_remote_params & params) {
|
||||||
auto [cli, parts] = common_http_client(url);
|
auto [cli, parts] = common_http_client(url);
|
||||||
|
|
||||||
httplib::Headers headers = {{"User-Agent", "llama-cpp"}};
|
httplib::Headers headers;
|
||||||
|
for (const auto & h : params.headers) {
|
||||||
for (const auto & header : params.headers) {
|
headers.emplace(h.first, h.second);
|
||||||
headers.emplace(header.first, header.second);
|
}
|
||||||
|
if (headers.find("User-Agent") == headers.end()) {
|
||||||
|
headers.emplace("User-Agent", "llama-cpp/" + build_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.timeout > 0) {
|
if (params.timeout > 0) {
|
||||||
|
|||||||
@@ -779,7 +779,6 @@ static void handle_media(
|
|||||||
// download remote image
|
// download remote image
|
||||||
// TODO @ngxson : maybe make these params configurable
|
// TODO @ngxson : maybe make these params configurable
|
||||||
common_remote_params params;
|
common_remote_params params;
|
||||||
params.headers.push_back({"User-Agent", "llama.cpp/" + build_info});
|
|
||||||
params.max_size = 1024 * 1024 * 10; // 10MB
|
params.max_size = 1024 * 1024 * 10; // 10MB
|
||||||
params.timeout = 10; // seconds
|
params.timeout = 10; // seconds
|
||||||
SRV_INF("downloading image from '%s'\n", url.c_str());
|
SRV_INF("downloading image from '%s'\n", url.c_str());
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
const static std::string build_info("b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT);
|
|
||||||
|
|
||||||
using json = nlohmann::ordered_json;
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
#define SLT_INF(slot, fmt, ...) LOG_INF("slot %12.*s: id %2d | task %d | " fmt, 12, __func__, (slot).id, ((slot).task ? (slot).task->id : -1), __VA_ARGS__)
|
#define SLT_INF(slot, fmt, ...) LOG_INF("slot %12.*s: id %2d | task %d | " fmt, 12, __func__, (slot).id, ((slot).task ? (slot).task->id : -1), __VA_ARGS__)
|
||||||
|
|||||||
Reference in New Issue
Block a user