Skip to content

Commit

Permalink
revert chat sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-esir committed Nov 28, 2024
1 parent dd69db2 commit 413c015
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions samples/cpp/chat_sample/chat_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#include "openvino/genai/llm_pipeline.hpp"
#include <regex>
#include <fstream>

int main(int argc, char* argv[]) try {
if (2 != argc) {
Expand All @@ -12,37 +10,9 @@ int main(int argc, char* argv[]) try {
std::string prompt;
std::string models_path = argv[1];

std::string model_path = models_path + "/openvino_model.xml";
std::string weights_path = std::regex_replace(model_path, std::regex(".xml"), ".bin");
std::ifstream model_file(model_path, std::ios::binary | std::ios::ate);
std::ifstream weights_file(weights_path, std::ios::binary | std::ios::ate);

if (!model_file.is_open() || !weights_file.is_open()) {
throw std::runtime_error("Cannot open model or weights file");
}

std::streamsize model_size = model_file.tellg();
std::streamsize weights_size = weights_file.tellg();

model_file.seekg(0, std::ios::beg);
weights_file.seekg(0, std::ios::beg);

std::vector<char> model_buffer(model_size);
std::vector<char> weights_buffer(weights_size);

if (!model_file.read(model_buffer.data(), model_size) || !weights_file.read(weights_buffer.data(), weights_size)) {
throw std::runtime_error("Error reading model or weights file");
}
std::vector<uint8_t> model_uint8_buffer(model_buffer.begin(), model_buffer.end());
std::vector<uint8_t> weights_uint8_buffer(weights_buffer.begin(), weights_buffer.end());


std::string device = "CPU"; // GPU, NPU can be used as well
// ov::genai::LLMPipeline pipe(models_path, device);
ov::genai::LLMPipeline pipe(models_path, device);

ov::genai::Tokenizer tok(models_path);
ov::genai::LLMPipeline pipe(model_uint8_buffer, weights_uint8_buffer, tok, device);

ov::genai::GenerationConfig config;
config.max_new_tokens = 100;
std::function<bool(std::string)> streamer = [](std::string word) {
Expand Down

0 comments on commit 413c015

Please sign in to comment.