From af39ad70949534d8ea7ec39ed458509b328f4bef Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 9 Mar 2024 02:17:26 -0500 Subject: [PATCH] Restructure project --- package-lock.json => cli/package-lock.json | 6 +- package.json => cli/package.json | 0 kuzco-cli.js | 93 ---------------------- 3 files changed, 3 insertions(+), 96 deletions(-) rename package-lock.json => cli/package-lock.json (99%) rename package.json => cli/package.json (100%) delete mode 100644 kuzco-cli.js diff --git a/package-lock.json b/cli/package-lock.json similarity index 99% rename from package-lock.json rename to cli/package-lock.json index da2890a..fffee04 100644 --- a/package-lock.json +++ b/cli/package-lock.json @@ -1,11 +1,11 @@ { - "name": "kyzco-cli", + "name": "kuzco-cli", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "kyzco-cli", + "name": "kuzco-cli", "version": "1.0.0", "dependencies": { "got": "^14.2.1", @@ -13,7 +13,7 @@ "prompt-sync": "^4.2.0" }, "bin": { - "kyzco-cli": "kuzco-cli.js" + "kuzco-cli": "kuzco-cli.js" } }, "node_modules/@sindresorhus/is": { diff --git a/package.json b/cli/package.json similarity index 100% rename from package.json rename to cli/package.json diff --git a/kuzco-cli.js b/kuzco-cli.js deleted file mode 100644 index 6450e83..0000000 --- a/kuzco-cli.js +++ /dev/null @@ -1,93 +0,0 @@ -const readline = require('readline'); -const fetch = require('node-fetch'); - -const fs = require('fs'); -const path = require('path'); -const prompt = require('prompt-sync')({ sigint: true }); -const os = require('os'); - -const configDir = path.join(os.homedir(), '.kuzco-cli'); -const configFile = path.join(configDir, 'config.json'); - -const BASE_URL = 'https://relay.kuzco.xyz/v1'; - -let API_KEY = ''; - -try { - if (!fs.existsSync(configDir)) { - fs.mkdirSync(configDir); - } - - let foundAPIKey = false; - - if (fs.existsSync(configFile)) { - const config = JSON.parse(fs.readFileSync(configFile, 'utf8')); - if (config.API_KEY) { - API_KEY = config.API_KEY; - console.log("API key loaded from config file."); - foundAPIKey = true; - } - } - - if (!foundAPIKey) { - console.log('API key not found.'); - API_KEY = prompt('Please enter your API key: '); - - const config = { API_KEY }; - fs.writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8'); - console.log(`API key saved to ${configFile}`); - } -} catch (error) { - console.error(`An error occurred: ${error}`); -} - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -const askQuestion = (query) => { - return new Promise(resolve => rl.question(query, ans => { - resolve(ans); - })); -}; - -async function main() { - let messages = []; - - while (true) { - const user_input = await askQuestion("User: "); - if (user_input.toLowerCase() === 'exit') { - break; - } - messages.push({ 'role': 'user', 'content': user_input + '\n' }); - - try { - const response = await fetch(`${BASE_URL}/chat/completions`, { - method: 'POST', - headers: { - 'Authorization': `Bearer ${API_KEY}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - messages: messages, - model: 'mistral', - stream: false - }) - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const data = await response.json(); - console.log(`\nKuzco (Mistral):\n\n${data.choices[0].message.content.trim()}\n`); - } catch (error) { - console.error(`An error occurred: ${error.message}`); - } - } - - rl.close(); -} - -main().catch(console.error); \ No newline at end of file