auto-gpt-ts
Version:
my take of Auto-GPT in typescript
120 lines • 6.11 kB
JavaScript
;
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;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAutoGpt = void 0;
const logging_1 = require("./logging");
const agent_1 = require("./agent/agent");
const config_1 = require("./config/config");
const configurator_1 = require("./configurator");
const prompt_generator_1 = require("./prompt/prompt-generator");
const chalk_1 = __importDefault(require("chalk"));
const Path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const workspace_1 = require("./workspace/workspace");
const command_1 = require("./commands/command");
const prompt_base_1 = require("./prompt/prompt-base");
const memory_1 = require("./memory");
const logger = (0, logging_1.getLogger)("run-auto-gpt");
function runAutoGpt(continuous, continuousLimit, aiSettings, skipReprompt, speak, debug, gpt3only, gpt4only, memoryType, browserName, allowDownloads, skipNews, workspaceDirectory) {
return __awaiter(this, void 0, void 0, function* () {
const cfg = new config_1.Config();
const commandRegistry = yield importCommands(cfg);
// TODO: fill in llm values here
(0, configurator_1.createConfig)(continuous, continuousLimit, aiSettings, skipReprompt, speak, debug, gpt3only, gpt4only, memoryType, browserName, allowDownloads, skipNews);
(0, config_1.checkOpenaiApiKey)();
if (!workspaceDirectory) {
workspaceDirectory = Path.resolve(__dirname, "..", "auto_gpt_workspace");
}
else {
workspaceDirectory = Path.resolve(workspaceDirectory);
}
if (!fs.existsSync(workspaceDirectory)) {
fs.mkdirSync(workspaceDirectory);
}
// TODO: pass in the ai_settings file and the env file and have them cloned into
// the workspace directory so we can bind them to the agent.
workspaceDirectory = workspace_1.Workspace.makeWorkspace(workspaceDirectory);
cfg.workspacePath = workspaceDirectory;
// HACK: doing this here to collect some globals that depend on the workspace.
const fileLoggerPath = Path.resolve(workspaceDirectory, "file_logger.txt");
if (!fs.existsSync(fileLoggerPath)) {
fs.writeFileSync(fileLoggerPath, "File Operation Logger ");
}
cfg.fileLoggerPath = fileLoggerPath;
// logger.debug(`config: `, cfg)
const aiName = "";
const aiConfig = yield (0, prompt_base_1.constructMainAiConfig)();
aiConfig.commandRegistry = commandRegistry;
// Initialize variables
const fullMessageHistory = [];
let nextActionCount = 0;
// Initialize memory and make sure it is empty.
// this is particularly important for indexing and referencing pinecone memory
const memory = (0, memory_1.getMemory)();
logger.info("Using memory of type: " + chalk_1.default.green(memory.constructor.name));
const systemPrompt = aiConfig.constructFullPrompt();
if (cfg.debugMode) {
logger.info("Prompt: " + chalk_1.default.green(systemPrompt));
}
const agent = new agent_1.Agent(aiName, memory, fullMessageHistory, nextActionCount, aiConfig, systemPrompt, prompt_generator_1.DEFAULT_TRIGGERING_PROMPT, workspaceDirectory);
yield agent.startInteractionLoop();
});
}
exports.runAutoGpt = runAutoGpt;
const importCommands = (cfg) => __awaiter(void 0, void 0, void 0, function* () {
const commandRegistry = new command_1.CommandRegistry();
const commandCategories = [
"./analyze-code",
// "./audio-text",
"./run-code",
"./file-operations",
"./git-operations",
"./google-search",
"./improve-code",
"./browse-web",
"./task-status",
"./opts",
];
logger.debug(`The following command categories are disabled: ${cfg.disabledCommandCategories}`);
const enabled_categories = commandCategories.filter((x) => !cfg.disabledCommandCategories.includes(x));
logger.debug(`The following command categories are enabled: ${enabled_categories}`);
for (const command_category of enabled_categories) {
yield commandRegistry.importCommands(command_category);
}
return commandRegistry;
});
//# sourceMappingURL=main.js.map