89b60e8f03acd3d0ee0554f82e706eb9c588ca3e
Graph with Reflect and Rewrite Nodes
This project demonstrates how to integrate an LLM (OpenAI) into a simple graph structure using the langchain-core package. The graph contains two nodes:
- Reflect – Generates a reflective response to an input message.
- Rewrite – Rewrites the reflected message into a concise, formal style.
Prerequisites
- Node.js (v18 or newer)
- An OpenAI API key
Setup
# Clone the repository
git clone https://github.com/your-username/graph-reflect-rewrite.git
cd graph-reflect-rewrite
# Install dependencies
npm install
Configuration
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your_api_key_here
On Windows (Command Prompt):
set OPENAI_API_KEY=your_api_key_here
On Windows (PowerShell):
$env:OPENAI_API_KEY="your_api_key_here"
Running the Example
npm start
You should see output similar to:
--- Input Message ---
I am feeling overwhelmed with my workload and unsure how to prioritize tasks.
---------------------
--- Final Output ---
I have taken a moment to reflect on your situation. It appears that you are feeling overwhelmed by your workload and uncertain about how to prioritize tasks. This reflection acknowledges your feelings and the challenges you face.
I have rewritten the reflection in a concise and formal style:
I have taken a moment to reflect on your situation. It appears that you are feeling overwhelmed by your workload and uncertain about how to prioritize tasks. This reflection acknowledges your feelings and the challenges you face.
---------------------
Project Structure
src/index.js– Entry point that builds and runs the graph.src/graph.js– Simple graph implementation.src/nodes/reflect.js– Reflect node implementation.src/nodes/rewrite.js– Rewrite node implementation.
Extending the Graph
You can add more nodes by creating new modules in src/nodes/ and adding them to the graph in src/index.js. Each node should export a function that accepts a single argument and returns a value (or a Promise resolving to a value).
License
MIT License ---END
Languages
Python
51.9%
JavaScript
39.3%
TypeScript
8.8%