44#include " common/event.h"
55#include " indicators/dynamic_progress.hpp"
66#include " indicators/progress_bar.hpp"
7+ #include " utils/engine_constants.h"
78#include " utils/format_utils.h"
89#include " utils/json_helper.h"
910#include " utils/logging_utils.h"
1011
12+ namespace {
13+ std::string Repo2Engine (const std::string& r) {
14+ if (r == kLlamaRepo ) {
15+ return kLlamaEngine ;
16+ } else if (r == kOnnxRepo ) {
17+ return kOnnxEngine ;
18+ } else if (r == kTrtLlmRepo ) {
19+ return kTrtLlmEngine ;
20+ }
21+ return r;
22+ };
23+ } // namespace
1124bool DownloadProgress::Connect (const std::string& host, int port) {
1225 if (ws_) {
1326 CTL_INF (" Already connected!" );
@@ -21,7 +34,7 @@ bool DownloadProgress::Connect(const std::string& host, int port) {
2134 return true ;
2235}
2336
24- bool DownloadProgress::Handle (const std::string& id ) {
37+ bool DownloadProgress::Handle (const DownloadType& event_type ) {
2538 assert (!!ws_);
2639 std::unordered_map<std::string, uint64_t > totals;
2740 status_ = DownloadStatus::DownloadStarted;
@@ -30,7 +43,7 @@ bool DownloadProgress::Handle(const std::string& id) {
3043 std::vector<std::unique_ptr<indicators::ProgressBar>> items;
3144 indicators::show_console_cursor (false );
3245 auto handle_message = [this , &bars, &items, &totals,
33- id ](const std::string& message) {
46+ event_type ](const std::string& message) {
3447 CTL_INF (message);
3548
3649 auto pad_string = [](const std::string& str,
@@ -50,8 +63,8 @@ bool DownloadProgress::Handle(const std::string& id) {
5063
5164 auto ev = cortex::event::GetDownloadEventFromJson (
5265 json_helper::ParseJsonString (message));
53- // Ignore other task ids
54- if (ev.download_task_ .id != id ) {
66+ // Ignore other task type
67+ if (ev.download_task_ .type != event_type ) {
5568 return ;
5669 }
5770
@@ -63,7 +76,7 @@ bool DownloadProgress::Handle(const std::string& id) {
6376 indicators::option::BarWidth{50 }, indicators::option::Start{" [" },
6477 indicators::option::Fill{" =" }, indicators::option::Lead{" >" },
6578 indicators::option::End{" ]" },
66- indicators::option::PrefixText{pad_string (i.id )},
79+ indicators::option::PrefixText{pad_string (Repo2Engine ( i.id ) )},
6780 indicators::option::ForegroundColor{indicators::Color::white},
6881 indicators::option::ShowRemainingTime{true }));
6982 bars->push_back (*(items.back ()));
@@ -80,7 +93,7 @@ bool DownloadProgress::Handle(const std::string& id) {
8093 if (ev.type_ == DownloadStatus::DownloadStarted ||
8194 ev.type_ == DownloadStatus::DownloadUpdated) {
8295 (*bars)[i].set_option (indicators::option::PrefixText{
83- pad_string (it.id ) +
96+ pad_string (Repo2Engine ( it.id ) ) +
8497 std::to_string (
8598 int (static_cast <double >(downloaded) / totals[it.id ] * 100 )) +
8699 ' %' });
@@ -94,8 +107,8 @@ bool DownloadProgress::Handle(const std::string& id) {
94107 auto total_str = format_utils::BytesToHumanReadable (totals[it.id ]);
95108 (*bars)[i].set_option (
96109 indicators::option::PostfixText{total_str + " /" + total_str});
97- (*bars)[i].set_option (
98- indicators::option::PrefixText{ pad_string (it.id ) + " 100%" });
110+ (*bars)[i].set_option (indicators::option::PrefixText{
111+ pad_string (Repo2Engine ( it.id ) ) + " 100%" });
99112 (*bars)[i].set_progress (100 );
100113
101114 CTL_INF (" Download success" );
0 commit comments