# 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: 1. **Reflect** – Generates a reflective response to an input message. 2. **Rewrite** – Rewrites the reflected message into a concise, formal style. ## Prerequisites - Node.js (v18 or newer) - An OpenAI API key ## Setup ```bash # 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: ```bash export OPENAI_API_KEY=your_api_key_here ``` On Windows (Command Prompt): ```cmd set OPENAI_API_KEY=your_api_key_here ``` On Windows (PowerShell): ```powershell $env:OPENAI_API_KEY="your_api_key_here" ``` ## Running the Example ```bash 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