Text Adventure Game Powered by LLM + Interrupt
A lightweight text‑adventure game that uses a large language model (LLM) via LangChain to generate dynamic storylines in real time.
The game runs entirely from the command line and can be extended with new prompts or models.
📦 Installation
-
Clone the repository
git clone https://github.com/your-username/text-adventure-llm.git cd text-adventure-llm -
Create a virtual environment (recommended)
python -m venv .venv source .venv/bin/activate # On Windows: .\.venv\Scripts\activate -
Install dependencies
pip install --upgrade pip pip install -r requirements.txtrequirements.txtcontains:langchain==0.2.0 langchain-openai==0.1.0 openai==1.30.0 -
Set your OpenAI API key
The game uses the OpenAI API via LangChain.
Export the key as an environment variable:export OPENAI_API_KEY="sk-..." # Windows PowerShell: $env:OPENAI_API_KEY = "sk-..."
🚀 Running the Game
The entire game logic is in solution.py. Simply execute it with Python:
python solution.py
You will see a welcome message and can start typing commands.
Type exit to quit.
Example Session
Добро пожаловать в текстовую приключенческую игру!
Введите команду (или 'exit' для выхода): Я открываю дверь.
Ответ ведущего:
Ты осторожно открываешь старую деревянную дверь, которая скрипит под твоим весом. За дверью виднеется темный коридор, освещенный мерцающим светом факелов. Внутри слышен шёпот ветра и отдалённые шаги.
Введите команду (или 'exit'): Я смотрю вокруг.
Ответ ведущего:
Тебе удаётся разглядеть несколько старинных портретов на стенах, их глаза будто следят за каждым твоим движением. В центре коридора стоит массивный каменный стол с таинственными рунами.
Введите команду (или 'exit'): exit
Спасибо за игру! До встречи.
📄 File Overview
| File | Purpose |
|---|---|
solution.py |
Main game loop, LangChain configuration, prompt template, and interaction logic. |
requirements.txt |
Python dependencies required to run the project. |
🔧 Extending the Game
- Change the model: Edit
model_nameinChatOpenAI(...). - Adjust temperature: Lower values make responses more deterministic; higher values increase creativity.
- Add new prompts: Modify
prompt_template.templateto change how the LLM is instructed. - Persist history: Currently, only the last user input and accumulated story are passed. You can store a full conversation log if needed.
📜 License
This project is released under the MIT License. Feel free to fork, modify, and distribute.