mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
33 lines
906 B
JavaScript
33 lines
906 B
JavaScript
|
|
require('dotenv').config();
|
||
|
|
const { Calculator } = require('langchain/tools/calculator');
|
||
|
|
const { SerpAPI } = require('langchain/tools');
|
||
|
|
const { ChatOpenAI } = require('langchain/chat_models/openai');
|
||
|
|
const { PlanAndExecuteAgentExecutor } = require('langchain/experimental/plan_and_execute');
|
||
|
|
|
||
|
|
const tools = [
|
||
|
|
new Calculator(),
|
||
|
|
new SerpAPI(process.env.SERPAPI_API_KEY || '', {
|
||
|
|
location: 'Austin,Texas,United States',
|
||
|
|
hl: 'en',
|
||
|
|
gl: 'us'
|
||
|
|
})
|
||
|
|
];
|
||
|
|
const model = new ChatOpenAI({
|
||
|
|
temperature: 0,
|
||
|
|
modelName: 'gpt-3.5-turbo',
|
||
|
|
verbose: true,
|
||
|
|
openAIApiKey: process.env.OPENAI_API_KEY
|
||
|
|
});
|
||
|
|
const executor = PlanAndExecuteAgentExecutor.fromLLMAndTools({
|
||
|
|
llm: model,
|
||
|
|
tools
|
||
|
|
});
|
||
|
|
|
||
|
|
(async () => {
|
||
|
|
const result = await executor.call({
|
||
|
|
input: `Who is the current president of the United States? What is their current age raised to the second power?`
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log({ result });
|
||
|
|
})();
|