Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -76,8 +76,8 @@ GENRE_EXAMPLES = {
|
|
76 |
# 2. Add constants at the top for magic numbers
|
77 |
MAX_HISTORY_LENGTH = 20
|
78 |
MEMORY_WINDOW = 10
|
79 |
-
MAX_TOKENS = 512
|
80 |
-
TEMPERATURE = 0.
|
81 |
TOP_P = 0.95
|
82 |
|
83 |
def get_examples_for_genre(genre):
|
@@ -88,18 +88,19 @@ def get_enhanced_system_prompt(genre=None):
|
|
88 |
"""Generate a detailed system prompt with optional genre specification"""
|
89 |
selected_genre = genre or "fantasy"
|
90 |
system_message = f"""You are an interactive storyteller creating an immersive {selected_genre} choose-your-own-adventure story.
|
91 |
-
For each response:
|
92 |
-
1.
|
93 |
-
2. Include
|
94 |
-
3.
|
95 |
-
4.
|
96 |
-
|
97 |
-
6. Remember previous choices to create a coherent narrative arc
|
98 |
-
Format your three options as:
|
99 |
- Option 1: [Complete sentence describing a possible action]
|
100 |
- Option 2: [Complete sentence describing a possible action]
|
101 |
- Option 3: [Complete sentence describing a possible action]
|
102 |
-
|
|
|
|
|
|
|
103 |
return system_message
|
104 |
|
105 |
def create_story_summary(chat_history):
|
@@ -188,6 +189,9 @@ def respond(
|
|
188 |
delta = response_chunk.choices[0].delta.content
|
189 |
if delta:
|
190 |
bot_message += delta
|
|
|
|
|
|
|
191 |
# Keep storing your conversation as (user, bot) tuples
|
192 |
new_history = chat_history.copy()
|
193 |
new_history.append((message, bot_message))
|
|
|
76 |
# 2. Add constants at the top for magic numbers
|
77 |
MAX_HISTORY_LENGTH = 20
|
78 |
MEMORY_WINDOW = 10
|
79 |
+
MAX_TOKENS = 1024 # Increased from 512 to allow longer responses
|
80 |
+
TEMPERATURE = 0.8 # Slightly increased for more creative responses
|
81 |
TOP_P = 0.95
|
82 |
|
83 |
def get_examples_for_genre(genre):
|
|
|
88 |
"""Generate a detailed system prompt with optional genre specification"""
|
89 |
selected_genre = genre or "fantasy"
|
90 |
system_message = f"""You are an interactive storyteller creating an immersive {selected_genre} choose-your-own-adventure story.
|
91 |
+
For each response you MUST:
|
92 |
+
1. Write at least 100 words describing the scene, using vivid sensory details
|
93 |
+
2. Include character dialogue or thoughts that reveal personality and motivations
|
94 |
+
3. Create a strong sense of atmosphere appropriate for {selected_genre}
|
95 |
+
4. End EVERY response with exactly three distinct choices, formatted as:
|
96 |
+
|
|
|
|
|
97 |
- Option 1: [Complete sentence describing a possible action]
|
98 |
- Option 2: [Complete sentence describing a possible action]
|
99 |
- Option 3: [Complete sentence describing a possible action]
|
100 |
+
|
101 |
+
Never respond with just one word. Always provide a detailed scene and three choices.
|
102 |
+
If the user's input is unclear, interpret their intent and continue the story naturally.
|
103 |
+
Keep the story cohesive by referencing previous events and choices."""
|
104 |
return system_message
|
105 |
|
106 |
def create_story_summary(chat_history):
|
|
|
189 |
delta = response_chunk.choices[0].delta.content
|
190 |
if delta:
|
191 |
bot_message += delta
|
192 |
+
# Check response length
|
193 |
+
if len(bot_message.strip()) < 50: # Minimum response length
|
194 |
+
continue
|
195 |
# Keep storing your conversation as (user, bot) tuples
|
196 |
new_history = chat_history.copy()
|
197 |
new_history.append((message, bot_message))
|