UNPKG

auto-gpt-ts

Version:

my take of Auto-GPT in typescript

122 lines 4.93 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AIConfig = void 0; const config_1 = require("./config"); const prompt_generator_1 = require("../prompt/prompt-generator"); const node_os_1 = require("node:os"); const fs = __importStar(require("fs")); const yaml = __importStar(require("js-yaml")); const os_name_1 = require("../os-name"); class AIConfig { constructor(aiName = "", aiRole = "", aiGoals = null, apiBudget = Infinity) { if (aiGoals === null) { aiGoals = []; } this.aiName = aiName; this.aiRole = aiRole; this.aiGoals = aiGoals; this.apiBudget = apiBudget; this.promptGenerator = null; this.commandRegistry = null; } static load(configFile = "../ai_settings.yaml") { /** * Returns class object with parameters (ai_name, ai_role, ai_goals, api_budget) loaded from * yaml file if yaml file exists, * else returns class with no parameters. */ var _a; let configParams; try { const file = fs.readFileSync(configFile, "utf-8"); configParams = yaml.load(file); } catch (err) { configParams = {}; } const aiName = configParams.aiName || ""; const aiRole = configParams.aiRole || ""; const aiGoals = ((_a = configParams.aiGoals) === null || _a === void 0 ? void 0 : _a.map((goal) => { if (typeof goal === "object") { goal = JSON.stringify(goal); } return goal; })) || []; const apiBudget = configParams.apiBudget || 0.0; return new AIConfig(aiName, aiRole, aiGoals, apiBudget); } save(configFile = "../ai_settings.yaml") { /** * Saves the class parameters to the specified file yaml file path as a yaml file. */ const fs = require("fs"); const yaml = require("js-yaml"); const config = { aiName: this.aiName, aiRole: this.aiRole, aiGoals: this.aiGoals, apiBudget: this.apiBudget, }; fs.writeFileSync(configFile, yaml.dump(config)); } constructFullPrompt(promptGenerator) { /** * Returns a prompt to the user with the class information in an organized fashion. */ let promptStart = ` Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications. `; const cfg = new config_1.Config(); if (!promptGenerator) { promptGenerator = (0, prompt_generator_1.buildDefaultPromptGenerator)(); } promptGenerator.goals = this.aiGoals; promptGenerator.name = this.aiName; promptGenerator.role = this.aiRole; promptGenerator.commandRegistry = this.commandRegistry; if (cfg.executeLocalCommands) { // add OS info to prompt const os_name = (0, node_os_1.platform)(); const os_info = (0, os_name_1.osName)(os_name); promptStart += `\nThe OS you are running on is: ${os_info}`; } let fullPrompt = `You are ${promptGenerator.name}, ${promptGenerator.role}\n${promptStart}GOALS:\n\n`; for (let i = 0; i < this.aiGoals.length; i++) { const goal = this.aiGoals[i]; fullPrompt += `${i + 1}. ${goal}\n`; } if (this.apiBudget > 0.0) { fullPrompt += `\nIt takes money to let you run. Your API budget is $${this.apiBudget.toFixed(3)}`; } this.promptGenerator = promptGenerator; fullPrompt += `\n\n${promptGenerator.generatePromptString().join('\n')}`; return fullPrompt; } } exports.AIConfig = AIConfig; //# sourceMappingURL=ai-config.js.map