Harness the power of AI in your Ren'Py visual novel projects! This plugin facilitates the creation of interactive text-based games by leveraging an AI model for narrative generation. It's seamlessly integrated with the Ren'Py visual novel engine. The feature also involves the control of player status attributes.
-
Clone this directory into the
game/
directory of your Ren'Py project. -
Check out
Stories/README.md
for instructions on utilizing ChatGPT for generating essential story configuration files. -
Organize your config files in subdirectories within the
Stories/
directory. Your files should include:character_attributes.json
character_options.json
end_conditions.json
story_instructions.txt
-
In
main.rpy
, provide the absolute path to theAutoScriptPlugin/
directory and enter your ChatGPT API keys:API_KEY = 'YOUR_API_KEY' ... DIR_PATH = ".../AutoScriptPlugin/" # Replace with the actual path to this directory. STORY_CONFIG_PATH = DIR_PATH + "Stories/" + YOUR_OWN_STORY_DIRECTORY + "/"
(Note: If you include any subdirectories in the
Stories/
directory, the game will instantly load with the example story configurations I've provided.)(🔑 How to generate your own API Key : https://openaimaster.com/how-to-get-chatgpt-api-key-free-use-it/)
-
Within any Ren'Py label, use
jump AutoScript
to kick off the text game experience.jump AutoScript
-
For optimization and fine-tuning, modify the
initial_prompt
withinauto-script/auto_script.rpy
.Your
initial_prompt
and the content withinstory_instructions.txt
substantially affect the narrative quality delivered by the API. Thus, carefully craft your prompts and instructions, ensuring you highlight crucial elements, like how scenes should be depicted by the AI.
- Contributions welcome!
- MIT License: Feel free to use this plugin for both commercial and non-commercial projects.
main.rpy
-
Initialization: Configures API keys, directory paths, time intervals, and file settings.
-
Functions: Oversees operations like character status determination, game data handling in JSON, and game state management.
-
UI Components: Offers interfaces for game preferences, character details, status updates, and game reset confirmations.
-
Game Mechanics: Manages theme shifts, player and partner naming, game initiation, and interaction handling. The script orchestrates in-game interactions, leverages the GPT model, and governs game state transitions and character nuances.
auto-character/build_character.rpy
-
CharacterBuilder
:-
Purpose: To streamline the creation of a GPTCharacter.
-
Key Functions:
-
build_character()
: Ingests character attributes, prompts for a name, and facilitates user attribute selection. -
choose_option()
: Assists users in selecting character traits from available choices. -
load_attribute_options()
: Sources character attributes from a specified JSON file.
-
-
-
GPTCharacter
-
Purpose: To represent a character, bifurcated into fixed and dynamic attributes.
-
Key Functions:
-
load_attributes()
: Ingests character traits, prompts for a name, and lets users select certain attributes. -
set_fixed_attribute()
&set_dynamic_attribute()
: Allocate values to specific character attributes. -
get_attribute_value()
: Fetches the value of a designated attribute.
-
-
The entire operation is architected around character creation by importing attributes from JSON files, soliciting user responses, and cementing the character attributes.
auto-script/auto_script.rpy
AutoScriptGPT
-
Dependencies: Uses
json
for file parsing andrequests
for HTTP communication. -
Key Class:
AutoScriptGPT
which drives an event-based visual novel game with GPT models. -
Features:
- Initialization: Sets up player, partner, game state, parser, and initial game prompt.
- Configuration Loader: Reads ending configurations and story instructions from files.
- Game Flow:
- Initial Prompt Generation: Creates a guide for players based on loaded configurations.
- Main Game Loop (
run
): Communicates with the GPT model, processes its responses, checks for game-ending conditions, and periodically summarizes the storyline.
- Game Saving & Loading: Can load a saved game state from JSON files.
- Story Summarization: Periodically condenses the story progression into a summary.
- Custom Ending: Generates an ending based on the current story progression and character attributes.
- GPT Communication (
getResponse
): Contacts the GPT model using HTTP requests and processes its responses.
- Note: There's a commented section related to RenPy's persistent data setup, not detailed here. This description aims to give a reader a general idea of what the code does, without diving deep into specifics. Adjustments can be made based on the desired level of detail for the README file.
auto-script/parse_response.rpy
AutoScriptParser
- Designed for: Processing scripts for visual novel games.
- Key Attributes:
- Prefix constants to identify script sections:
DIALOG_PREFIX
,NARRATION_PREFIX
, etc. SPLITTER
: Regex for text segmentation into sentences.STATIC_REPLACEMENTS
: Patterns to be replaced in scripts.
- Prefix constants to identify script sections:
- Main Functions:
- Replace script placeholders with character names.
- Parse and interpret dialogues, narrations, menus, and attribute modifications.
- Modify a character's attributes based on script instructions.
- Utility:
split_into_sentences
: Splits a block of text into separate sentences
-
Formatting Concerns: While I've worked diligently to ensure the ChatGPT API maintains a consistent response format, there are rare occasions when it might deviate. Many issues you encounter with this plugin may stem from these inconsistencies. Therefore, always inspect the response using a console print before parsing.
-
Development Phase: Keep in mind that this plugin is still in its early stages, resembling more of a demo. As a result, you can expect further refinements, enhancements, and the introduction of additional features in the future.
Stay tuned for updates, and thank you for your understanding and patience!