UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

33 lines • 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dotenv_1 = require("dotenv"); const openai_1 = require("./llms/openai"); const prompt_1 = require("./prompts/prompt"); const llm_1 = require("./chains/llm"); // Load environment variables (0, dotenv_1.config)(); async function main() { try { console.log('šŸš€ Starting Mini-LangChain Example...\n'); // Initialize OpenAI LLM const llm = new openai_1.OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: 'gpt-3.5-turbo', defaultTemperature: 0.7 }); // Create a simple prompt template const prompt = prompt_1.PromptTemplate.fromTemplate("What is a good name for a company that makes {product}?"); // Create an LLM chain const chain = new llm_1.LLMChain({ llm, prompt }); // Run the chain const result = await chain.call({ product: "colorful socks" }); console.log('šŸŽÆ Result:', result.text); console.log('\nāœ… Example completed successfully!'); } catch (error) { console.error('āŒ Error:', error); } } // Run the example main(); //# sourceMappingURL=example.js.map