handles requires BURL parameter and shows an error in case of network failure
This commit is contained in:
parent
1d5eace40a
commit
fdaad4ed8b
8 changed files with 57 additions and 11 deletions
BIN
.genio
BIN
.genio
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <string>
|
||||
#include <regex>
|
||||
|
||||
static const uint32 kShowError = 'serr';
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
BIN
DumBer
BIN
DumBer
Binary file not shown.
2
LICENSE
2
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:
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
12
MainWindow.h
12
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';
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue