drAbreu commited on
Commit
5109026
·
1 Parent(s): c3be4d9

Added thinking capabilities to anthropic models

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -118,15 +118,31 @@ class BasicAgent:
118
 
119
 
120
  class ResponseCache:
121
- """Cache manager for storing and retrieving agent responses."""
122
 
123
- def __init__(self, cache_file="agent_cache.json"):
124
  """Initialize the cache manager.
125
 
126
  Args:
127
- cache_file: Path to the JSON file for storing the cache
128
  """
129
- self.cache_file = cache_file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  self.cache = self._load_cache()
131
 
132
  # Stats for the current session
@@ -138,7 +154,10 @@ class ResponseCache:
138
  try:
139
  if os.path.exists(self.cache_file):
140
  with open(self.cache_file, 'r') as f:
141
- return json.load(f)
 
 
 
142
  return {}
143
  except Exception as e:
144
  print(f"Error loading cache: {e}. Starting with empty cache.")
@@ -149,6 +168,7 @@ class ResponseCache:
149
  try:
150
  with open(self.cache_file, 'w') as f:
151
  json.dump(self.cache, f)
 
152
  except Exception as e:
153
  print(f"Error saving cache: {e}")
154
 
 
118
 
119
 
120
  class ResponseCache:
121
+ """Cache manager for storing and retrieving agent responses with persistence across HF rebuilds."""
122
 
123
+ def __init__(self, cache_name="agent_responses"):
124
  """Initialize the cache manager.
125
 
126
  Args:
127
+ cache_name: Base name for the cache file
128
  """
129
+ # Use /data directory for persistence in HF Spaces
130
+ # Fall back to local directory if running locally
131
+ if os.path.exists("/data") and os.access("/data", os.W_OK):
132
+ self.cache_dir = Path("/data")
133
+ print("Using HF Spaces persistent storage in /data directory")
134
+ else:
135
+ self.cache_dir = Path(".")
136
+ print("Using local directory for cache (not persistent across HF rebuilds)")
137
+
138
+ # Ensure directory exists
139
+ os.makedirs(self.cache_dir, exist_ok=True)
140
+
141
+ # Full path to cache file
142
+ self.cache_file = self.cache_dir / f"{cache_name}.json"
143
+ print(f"Cache file location: {self.cache_file}")
144
+
145
+ # Load the cache
146
  self.cache = self._load_cache()
147
 
148
  # Stats for the current session
 
154
  try:
155
  if os.path.exists(self.cache_file):
156
  with open(self.cache_file, 'r') as f:
157
+ cache_data = json.load(f)
158
+ print(f"Cache loaded with {len(cache_data)} entries")
159
+ return cache_data
160
+ print("No existing cache found, starting with empty cache")
161
  return {}
162
  except Exception as e:
163
  print(f"Error loading cache: {e}. Starting with empty cache.")
 
168
  try:
169
  with open(self.cache_file, 'w') as f:
170
  json.dump(self.cache, f)
171
+ print(f"Cache saved with {len(self.cache)} entries")
172
  except Exception as e:
173
  print(f"Error saving cache: {e}")
174