Skip to content

Commit a7ced3e

Browse files
committed
final
1 parent 1bef809 commit a7ced3e

File tree

2 files changed

+16
-54
lines changed

2 files changed

+16
-54
lines changed

src/image_gen/http_image_gen_calculator.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,11 @@
3030

3131
#include "pipelines.hpp"
3232

33-
static void save_png_to_disk(const std::string& png_data, const std::string& filename) {
34-
std::ofstream out_file(filename, std::ios::binary);
35-
if (!out_file) {
36-
throw std::runtime_error("Failed to open file for writing: " + filename);
37-
}
38-
39-
out_file.write(png_data.data(), png_data.size());
40-
41-
if (!out_file.good()) {
42-
out_file.close();
43-
std::remove(filename.c_str()); // Clean up partial file
44-
throw std::runtime_error("Failed to write data to file: " + filename);
45-
}
46-
47-
out_file.close();
48-
}
33+
#pragma warning(push)
34+
#pragma warning(disable : 6001 4324 6385 6386)
35+
#include "absl/strings/escaping.h"
36+
#include "absl/strings/str_cat.h"
37+
#pragma warning(pop)
4938

5039
using namespace ovms;
5140

@@ -115,7 +104,17 @@ class ImageGenCalculator : public CalculatorBase {
115104
ov::genai::num_images_per_prompt(1)}); // todo: get from req
116105

117106
std::string res = save_image_stbi(image);
118-
save_png_to_disk(res, "output.png");
107+
108+
// Convert the image to a base64 string
109+
std::string base64_image;
110+
absl::Base64Escape(res, &base64_image);
111+
112+
// Create the JSON response
113+
std::string json_response = absl::StrCat("{\"data\":[{\"b64_json\":\"", base64_image, "\"}]}");
114+
// Produce std::string packet
115+
auto output = absl::make_unique<std::string>(json_response);
116+
cc->Outputs().Tag(OUTPUT_TAG_NAME).Add(output.release(), cc->InputTimestamp());
117+
119118
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "ImageGenCalculator [Node: {}] Process end", cc->NodeName());
120119
return absl::OkStatus();
121120
}

src/llm/apis/openai_completions.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -89,43 +89,6 @@ absl::Status OpenAIChatCompletionsHandler::parseCompletionsPart() {
8989
return absl::OkStatus();
9090
}
9191

92-
// ov::Tensor load_image_stbi(const std::string& imageBytes) {
93-
// int x = 0, y = 0, channelsInFile = 0;
94-
// constexpr int desiredChannels = 3;
95-
// unsigned char* image = stbi_load_from_memory(
96-
// (const unsigned char*)imageBytes.data(), imageBytes.size(),
97-
// &x, &y, &channelsInFile, desiredChannels);
98-
// if (!image) {
99-
// std::stringstream errorMessage;
100-
// errorMessage << "Failed to load the image";
101-
// throw std::runtime_error{errorMessage.str()};
102-
// }
103-
// struct SharedImageAllocator {
104-
// unsigned char* image;
105-
// int channels, height, width;
106-
// void* allocate(size_t bytes, size_t) const {
107-
// if (image && channels * height * width == bytes) {
108-
// return image;
109-
// }
110-
// throw std::runtime_error{"Unexpected number of bytes was requested to allocate."};
111-
// }
112-
// void deallocate(void*, size_t bytes, size_t) {
113-
// if (channels * height * width != bytes) {
114-
// throw std::runtime_error{"Unexpected number of bytes was requested to deallocate."};
115-
// }
116-
// if (image != nullptr) {
117-
// stbi_image_free(image);
118-
// image = nullptr;
119-
// }
120-
// }
121-
// bool is_equal(const SharedImageAllocator& other) const noexcept { return this == &other; }
122-
// };
123-
// return ov::Tensor(
124-
// ov::element::u8,
125-
// ov::Shape{1, size_t(y), size_t(x), size_t(desiredChannels)},
126-
// SharedImageAllocator{image, desiredChannels, y, x});
127-
// }
128-
12992
absl::Status OpenAIChatCompletionsHandler::parseMessages() {
13093
auto it = doc.FindMember("messages");
13194
if (it == doc.MemberEnd())

0 commit comments

Comments
 (0)