handles missing api key

This commit is contained in:
Santiago Lema 2025-05-07 19:26:56 -03:00
parent 2489e46d23
commit 708eb51755
7 changed files with 85 additions and 13 deletions

View file

@ -6,6 +6,7 @@
#include <FindDirectory.h>
#include <Path.h>
#include <String.h>
#include <Alert.h>
#include <Url.h>
#include <MimeType.h>
@ -178,6 +179,9 @@ void Conversation::ask(const std::string& prompt) {
}
BString Conversation::ReadOpenAIKey() {
// /boot/home/config/openai_key
@ -187,13 +191,16 @@ BString Conversation::ReadOpenAIKey() {
if (find_directory(B_USER_SETTINGS_DIRECTORY, &configPath) != B_OK)
return "error: couldn't find config directory";
configPath.Append("openai_key");
configPath.Append("openai_keyxxx");
BFile file(configPath.Path(), B_READ_ONLY);
printf("full path:%s\n", configPath.Path());
if (file.InitCheck() != B_OK)
{
validKey=false;
return "error: couldn't open key file ";
}
off_t size;
file.GetSize(&size);
@ -204,6 +211,8 @@ BString Conversation::ReadOpenAIKey() {
BString result(buffer);
delete[] buffer;
validKey=true;
return result;
}