diff --git a/.genio b/.genio index c79fcc3..29332b7 100644 Binary files a/.genio and b/.genio differ diff --git a/Conversation.cpp b/Conversation.cpp index 0906d6b..037b363 100644 --- a/Conversation.cpp +++ b/Conversation.cpp @@ -76,6 +76,10 @@ Conversation::FilterTextModels(const json &modelsJson) { } void Conversation::MessageReceived(BMessage *message) { + + try { + + switch (message->what) { //.. case B_HTTP_DATA_RECEIVED: { // break; @@ -222,6 +226,34 @@ void Conversation::MessageReceived(BMessage *message) { BHandler::MessageReceived(message); break; } + + } catch (const BPrivate::Network::BNetworkRequestError& e) { + + std::cout << "Caught a BNetworkRequestError: " << e.DebugMessage() << std::endl; + + BMessage msgr(kSendReply); + msgr.AddString("text", "Oops. Network error. Check internet connection."); + sendReply(msgr); + + + BMessage msg(kShowError); + msg.AddString("text", e.DebugMessage()); + sendReply(msg); + + + } catch (const std::exception& e) { + std::cout << "Caught a standard exception: " << e.what() << std::endl; + BMessage msg(kShowError); + msg.AddString("text", e.what()); + sendReply(msg); + + } catch (...) { + std::cout << "Caught an unknown exception!" << std::endl; + BMessage msg(kShowError); + msg.AddString("text", "unknown exception"); + sendReply(msg); + } + } std::string Conversation::buildBearerKey() { @@ -238,7 +270,7 @@ std::string Conversation::buildBearerKey() { void Conversation::loadModels() { - auto url = BUrl("https://api.openai.com/v1/models"); + auto url = BUrl("https://api.openai.com/v1/models", true); BHttpRequest request = BHttpRequest(url); request.SetMethod(BHttpMethod::Get); @@ -272,7 +304,7 @@ void Conversation::ask(const std::string &prompt) { if (_lastResult) _sharedSession.Cancel(_lastResult->Identity()); - auto url = BUrl("https://api.openai.com/v1/chat/completions"); + auto url = BUrl("https://api.openai.com/v1/chat/completions",true); BHttpRequest request = BHttpRequest(url); request.SetMethod(BHttpMethod::Post); // Allow up to 2 minute before timeout, it can be long depending on load or diff --git a/Conversation.h b/Conversation.h index 3993a13..bae0260 100644 --- a/Conversation.h +++ b/Conversation.h @@ -14,6 +14,8 @@ #include #include +static const uint32 kShowError = 'serr'; + diff --git a/DumBer b/DumBer index cadeb35..8c9f498 100755 Binary files a/DumBer and b/DumBer differ diff --git a/LICENSE b/LICENSE index 9bb0d38..c551424 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Santiago Lema +Copyright (c) 2024-2025 Santiago Lema Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/MainWindow.cpp b/MainWindow.cpp index dca23a8..638d79d 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -303,6 +303,20 @@ void MainWindow::MessageReceived(BMessage *message) { } break; + case kShowError: { + + printf("error received:"); + const char *text; + + if (message->FindString("text", &text) == B_OK) { + _infoView->SetText(BString("ERROR: ") << text); + printf("ERROR: %s\n", text); + } + + } break; + + + case kModelSelected: { printf("model selected"); diff --git a/MainWindow.h b/MainWindow.h index 79b8523..df3dec0 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -17,14 +17,12 @@ #include "Conversation.h" -static const uint32 kCheckKey = 'chkk'; -static const uint32 kMsgNewFile = 'fnew'; -static const uint32 kMsgOpenFile = 'fopn'; -static const uint32 kMsgSaveFile = 'fsav'; +static const uint32 kCheckKey = 'chkk'; +static const uint32 kMsgNewFile = 'fnew'; +static const uint32 kMsgOpenFile = 'fopn'; +static const uint32 kMsgSaveFile = 'fsav'; static const uint32 kModelSelected = 'msel'; -static const uint32 kViewJSON = 'vjso'; - - +static const uint32 kViewJSON = 'vjso'; static const uint32 kPulse = 'plse'; diff --git a/Resources.rdef b/Resources.rdef index e36654d..da2539e 100644 --- a/Resources.rdef +++ b/Resources.rdef @@ -5,7 +5,7 @@ resource app_flags B_SINGLE_LAUNCH; resource app_version { major = 1, middle = 0, - minor = 0, + minor = 1, /* 0 = development 1 = alpha 2 = beta 3 = gamma 4 = golden master 5 = final */