auto-gpt-ts
Version:
my take of Auto-GPT in typescript
158 lines (152 loc) • 8.8 kB
JavaScript
;
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.promptUser = void 0;
const chalk_1 = __importDefault(require("chalk"));
const utils_1 = require("./utils");
const ai_config_1 = require("./config/ai-config");
const llm_utils_1 = require("./llm/llm-utils");
const config_1 = require("./config/config");
const logging_1 = require("./logging");
const CFG = new config_1.Config();
const logger = (0, logging_1.getLogger)('Auto-GPT', 'Setup');
function promptUser() {
return __awaiter(this, void 0, void 0, function* () {
// Construct the prompt
logger.info('Welcome to Auto-GPT! ');
// Get user desire
logger.info('Create an AI-Assistant: ' + chalk_1.default.green('input \'--manual\' to enter manual mode.'));
let userDesire = yield (0, utils_1.cleanInput)(`${chalk_1.default.blue('I want Auto-GPT to')}: `);
if (userDesire === '') {
userDesire =
'Write a wikipedia style article about the project: https://github.com/significant-gravitas/Auto-GPT'; // Default prompt
}
// If user desire contains "--manual"
if (userDesire.includes('--manual')) {
logger.info(chalk_1.default.green('Manual Mode Selected'));
return generateAiConfigManual();
}
else {
try {
return yield generateAiConfigAutomatic(userDesire);
}
catch (error) {
logger.info('Unable to automatically generate AI Config based on user desire. ' +
chalk_1.default.red('Falling back to manual mode.'));
return generateAiConfigManual();
}
}
});
}
exports.promptUser = promptUser;
function generateAiConfigManual() {
return __awaiter(this, void 0, void 0, function* () {
// Manual Setup Intro
logger.info('Create an AI-Assistant: ' +
chalk_1.default.green('Enter the name of your AI and its role below. Entering nothing will load defaults.'));
// Get AI Name from User
logger.info('Name your AI: ' +
chalk_1.default.green("For example, 'Entrepreneur-GPT'"));
let aiName = yield (0, utils_1.cleanInput)('AI Name: ');
if (aiName === '') {
aiName = 'Entrepreneur-GPT';
}
logger.info(`${aiName} here! ` +
chalk_1.default.blue('I am at your service.'));
// Get AI Role from User
logger.info("Describe your AI's role: " +
chalk_1.default.green("For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'"));
let aiRole = yield (0, utils_1.cleanInput)(`${aiName} is: `);
if (aiRole === '') {
aiRole =
"an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.";
}
// Enter up to 5 goals for the AI
logger.info('Enter up to 5 goals for your AI: ' +
chalk_1.default.green("For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'"));
logger.info('Enter nothing to load defaults, enter nothing when finished.');
const aiGoals = [];
for (let i = 1; i <= 5; i++) {
const ai_goal = yield (0, utils_1.cleanInput)(`${chalk_1.default.blue(`Goal ${i}`)}: `);
if (ai_goal === '') {
break;
}
aiGoals.push(ai_goal);
}
if (aiGoals.length === 0) {
aiGoals.push('Increase net worth', 'Grow Twitter Account', 'Develop and manage multiple businesses autonomously');
}
// Get API Budget from User
logger.info('Enter your budget for API calls: ' +
chalk_1.default.green('For example: $1.50'));
logger.info('Enter nothing to let the AI run without monetary limit');
const apiBudgetInput = yield (0, utils_1.cleanInput)(`${chalk_1.default.blue('Budget')}: $`);
let api_budget = 0.0;
if (apiBudgetInput !== '') {
try {
api_budget = parseFloat(apiBudgetInput.replace('$', ''));
}
catch (error) {
logger.info('Invalid budget input. Setting budget to unlimited.');
}
}
return new ai_config_1.AIConfig(aiName, aiRole, aiGoals, api_budget);
});
}
function generateAiConfigAutomatic(userPrompt) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const systemPrompt = `
Your task is to devise up to 5 highly effective goals and an appropriate role-based name (_GPT) for an autonomous agent, ensuring that the goals are optimally aligned with the successful completion of its assigned task.
The user will provide the task, you will provide only the output in the exact format specified below with no explanation or conversation.
Example input:
Help me with marketing my business
Example output:
Name: CMOGPT
Description: a professional digital marketer AI that assists Solopreneurs in growing their businesses by providing world-class expertise in solving marketing problems for SaaS, content products, agencies, and more.
Goals:
- Engage in effective problem-solving, prioritization, planning, and supporting execution to address your marketing needs as your virtual Chief Marketing Officer.
- Provide specific, actionable, and concise advice to help you make informed decisions without the use of platitudes or overly wordy explanations.
- Identify and prioritize quick wins and cost-effective campaigns that maximize results with minimal time and budget investment.
- Proactively take the lead in guiding you and offering suggestions when faced with unclear information or uncertainty to ensure your marketing strategy remains on track.`;
// Call LLM with the string as user input
const messages = [
{
role: "system",
content: systemPrompt,
},
{
role: "user",
content: `Task: '${userPrompt}'
Respond only with the output in the exact format specified in the system prompt, with no explanation or conversation.\n`,
},
];
const output = yield (0, llm_utils_1.createChatCompletion)(messages, CFG.fastLlmModel);
// Debug LLM Output
logger.debug(`AI Config Generator Raw Output: ${output}`);
// Parse the output
const nameMatch = output.match(/Name(?:\s*):(?:\s*)(.*)/i);
const aiName = nameMatch ? nameMatch[1] : "CMOGPT";
const descriptionMatch = output.match(/Description(?:\s*):(?:\s*)(.*?)(?:(?:\n)|Goals)/is);
const aiRole = descriptionMatch ? descriptionMatch[1].trim() : "a professional digital marketer AI that assists Solopreneurs in growing their businesses by providing world-class expertise in solving marketing problems for SaaS, content products, agencies, and more.";
const aiGoals = (_a = output.match(/(?:\n)-\s*(.*)/g)) === null || _a === void 0 ? void 0 : _a.map(match => match.slice(3));
return new ai_config_1.AIConfig(aiName, aiRole, aiGoals || [
"Engage in effective problem-solving, prioritization, planning, and supporting execution to address your needs as your virtual assistant.",
"Provide specific, actionable, and concise advice to help you make informed decisions without the use of platitudes or overly wordy explanations.",
"Identify and prioritize quick wins and effective solutions that maximize results with minimal time and resources investment.",
"Proactively take the lead in guiding you and offering suggestions when faced with unclear information or uncertainty to ensure your tasks remain on track.",
]);
});
}
//# sourceMappingURL=setup.js.map