Add function to alert user if their API key isnt set and open a popup for user to enter their key

This commit is contained in:
2024-03-09 02:42:30 -05:00
parent 61cf0bd49e
commit 97402a8b1f
5 changed files with 76 additions and 6 deletions

View File

@@ -12,21 +12,30 @@ async function fetchData(url, options = {}) {
class KuzcoCore {
constructor() {
this.configPath = path.join(os.homedir(), '.kuzco-cli', 'config.json');
this.API_KEY = this.loadApiKey();
}
loadApiKey() {
const configPath = path.join(os.homedir(), '.kuzco-cli', 'config.json');
try {
const configFile = fs.readFileSync(configPath);
const config = JSON.parse(configFile);
return config.API_KEY;
if (fs.existsSync(this.configPath)) {
const configFile = fs.readFileSync(this.configPath);
const config = JSON.parse(configFile);
return config.API_KEY;
} else {
console.log('API Key config file does not exist. Please set up your API Key.');
return '';
}
} catch (error) {
console.error(`An error occurred while reading the API key: ${error.message}`);
return '';
}
}
apiKeyExists() {
return fs.existsSync(this.configPath) && this.API_KEY !== '';
}
async sendPrompt(prompt) {
try {
const response = await fetch('https://relay.kuzco.xyz/v1/chat/completions', {