Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 119cd81

Browse files
committed
fix: Remove support for remote URL
1 parent 2140754 commit 119cd81

File tree

3 files changed

+11
-62
lines changed

3 files changed

+11
-62
lines changed

controllers/llamaCPP.cc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,38 +240,32 @@ void llamaCPP::chatCompletion(
240240
role = user_prompt;
241241

242242
json content_piece_image_data;
243+
content_piece_image_data["data"] = "";
243244

244245
auto content_piece_type = content_piece["type"].asString();
245246
if (content_piece_type == "text") {
246247
auto text = content_piece["text"].asString();
247248
formatted_output += text;
248249
} else if (content_piece_type == "image_url") {
249250
auto image_url = content_piece["image_url"]["url"].asString();
250-
std::string
251-
base64_image_data; // Declare the variable 'base64_image_data'
251+
std::string base64_image_data;
252252
if (image_url.find("http") != std::string::npos) {
253-
// If image url is a remote link, extract and use convert to
254-
// base64
255-
nitro_utils::processRemoteImage(
256-
image_url, [](const std::string &base64Image) {
257-
auto base64_image_data = base64Image;
258-
LOG_INFO << base64_image_data;
259-
});
253+
LOG_INFO << "Remote image detected but not supported yet";
260254
} else if (image_url.find("data:image") != std::string::npos) {
261-
// If image url is already in base64, use it directly
262-
auto base64_image_data = nitro_utils::extractBase64(image_url);
255+
LOG_INFO << "Base64 image detected";
256+
base64_image_data = nitro_utils::extractBase64(image_url);
263257
LOG_INFO << base64_image_data;
264258
} else {
265-
// If image url is a local file, convert to base64
259+
LOG_INFO << "Local image detected";
266260
nitro_utils::processLocalImage(
267-
image_url, [](const std::string &base64Image) {
268-
auto base64_image_data = base64Image;
269-
LOG_INFO << base64_image_data;
261+
image_url, [&](const std::string &base64Image) {
262+
base64_image_data = base64Image;
270263
});
264+
LOG_INFO << base64_image_data;
271265
}
266+
content_piece_image_data["data"] = base64_image_data;
272267

273268
formatted_output += "[img-" + std::to_string(no_images) + "]";
274-
content_piece_image_data["data"] = base64_image_data;
275269
content_piece_image_data["id"] = no_images;
276270
data["image_data"].push_back(content_piece_image_data);
277271
no_images++;

llama.cpp

utils/nitro_utils.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -108,51 +108,6 @@ inline std::string generateUniqueFilename(const std::string &prefix,
108108
return ss.str();
109109
}
110110

111-
// Function to download an image
112-
inline void downloadImage(const std::string &url, const std::string &savePath,
113-
std::function<void(bool)> callback) {
114-
auto client = drogon::HttpClient::newHttpClient(url);
115-
client->sendRequest(
116-
drogon::HttpRequest::newHttpRequest(),
117-
[savePath, callback](drogon::ReqResult result,
118-
const drogon::HttpResponsePtr &response) {
119-
if (result == drogon::ReqResult::Ok) {
120-
// Save the image to the specified path
121-
std::ofstream outFile(savePath, std::ios::binary);
122-
outFile.write(response->body().data(), response->body().size());
123-
outFile.close();
124-
125-
// Invoke the callback with true to indicate success
126-
callback(true);
127-
} else {
128-
std::cerr << "Failed to download the image: " << result << std::endl;
129-
// Invoke the callback with false to indicate failure
130-
callback(false);
131-
}
132-
});
133-
}
134-
135-
inline void
136-
processRemoteImage(const std::string &url,
137-
std::function<void(const std::string &)> callback) {
138-
std::string localPath =
139-
generateUniqueFilename("temp_", ".jpg"); // Generate a unique filename
140-
141-
downloadImage(url, localPath, [localPath, callback](bool success) {
142-
if (success) {
143-
try {
144-
std::string base64Image = imageToBase64(localPath);
145-
std::remove(localPath.c_str()); // Delete the local file
146-
callback(base64Image); // Invoke the callback with the Base64 string
147-
} catch (const std::exception &e) {
148-
std::cerr << "Error during processing: " << e.what() << std::endl;
149-
}
150-
} else {
151-
std::cerr << "Failed to download the image." << std::endl;
152-
}
153-
});
154-
}
155-
156111
inline void
157112
processLocalImage(const std::string &localPath,
158113
std::function<void(const std::string &)> callback) {

0 commit comments

Comments
 (0)