UNPKG

ggai

Version:

OpenAI LLM Agent Interface

45 lines (39 loc) 1.04 kB
const ask = require('./ask.js'); const chalk = require('chalk'); const { Agent } = require('./agent.js'); module.exports = async ({ model, temperature, systemPrompt, historyLimit, verbose = false, toolsPath = './tools.js' }) => { let config, tools; try { const data = require(toolsPath); config = data.config; tools = data.tools; if (!tools) throw new Error('exported tools not found'); if (!config) throw new Error('exported config not found'); } catch (err) { console.log('Invalid tools file: ' + err.message); process.exit(1); } const agent = new Agent({ model, temperature, systemPrompt, historyLimit, config, tools, verbose, streamingIndicators: true, }); while (true) { try { console.log(); const input = await ask('>>> '); console.log(); await agent.send(input); console.log(); } catch { console.log(); console.log(chalk.green(`Estimated cost: $${agent.cost.toFixed(5)}`)); process.exit(); } } };