From 3f147f22d238d1e99e42d4253f476e7039be6ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B8=D1=8F=20=D0=91=D0=B5=D1=80=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=D0=B0?= Date: Thu, 28 May 2026 09:02:54 +0000 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B8=D0=B3=D1=80=D0=B0=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20llm=20+=20interrupt:=20README.?= =?UTF-8?q?md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2c571c..7e918ac 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,92 @@ -# task-69b1a07c-tekstovaya-igra-na-osnove +# Text Adventure Game – LLM + Interrupt -Решения домашних заданий \ No newline at end of file +A lightweight text‑based adventure game that uses a large language model (LLM) to generate dynamic responses to player commands. +The project demonstrates how to integrate **LangChain** with an OpenAI chat model and use **Rich** for pretty console output. + +> ⚠️ **Prerequisites** – The code is written for Python 3.10+. +> It requires an OpenAI API key set in the environment variable `OPENAI_API_KEY`. + +--- + +## 📦 Installation + +```bash +# 1️⃣ Clone the repository (or copy the single file) +git clone https://github.com/yourname/text-adventure-llm.git +cd text-adventure-llm + +# 2️⃣ Create a virtual environment (recommended) +python -m venv .venv +source .venv/bin/activate # On Windows: .\.venv\Scripts\activate + +# 3️⃣ Install dependencies +pip install --upgrade pip +pip install langchain==0.1.0 # or the latest compatible version +pip install rich +``` + +> **Tip** – If you prefer a single‑file solution, just copy `solution.py` into your project directory and skip step 2. + +--- + +## 🚀 Running the Game + +```bash +# Make sure your OpenAI key is exported: +export OPENAI_API_KEY="sk-..." + +# Run the script +python solution.py +``` + +The game will start in an interactive console. +Type any command (e.g., `look around`, `go north`, `take sword`) and press **Enter**. +The LLM will generate a narrative response, which is printed with Rich formatting. + +--- + +## 📁 File Overview + +| File | Purpose | +|------|---------| +| `solution.py` | Main entry point – defines `TextAdventureGame` and runs the REPL loop. | + +If you want to experiment with different models or temperatures: + +```python +game = TextAdventureGame(model_name="gpt-4", temperature=0.5) +``` + +--- + +## 🎮 Example Session + +``` +$ python solution.py +Welcome to the LLM Adventure! Type your commands below. + +> look around +You find yourself in a dimly lit cavern, the walls dripping with moisture. A faint glow emanates from a crystal on the far wall. + +> take crystal +The crystal hums as you grasp it; its light warms your hand and reveals hidden runes etched into the stone floor. + +> go north +A narrow passage leads deeper underground. The air grows colder, and distant echoes hint at unseen dangers. + +... +``` + +--- + +## 🛠️ Extending + +- **Custom prompts** – Modify `TextAdventureGame` to prepend a system prompt or context. +- **Interrupt handling** – Add keyboard interrupt logic (`Ctrl+C`) to pause or exit gracefully. +- **State persistence** – Store the game state in a file or database for long‑term sessions. + +--- + +## 📄 License + +MIT © 2026. Feel free to fork, modify, and share! \ No newline at end of file