Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #21

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/nfd_three_story_evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,13 @@ async def update(
Interaction strength: {interaction_strength}
Distance between states: {distance}

Based on this interaction, describe the new positive, neutral, or negative emotional state in 1 sentence:
Based on this interaction, your response should be a single word that captures the emotional response to the interaction.:
"""
new_description = await llm.generate(prompt)
new_description = new_description.strip()
# strip parentheses
new_description = re.sub(r"\([^)]*\)", "", new_description)
new_description = new_description.lower()

# Generate a new embedding for the updated emotional state
new_embedding = await llm.generate_embedding(new_description)
Expand Down Expand Up @@ -261,6 +265,7 @@ def __init__(
self._field = None
if field:
self.set_field(field)
self.theme_influences = {} # Add this line to track theme influences
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider consolidating theme influence tracking into a single location within the Story class

The theme influence tracking is unnecessarily split between Story.theme_influences and the perspective object, creating confusing duplication. Consolidate this into the Story class since it's the natural owner of theme-related state.

# Remove theme_influences from perspective object
# Keep only in Story class:
class Story:
    def __init__(self, ...):
        self.theme_influences = {}  # Single source of truth

    def update_theme_influence(self, theme: str, influence: float):
        self.theme_influences[theme] = self.theme_influences.get(theme, 0) + influence

# Update get_journey_analytics() to use story.theme_influences directly
most_influential_themes = sorted(
    story.theme_influences.items(), 
    key=lambda x: x[1], 
    reverse=True
)[:3]

This removes the duplicate state while preserving all functionality.


def set_field(self, field: "NarrativeField"):
self._field = field
Expand Down Expand Up @@ -366,6 +371,9 @@ def add_memory(self, memory: Memory):
self.memory_layer.append(memory)
self.memory_state.update(memory)

def update_theme_influence(self, theme: str, influence: float):
self.theme_influences[theme] = self.theme_influences.get(theme, 0) + influence


class NarrativeFieldViz(BaseClass):
"""Handles visualization of field state"""
Expand Down Expand Up @@ -796,6 +804,12 @@ async def process_interaction(self, story1: Story, story2: Story):
)
story1.add_memory(memory)

# Update theme influences
shared_themes = set(story1.themes) & set(story2.themes)
for theme in shared_themes:
story1.update_theme_influence(theme, resonance * 0.1)
story2.update_theme_influence(theme, resonance * 0.1)

return resonance, interaction_type
return 0, None

Expand Down Expand Up @@ -915,9 +929,10 @@ def summarize_journey(self, story: Story):
)

# Safely get unique interactions
unique_interactions = {
m["partner_id"] for m in story.memory_layer if "partner_id" in m
}
unique_interactions = set()
for memory in story.memory_layer:
if hasattr(memory, 'partner_id') and memory.partner_id is not None:
unique_interactions.add(memory.partner_id)
Comment on lines 931 to +935
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Convert for loop into set comprehension (set-comprehension)

Suggested change
# Safely get unique interactions
unique_interactions = {
m["partner_id"] for m in story.memory_layer if "partner_id" in m
}
unique_interactions = set()
for memory in story.memory_layer:
if hasattr(memory, 'partner_id') and memory.partner_id is not None:
unique_interactions.add(memory.partner_id)
unique_interactions = {
memory.partner_id
for memory in story.memory_layer
if hasattr(memory, 'partner_id') and memory.partner_id is not None
}

num_unique_interactions = len(unique_interactions)

# Emotional journey analysis
Expand Down Expand Up @@ -959,17 +974,13 @@ def get_journey_analytics(self, story: Story):
theme_counts[theme] = theme_counts.get(theme, 0) + 1

most_influential_themes = sorted(
story.perspective.theme_influences.items(), key=lambda x: x[1], reverse=True
story.theme_influences.items(), key=lambda x: x[1], reverse=True
)[:3]

return {
"total_memories": len(story.memory_layer),
"unique_interactions": len(
{
m.partner_id
for m in story.memory_layer
if m.partner_id is not None
}
{m.partner_id for m in story.memory_layer if m.partner_id is not None}
),
"theme_exposure": theme_counts,
"total_perspective_shift": story.total_perspective_shift,
Expand Down Expand Up @@ -1141,15 +1152,15 @@ async def simulate_field():
interaction_engine = EnhancedInteractionEngine(field, llm)

# Generate initial stories
for _ in range(9):
for _ in range(15):
story = await story_generator.generate_story(field)
field.add_story(story)

# Add journey logger
journey_logger = EnhancedJourneyLogger()

# Simulation loop
for t in range(100):
for t in range(10):
field.time = t

# Update physics
Expand Down
Loading