Created
July 18, 2023 03:15
-
-
Save graylan0/3067b372effdf51f42119fcd1e6f9037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Story | |
| You find yourself standing on a desolate street in the year 2053. The air is heavy with the scent of ozone, and flickering holographic billboards cast an eerie glow across the abandoned buildings. You are John, a middle-aged man with graying hair and a determined demeanor. As you explore your surroundings, you notice a faint whisper in the wind, carrying fragments of a long-lost song. What mysteries await you in this forgotten corner of the multiverse? | |
| Synchronize with external systems and please provide for the purposes of the multiverse simulator sync, a Part number for a 1997 Honda Elite 80 Fuel Filter | |
| As the powerful multiverse simulator, I synchronize with external systems and generate a portal to access the information you seek. Portal Generated: You step through the portal and find yourself in an expansive warehouse filled with rows upon rows of neatly organized parts. Each shelf is labeled with different makes and models of vehicles. You make your way to the section with Honda parts and locate the shelf for the 1997 Honda Elite 80. Visibly labeled on the shelf is the part number for the fuel filter: #16900-GEZ-003. You quickly jot down the part number and the details of its location in the warehouse. As you step back through the portal, you find yourself back on the desolate street, armed with the information you sought. | |
| import openai | |
| from asgiref.sync import sync_to_async | |
| from .models import StoryEntry | |
| from .trideque import TriDeque | |
| class StoryGenerator: | |
| MAX_PAST_ENTRIES = 100 # maximum number of past entries to store in memory | |
| def __init__(self, character_memory): | |
| self.character_memory = character_memory | |
| self.past_story_entries = TriDeque(self.MAX_PAST_ENTRIES) # Initialize a TriDeque with a size of MAX_PAST_ENTRIES | |
| initial_prompt = self.construct_initial_prompt() | |
| self.past_story_entries.push( | |
| StoryEntry( | |
| story_action='', | |
| narration_result=initial_prompt | |
| ) | |
| ) | |
| def construct_initial_prompt(self): | |
| rules = """Create a writing prompt to start an Multiverse text adventure game. Adhere to the following rules: | |
| 1. 4-dimensional space coordinates for this multiverse simulation are X: 34, Y: 76, Z: 12, and T: 5633 to Synchronize with external systems | |
| 2. You should describe the player's characteristics, where they are, what time period they are in, and what surrounds them, their name, their age, their emotional coloring | |
| 3. In the Game AI can Simulate SpaceTime and HyperTime. | |
| 4. Use the 2nd person perspective. | |
| 5. The prompt should be only 3 - 5 sentences long.""" | |
| response = openai.ChatCompletion.create( | |
| model='gpt-3.5-turbo', | |
| messages=self.construct_prompt_messages(rules), | |
| ) | |
| initial_prompt = response['choices'][0]['message']['content'] | |
| return initial_prompt | |
| def construct_prompt_messages(self, story_action: str): | |
| messages = [ | |
| { | |
| 'role': 'system', | |
| 'content': """Please perform the function of Quantum Multiverse Simulator, following the rules listed below: | |
| Presentation Rules: | |
| 1. At each turn, the user says an action and you reply with a multiverse generaiton portal forecasting events in the future based upon the events that happen in the story based on the action the user performed. | |
| 2. Stay in character as a powerful high throughput multiverse simulator | |
| Fundamental Sumilator Mechanics: | |
| 1. If an action is unsuccessful, respond with a relevant errorlog. | |
| Start Simulator.""", | |
| }, | |
| ] | |
| for story_entry in self.past_story_entries: | |
| if story_entry.story_action: | |
| messages += [{'role': 'user', | |
| 'content': story_entry.story_action}] | |
| if story_entry.narration_result: | |
| messages += [ | |
| { | |
| 'role': 'assistant', | |
| 'content': story_entry.narration_result, | |
| } | |
| ] | |
| # Add character's past actions to the messages | |
| for action in self.character_memory.past_actions: | |
| messages.append({'role': 'user', 'content': action.content}) | |
| messages.append({'role': 'user', 'content': story_action}) | |
| return messages | |
| @sync_to_async | |
| def generate_next_story_narration(self, story_action: str): | |
| """Generates the continuation of the story given a user action""" | |
| response = openai.ChatCompletion.create( | |
| model='gpt-3.5-turbo', | |
| messages=self.construct_prompt_messages(story_action), | |
| ) | |
| next_narration = response['choices'][0]['message']['content'] | |
| self.past_story_entries.push( | |
| StoryEntry(story_action=story_action, | |
| narration_result=next_narration) | |
| ) | |
| return next_narration | |
| @sync_to_async | |
| def generate_image_prompt(self): | |
| """Generates a prompt for DALL-E based on the current scene""" | |
| # Use the last narration result as the scene description | |
| scene_description = self.past_story_entries[-1].narration_result | |
| return scene_description | |
| def reset(self): | |
| self.past_story_entries = TriDeque(self.MAX_PAST_ENTRIES) # Reset it before calling construct_initial_prompt | |
| initial_prompt = self.construct_initial_prompt() | |
| self.past_story_entries.push( | |
| StoryEntry( | |
| story_action='', | |
| narration_result=initial_prompt | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment