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.mov
- Node.js: The runtime environment for executing the JavaScript code.
- LangChain: A framework for developing applications powered by language models.
- @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.
- Chat Model: Uses Anthropic's Claude 3.5 Sonnet model for generating responses.
- Conversation Memory: Implements in-memory chat history to maintain context across interactions.
- Prompt Templates: Utilizes ChatPromptTemplate for structuring prompts with system messages and placeholders.
- Runnable Sequences: Implements a chain of operations using RunnableSequence for processing inputs and generating responses.
- Streaming Responses: Supports streaming of AI responses for real-time output.
- Clone the repository.
- Install dependencies with
npm install
. - Create a
.env
file with the following variable:ANTHROPIC_API_KEY
: Your Anthropic API key
Run the script with:
node index.js
The script demonstrates the chat bot's capabilities by:
- Initializing with a pre-defined conversation history.
- Asking a question that requires remembering previous information.
- Streaming the AI's response to the console.
- 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.