Skip to content

Chat bot with conversation memory using Anthropic's Claude AI model on LangChain JS

Notifications You must be signed in to change notification settings

extrawest/anthropic-claude-chat-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anthropic Claude Chat Bot

This project implements a chat bot using Anthropic's Claude AI model, with conversation memory and streaming capabilities. It's built using Node.js and leverages the LangChain framework for AI interactions.

Demo

demo.mov

Technologies and Frameworks Used

  • Node.js: The runtime environment for executing the JavaScript code.
  • LangChain: A framework for developing applications powered by language models.

Libraries and Packages

  • @langchain/anthropic: For interacting with Anthropic's Claude AI model.
  • @langchain/core: Core LangChain functionalities for prompts, messages, and chat history.
  • dotenv: For loading environment variables.

Key Concepts and Features

  1. Chat Model: Uses Anthropic's Claude 3.5 Sonnet model for generating responses.
  2. Conversation Memory: Implements in-memory chat history to maintain context across interactions.
  3. Prompt Templates: Utilizes ChatPromptTemplate for structuring prompts with system messages and placeholders.
  4. Runnable Sequences: Implements a chain of operations using RunnableSequence for processing inputs and generating responses.
  5. Streaming Responses: Supports streaming of AI responses for real-time output.

Setup and Configuration

  1. Clone the repository.
  2. Install dependencies with npm install.
  3. Create a .env file with the following variable:
    • ANTHROPIC_API_KEY: Your Anthropic API key

Usage

Run the script with:

node index.js

The script demonstrates the chat bot's capabilities by:

  1. Initializing with a pre-defined conversation history.
  2. Asking a question that requires remembering previous information.
  3. Streaming the AI's response to the console.

Customization

  • Modify the messages array to change the initial conversation history.
  • Adjust the prompt template to alter the system message or structure of the prompts.
  • Change the model configuration in the ChatAnthropic constructor to use different Claude models or parameters.

About

Chat bot with conversation memory using Anthropic's Claude AI model on LangChain JS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published