Files
tekstovaya-igra-na-osnove-l…/README.md
T

2.0 KiB
Raw Blame History

# Interactive ChooseYourOwnAdventure

This project demonstrates a simple text adventure game that uses an LLM (OpenAI) to generate a story opening, presents the user with three choices, and then continues the story based on the chosen option.  
The flow is built with **LangGraph** and uses **interrupts** to pause the graph and wait for user input in the console.

## Features

- Generates a short opening and three distinct choices using an LLM.
- Pauses execution with an interrupt and presents the choices via a console menu.
- Resumes the graph with the users selection and generates a short ending.
- Stores the entire story (topic, opening, choice, ending) in a JSON file.

## Prerequisites

- Python 3.10+
- An OpenAI API key. Set it in your environment:

```bash
export OPENAI_API_KEY="sk-..."

Installation

# Clone the repository
git clone https://github.com/yourusername/interactive-adventure.git
cd interactive-adventure

# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate   # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Usage

python src/main.py

You will be prompted to enter a topic for the adventure.
After the LLM generates the opening and choices, a menu will appear.
Select an option, and the story will continue with a short ending.
The final story will be printed to the console and saved to adventure_story.json.

Project Structure

interactive-adventure/
├── src/
│   └── main.py          # Main application logic
├── requirements.txt     # Python dependencies
└── README.md            # Documentation

Customization

  • LLM Model: Change the model parameter in ChatOpenAI inside src/main.py to use a different model.
  • Prompt Templates: Modify the prompt strings in generate_scene_and_choices and generate_ending to tweak the story style.
  • Number of Choices: Adjust the parsing logic if you want more or fewer options.

License

MIT License