LangChain Agent Example: Empower Your Applications with Intelligent Tools

Agents


import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, AIMessage } from "@langchain/core/messages";
import * as dotenv from "dotenv";
dotenv.config();

async function main() {
  const chatModel = new ChatOpenAI({
    modelName: "gpt-3.5-turbo",
    temperature: 0.7,
    openAIApiKey: process.env.OPENAI_API_KEY!,
  });

  const chatHistory = [
    new HumanMessage("What is LangChain?"),
    new AIMessage("LangChain is a framework for building applications powered by language models."),
    new HumanMessage("What are its key features?"),
  ];

  chatHistory.push(new HumanMessage("Can you provide an example of how to use it?"));

  const response = await chatModel.call(chatHistory);

  console.log("Chat History Example:");
  console.log("Response:", response.text || response);
}

main().catch(console.error);

Explore how to build intelligent agents using LangChain and OpenAI. This tutorial showcases a practical implementation of a LangChain Agent that integrates a custom calculator tool for performing arithmetic operations. Learn how to empower your applications with reactive and task-oriented capabilities, ideal for interactive and dynamic user experiences.

https://js.langchain.com/docs/

Conclusion

...

Under Construction
Under Construction