UNPKG

ggai

Version:

OpenAI LLM Agent Interface

54 lines (47 loc) 1.03 kB
const { Agent, ask } = require('./agent'); (async () => { const config = [ { type: 'function', function: { name: 'log', description: 'Log something to console.', parameters: { type: 'object', properties: { text: { type: 'string', description: 'The text to log', }, }, required: ['text'], }, }, }, ]; const tools = { log: async ({ text }) => { console.log(`Logging from tool: ${text}`); return true; }, }; const systemPrompt = "You are a helpful assistant"; const agent = new Agent({ verbose: true, streamingIndicators: true, config, tools, systemPrompt, }); while (true) { try { const question = await ask('>>>'); await agent.send(question); console.log(); } catch (err) { console.log(); console.log(`Estimated cost: $${agent.cost.toFixed(5)}`); process.exit(); } } })();