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

Add base_temperature to StateAwareLLM to fix AttributeError #68

Merged
merged 5 commits into from
Dec 7, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Dec 7, 2024

Added base_temperature attribute to StateAwareLLM initialization with a default
value of 0.7. This fixes the AttributeError in the adjust_temperature method
by providing a baseline temperature that gets modified based on emotional state.

Summary by Sourcery

Introduce a new BrainLayer class for enhanced emotional processing and a StateAwareLLM class to manage state transitions and response adjustments. Fix an AttributeError in the adjust_temperature method by adding a base_temperature attribute. Remove unnecessary dependencies from requirements.txt.

New Features:

  • Introduce a new BrainLayer class that enhances emotional processing, metacognition, and rest states for the AI model.
  • Add a StateAwareLLM class that integrates with the BrainLayer to manage state transitions and adjust response temperature based on emotional state.

Bug Fixes:

  • Fix an AttributeError in the adjust_temperature method by adding a base_temperature attribute to the StateAwareLLM class.

Enhancements:

  • Enhance emotional processing by adding an EmotionalMemory class to track emotional patterns and transitions.
  • Improve thought processing with a multi-layer approach, including perception, memory comparison, emotional processing, and metacognition.

Build:

  • Remove unnecessary dependencies from requirements.txt, including llama-cpp-python and PyWavelets.

- Add vector-based memory system using ChromaDB with cosine similarity
- Initialize memory with foundational human-related thoughts
- Enhance thought processing with semantic similarity search
- Improve output format with structured related memories
- Add memory seeding on first run
- Limit embedding vector output for better readability

The brain can now:
- Store and retrieve semantically similar thoughts
- Compare new thoughts with existing memories
- Return relevant memories with similarity scores
- Process thoughts through multiple cognitive layers

Technical details:
- Uses nomic-embed-text for embeddings
- Uses llama3.2 for thought processing
- Implements cosine similarity for memory comparison
Implements a more sophisticated cognitive architecture with:
- Emotional analysis using LLM-based sentiment extraction
- Metacognitive processing with complexity metrics
- Temporal pattern recognition across thoughts
- Enhanced memory initialization
- Thought history tracking

New features:
- Emotional layer that identifies primary emotions and intensities
- Metacognitive analysis including:
  * Thought complexity metrics
  * Self-awareness level calculation
  * Pattern recognition across recent thoughts
  * Temporal tracking
- Expanded initial memory seeding
- Sequential thought processing capability
- Pretty-printed output for key components

Technical improvements:
- JSON response parsing for emotional analysis
- NumPy-based pattern recognition
- Timestamp tracking for temporal analysis
- Error handling for all processing layers
- Type hints for better code clarity
- History management with size limits

Breaking changes: None
Dependencies: Added numpy for statistical analysis
- Add constant model names for LLM and embeddings
- Fix emotional_momentum missing key in EmotionalMemory
- Update all model references to use constants
- Improve JSON response parsing with error handling

The changes ensure consistent model usage across the codebase and more
robust handling of emotional analysis responses. Model names are now
centralized as constants to prevent accidental changes.
Added base_temperature attribute to StateAwareLLM initialization with a default
value of 0.7. This fixes the AttributeError in the adjust_temperature method
by providing a baseline temperature that gets modified based on emotional state.
Copy link
Contributor

sourcery-ai bot commented Dec 7, 2024

Reviewer's Guide by Sourcery

This PR implements a new brain layer system with emotional processing and state management capabilities. The core change adds a base_temperature attribute to StateAwareLLM initialization to fix an AttributeError in the adjust_temperature method. The implementation includes a comprehensive brain architecture with emotional memory, metacognition, and state transitions.

Class diagram for BrainLayer and StateAwareLLM

classDiagram
    class BrainLayer {
        -OllamaClient llm
        -ChromaClient memory
        -EmotionalMemory emotional_memory
        -List thought_history
        -BrainState brain_state
        -int rest_cycle_counter
        -int max_thoughts_before_rest
        -Collection collection
        +process_thought(input_text: str) Dict
        +add_emotional_layer(thought: str) Dict
        +add_metacognition(thought: str, embeddings: List, emotional_state: Dict) Dict
        +_initialize_memory() void
        +_check_rest_state() Tuple
        +_analyze_thought_coherence(current_thought: str, prev_thoughts: List) float
        +_analyze_patterns() float
    }
    class StateAwareLLM {
        -BrainLayer brain
        -int rest_duration
        -int max_rest_duration
        -float base_temperature
        +check_state_transition(brain_state: Dict) Optional
        +adjust_temperature(emotional_state: Dict) float
        +create_context_prompt(user_input: str, brain_state: Dict) str
        +generate_response(prompt: str, temperature: float) str
        +format_response(response: str, brain_state: Dict) str
        +respond(user_input: str) str
    }
    BrainLayer --> EmotionalMemory
    StateAwareLLM --> BrainLayer
    class EmotionalMemory {
        -List emotional_history
        -int max_history
        +add_emotion(emotion: Dict) void
        +get_emotional_trend() Dict
    }
    class BrainState {
        <<enumeration>>
        ACTIVE
        RESTING
        LEARNING
        REFLECTING
    }
Loading

File-Level Changes

Change Details Files
Implemented a new brain layer system with emotional processing and state management
  • Created BrainState enum for tracking brain states (ACTIVE, RESTING, LEARNING, REFLECTING)
  • Implemented EmotionalMemory class for tracking emotional patterns and transitions
  • Added BrainLayer class with LLM and memory management capabilities
  • Implemented metacognition and thought processing functionality
  • Added emotional trend analysis and pattern recognition
brain/brain_layer.py
Added state-aware LLM implementation with temperature control
  • Added base_temperature attribute with default value of 0.7
  • Implemented temperature adjustment based on emotional state
  • Added state transition logic with rest/wake cycles
  • Created context-aware prompt generation
  • Added response formatting based on emotional state
brain/brain_layer.py
Updated project dependencies
  • Removed llama-cpp-python dependency
  • Removed PyWavelets dependency
requirements.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Add base_temperature to StateAwareLLM to fix AttributeError Dec 7, 2024
@leonvanbokhorst leonvanbokhorst self-assigned this Dec 7, 2024
@leonvanbokhorst leonvanbokhorst added the enhancement New feature or request label Dec 7, 2024
@leonvanbokhorst leonvanbokhorst added this to the Phase 1 milestone Dec 7, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leonvanbokhorst - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

brain/brain_layer.py Show resolved Hide resolved
brain/brain_layer.py Show resolved Hide resolved
brain/brain_layer.py Show resolved Hide resolved
brain/brain_layer.py Show resolved Hide resolved
brain/brain_layer.py Show resolved Hide resolved
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@leonvanbokhorst leonvanbokhorst merged commit aa9d952 into main Dec 7, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant