UNPKG

agentis

Version:

A TypeScript framework for building sophisticated multi-agent systems

44 lines (43 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VercelLLMTool = void 0; class VercelLLMTool { constructor(model = 'gpt-4', temperature = 0.7) { this.name = 'VercelLLMTool'; this.description = 'Advanced LLM tool using OpenAI API'; this.model = model; this.temperature = temperature; } async execute(input) { try { const response = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${process.env.OPENAI_API_KEY}`, }, body: JSON.stringify({ model: this.model, messages: [{ role: 'user', content: input }], temperature: this.temperature, }), }); if (!response.ok) { throw new Error(`OpenAI API error: ${response.statusText}`); } const data = await response.json(); return { result: data.choices[0]?.message?.content || '', raw: data }; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; return { result: null, error: errorMessage }; } } } exports.VercelLLMTool = VercelLLMTool;