cryogenic22 commited on
Commit
43b1336
·
verified ·
1 Parent(s): 4cf66df

Update storage/storage_manager.py

Browse files
Files changed (1) hide show
  1. storage/storage_manager.py +10 -33
storage/storage_manager.py CHANGED
@@ -19,15 +19,19 @@ class UserStorageManager:
19
  except Exception as e:
20
  st.error(f"Error creating directories: {str(e)}")
21
 
22
- def save_chat(self, chat_data, images=None, filename=None):
23
- """Save chat with associated images"""
24
  try:
25
  timestamp = datetime.now().isoformat()
26
  formatted_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
27
- chat_id = f"chat_{formatted_timestamp}"
28
 
29
- if filename:
30
- chat_id = filename.replace('.json', '')
 
 
 
 
 
31
 
32
  # Save chat data
33
  chat_file = self.paths["chats"] / f"{chat_id}.json"
@@ -37,36 +41,9 @@ class UserStorageManager:
37
  'id': chat_id,
38
  'timestamp': timestamp,
39
  'formatted_timestamp': formatted_timestamp,
 
40
  'data': chat_data
41
  }
42
-
43
- with open(chat_file, "w") as f:
44
- json.dump(chat_metadata, f)
45
-
46
- # Save associated images
47
- if images:
48
- image_dir = self.paths["images"] / chat_id
49
- image_dir.mkdir(exist_ok=True)
50
-
51
- if isinstance(images, list):
52
- for idx, img_data in enumerate(images):
53
- img_file = image_dir / f"image_{idx}.png"
54
- with open(img_file, "wb") as f:
55
- f.write(img_data)
56
- else:
57
- img_file = image_dir / "image_0.png"
58
- with open(img_file, "wb") as f:
59
- f.write(images)
60
-
61
- # Update chat data with image references
62
- chat_metadata['image_paths'] = [str(p) for p in image_dir.glob("*.png")]
63
- with open(chat_file, "w") as f:
64
- json.dump(chat_metadata, f)
65
-
66
- return chat_id
67
- except Exception as e:
68
- st.error(f"Error saving chat: {str(e)}")
69
- return None
70
 
71
  def get_all_chats(self):
72
  """Get all user's chats with metadata"""
 
19
  except Exception as e:
20
  st.error(f"Error creating directories: {str(e)}")
21
 
22
+ def save_chat(self, chat_data, images=None, filename=None, claude_service=None):
23
+ """Save chat with associated images and smart naming"""
24
  try:
25
  timestamp = datetime.now().isoformat()
26
  formatted_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
 
27
 
28
+ # Generate smart name if available
29
+ chat_title = None
30
+ if claude_service and isinstance(chat_data, list):
31
+ from utils.smart_naming import generate_chat_name
32
+ chat_title = generate_chat_name(chat_data, claude_service)
33
+
34
+ chat_id = filename or f"chat_{formatted_timestamp}"
35
 
36
  # Save chat data
37
  chat_file = self.paths["chats"] / f"{chat_id}.json"
 
41
  'id': chat_id,
42
  'timestamp': timestamp,
43
  'formatted_timestamp': formatted_timestamp,
44
+ 'title': chat_title or f"Trading Analysis {formatted_timestamp}",
45
  'data': chat_data
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  def get_all_chats(self):
49
  """Get all user's chats with metadata"""