about summary refs log tree commit diff stats
path: root/bash/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'bash/exploration')
-rwxr-xr-xbash/exploration246
1 files changed, 246 insertions, 0 deletions
diff --git a/bash/exploration b/bash/exploration
new file mode 100755
index 0000000..8dc09b7
--- /dev/null
+++ b/bash/exploration
@@ -0,0 +1,246 @@
+#!/bin/bash
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Exploration System
+# This script systematically explores multiple solution paths and compares alternatives.
+#
+# APPLICATION LOGIC:
+# The exploration process implements a branching analysis system that systematically
+# explores multiple approaches to a problem and compares their merits. The system
+# operates through three distinct phases designed to maximize discovery and comparison:
+#
+# PHASE 1 - PATH GENERATION:
+#   - Identifies multiple possible approaches to the problem
+#   - Generates alternative solution paths
+#   - Ensures comprehensive coverage of the solution space
+#   - Creates a foundation for systematic comparison
+#
+# PHASE 2 - PATH EXPLORATION:
+#   - Explores each identified path in detail
+#   - Develops the implications and consequences of each approach
+#   - Identifies strengths, weaknesses, and trade-offs
+#   - Provides detailed analysis of each alternative
+#
+# PHASE 3 - COMPARATIVE ANALYSIS:
+#   - Systematically compares all explored paths
+#   - Evaluates relative merits and trade-offs
+#   - Identifies optimal approaches or combinations
+#   - Provides recommendations based on different criteria
+#
+# EXPLORATION MODELING:
+# The system applies systematic exploration principles to AI response generation:
+#   - Multiple paths ensure comprehensive problem coverage
+#   - Systematic comparison reveals optimal approaches
+#   - Trade-off analysis helps users make informed decisions
+#   - The process may reveal unexpected insights or approaches
+#   - Transparency shows how different paths were evaluated
+#   - The method may identify novel solutions that single-path approaches miss
+#
+# The exploration process emphasizes systematic analysis and comparison,
+# ensuring users understand the full range of possible approaches and their implications.
+
+# Source the logging system using absolute path
+source "${SCRIPT_DIR}/logging.sh"
+
+# --- Model Configuration ---
+EXPLORATION_MODEL="llama3:8b-instruct-q4_K_M"
+ANALYSIS_MODEL="phi3:3.8b-mini-4k-instruct-q4_K_M"
+
+# --- Defaults ---
+DEFAULT_PATHS=3
+
+# --- Argument Validation ---
+if [ "$#" -lt 1 ]; then
+    echo -e "\n\tExploration"
+    echo -e "\tThis script systematically explores multiple solution paths and compares alternatives."
+    echo -e "\n\tUsage: $0 [-f <file_path>] [-p <number_of_paths>] \"<your prompt>\" [number_of_rounds]"
+    echo -e "\n\tExample: $0 -f ./input.txt -p 4 \"How can we solve this problem?\" 2"
+    echo -e "\n\tIf number_of_rounds is not provided, the program will default to 2 rounds."
+    echo -e "\n\t-f <file_path> (optional): Append the contents of the file to the prompt."
+    echo -e "\n\t-p <paths> (optional): Number of solution paths to explore (default: 3)."
+    echo -e "\n"
+    exit 1
+fi
+
+# --- Argument Parsing ---
+FILE_PATH=""
+NUM_PATHS=$DEFAULT_PATHS
+while getopts "f:p:" opt; do
+  case $opt in
+    f)
+      FILE_PATH="$OPTARG"
+      ;;
+    p)
+      NUM_PATHS="$OPTARG"
+      ;;
+    *)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+  esac
+done
+shift $((OPTIND -1))
+
+PROMPT="$1"
+if [ -z "$2" ]; then
+    ROUNDS=2
+else
+    ROUNDS=$2
+fi
+
+# If file path is provided, append its contents to the prompt
+if [ -n "$FILE_PATH" ]; then
+    if [ ! -f "$FILE_PATH" ]; then
+        echo "File not found: $FILE_PATH" >&2
+        exit 1
+    fi
+    FILE_CONTENTS=$(cat "$FILE_PATH")
+    PROMPT="$PROMPT\n[FILE CONTENTS]\n$FILE_CONTENTS\n[END FILE]"
+fi
+
+# --- File Initialization ---
+mkdir -p ~/tmp
+SESSION_FILE=~/tmp/exploration_$(date +%Y%m%d_%H%M%S).txt
+
+# Initialize timing
+SESSION_ID=$(generate_session_id)
+start_timer "$SESSION_ID" "exploration"
+
+echo "Exploration Session Log: ${SESSION_FILE}"
+echo "---------------------------------"
+
+# Store the initial user prompt in the session file
+echo "USER PROMPT: ${PROMPT}" >> "${SESSION_FILE}"
+echo "NUMBER OF PATHS: ${NUM_PATHS}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 1: Path Generation ---
+echo "Phase 1: Generating solution paths..."
+echo "PHASE 1 - PATH GENERATION:" >> "${SESSION_FILE}"
+
+PATH_GENERATION_PROMPT="You are a strategic thinker. Your task is to identify ${NUM_PATHS} distinct, viable approaches to the following problem. Each path should represent a different strategy or methodology.
+
+PROBLEM: ${PROMPT}
+
+Please identify ${NUM_PATHS} different solution paths. For each path, provide:
+1. A clear name/title for the approach
+2. A brief description of the strategy
+3. The key principles or methodology it follows
+
+Format your response as:
+PATH 1: [Name]
+[Description]
+
+PATH 2: [Name]
+[Description]
+
+etc.
+
+Ensure the paths are genuinely different approaches, not just variations of the same idea."
+
+paths_output=$(ollama run "${EXPLORATION_MODEL}" "${PATH_GENERATION_PROMPT}")
+
+echo "GENERATED PATHS:" >> "${SESSION_FILE}"
+echo "${paths_output}" >> "${SESSION_FILE}"
+echo "" >> "${SESSION_FILE}"
+
+# --- Phase 2: Path Exploration ---
+echo "Phase 2: Exploring each path in detail..."
+echo "PHASE 2 - PATH EXPLORATION:" >> "${SESSION_FILE}"
+
+declare -a path_analyses
+declare -a path_names
+
+# Extract path names and explore each one
+for i in $(seq 1 "${NUM_PATHS}"); do
+    echo "  Exploring path ${i}..."
+    
+    # Extract the path description (simplified approach)
+    path_section=$(echo "${paths_output}" | sed -n "/PATH ${i}:/,/PATH $((i+1)):/p" | sed '$d')
+    if [ -z "$path_section" ]; then
+        path_section=$(echo "${paths_output}" | sed -n "/PATH ${i}:/,\$p")
+    fi
+    
+    # Generate path name from the section
+    path_name=$(echo "${path_section}" | head -n1 | sed 's/^PATH [0-9]*: //')
+    
+    EXPLORATION_PROMPT="You are a detailed analyst. Explore the following solution path in depth, considering its implications, requirements, and potential outcomes.
+
+ORIGINAL PROBLEM: ${PROMPT}
+
+PATH TO EXPLORE: ${path_section}
+
+Please provide a comprehensive analysis of this path including:
+1. Detailed implementation approach
+2. Potential benefits and advantages
+3. Potential challenges and risks
+4. Resource requirements and constraints
+5. Expected outcomes and timeline
+6. Success factors and critical elements
+7. Potential variations or adaptations
+
+Provide a thorough, well-structured analysis."
+
+    path_analysis=$(ollama run "${EXPLORATION_MODEL}" "${EXPLORATION_PROMPT}")
+    
+    path_analyses[$((i-1))]="${path_analysis}"
+    path_names[$((i-1))]="${path_name}"
+    
+    echo "PATH ${i} ANALYSIS (${path_name}):" >> "${SESSION_FILE}"
+    echo "${path_analysis}" >> "${SESSION_FILE}"
+    echo "" >> "${SESSION_FILE}"
+done
+
+# --- Phase 3: Comparative Analysis ---
+echo "Phase 3: Comparing and evaluating paths..."
+echo "PHASE 3 - COMPARATIVE ANALYSIS:" >> "${SESSION_FILE}"
+
+# Create comparison prompt
+COMPARISON_PROMPT="You are a strategic analyst. Compare and evaluate the following solution paths for the given problem.
+
+ORIGINAL PROBLEM: ${PROMPT}
+
+PATH ANALYSES:"
+
+for i in $(seq 0 $((NUM_PATHS-1))); do
+    COMPARISON_PROMPT="${COMPARISON_PROMPT}
+
+PATH ${i+1}: ${path_names[$i]}
+${path_analyses[$i]}"
+done
+
+COMPARISON_PROMPT="${COMPARISON_PROMPT}
+
+Please provide a comprehensive comparative analysis including:
+1. Direct comparison of approaches across key criteria
+2. Relative strengths and weaknesses of each path
+3. Trade-offs and opportunity costs
+4. Risk assessment for each approach
+5. Recommendations based on different scenarios
+6. Potential for combining elements from multiple paths
+7. Final recommendation with justification
+
+Provide a clear, structured comparison that helps decision-making."
+
+comparative_analysis=$(ollama run "${ANALYSIS_MODEL}" "${COMPARISON_PROMPT}")
+
+echo "COMPARATIVE ANALYSIS:" >> "${SESSION_FILE}"
+echo "${comparative_analysis}" >> "${SESSION_FILE}"
+
+# End timing
+duration=$(end_timer "$SESSION_ID" "exploration")
+
+# --- Final Output ---
+echo "---------------------------------"
+echo "Exploration process complete."
+echo "Comparative analysis:"
+echo "---------------------------------"
+
+echo "${comparative_analysis}"
+echo ""
+echo "Paths explored: ${NUM_PATHS}"
+echo "Execution time: ${duration} seconds"
+echo ""
+echo "Full exploration log: ${SESSION_FILE}" 
\ No newline at end of file