UNPKG

ggai

Version:

OpenAI LLM Agent Interface

66 lines (62 loc) 2.41 kB
#!/usr/bin/env node const { Command } = require('commander'); const main = require('./main.js'); const chalk = require('chalk'); const fs = require('fs'); const path = require('path'); const { pricing } = require('./pricing.js'); const models = Object.keys(pricing) const program = new Command(); program .option('-m, --model <model>', 'specify the model', (value) => { if (models.indexOf(value) == -1) { console.log(chalk(`Unkown model specified: ${value}. Use at your own risk`)); } return value; }, models[0]) .option('-t, --temperature <temp>', 'specify the temperature', (value) => { const temp = parseFloat(value); if (isNaN(temp) || temp < 0 || temp > 2) { console.log('Invalid temperature specified. It should be a float between 0 and 2.'); process.exit(); } return temp; }, 0.1) .option('-s, --system-prompt <prompt>', 'a message to be included for system guidance', (value) => { if (typeof value !== 'string') { console.error('Invalid system prompt. It should be a string.'); process.exit(1); } return value; }) .option('-hl, --history-limit <limit>', 'specify the max number of message history to include in requests', (value) => { if (typeof value !== 'string') { console.error('Invalid system prompt. It should be a string.'); process.exit(1); } return value; }) .option('-tp, --tools-path <path>', 'path to a custom tools file', (value) => { if (typeof value !== 'string') { console.error('Invalid tools path. It should be a string.'); process.exit(1); } return value; }) .option('-e, --example-tools', 'display an example tools file', () => { const toolsFile = fs.readFileSync(path.join(__dirname, 'tools.js'), 'utf-8'); console.log(chalk.cyan(toolsFile)); process.exit(); }) .option('-v, --verbose', 'display tool calls and results', () => { return true; }) .action((options) => { const banner = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf-8'); const packageText = fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'); const version = JSON.parse(packageText).version; console.log(chalk.cyan(banner.replace('v0.0.0', chalk.red(`v${version}`)))); console.log(`Model: ${chalk.blue(options.model)}, Temperature: ${chalk.blue(options.temperature)}`); main(options); }); program.parse();