cryogenic22 commited on
Commit
3ac5f73
·
verified ·
1 Parent(s): 641c1fc

Create utils/smart_naming.py

Browse files
Files changed (1) hide show
  1. utils/smart_naming.py +41 -0
utils/smart_naming.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils/smart_naming.py
2
+
3
+ from datetime import datetime
4
+ import streamlit as st
5
+
6
+ def generate_chat_name(chat_history, claude_service):
7
+ """Generate a smart name based on chat content"""
8
+ try:
9
+ # Combine all analyses into one text for summarization
10
+ full_text = ""
11
+ for entry in chat_history:
12
+ if entry.get('analysis'):
13
+ full_text += entry['analysis'] + "\n"
14
+
15
+ if not full_text:
16
+ return None
17
+
18
+ # Generate a concise name using Claude
19
+ prompt = """Based on this trading analysis, create a very short (3-6 words) title that captures the key focus.
20
+ Make it specific but concise. Include any relevant tickers or patterns mentioned.
21
+ Example formats:
22
+ - "AAPL Bullish Breakout Analysis"
23
+ - "SPY Multiple Timeframe Support"
24
+ - "Crypto Markets Correlation Study"
25
+
26
+ Analysis text:
27
+ {text}
28
+ """
29
+
30
+ summary = claude_service.generate_educational_content(prompt.format(text=full_text))
31
+ if summary:
32
+ # Clean up the summary
33
+ summary = summary.strip().strip('"').strip("'")
34
+ # Add timestamp for uniqueness
35
+ timestamp = datetime.now().strftime("%Y%m%d")
36
+ return f"{summary}_{timestamp}"
37
+
38
+ except Exception as e:
39
+ st.error(f"Error generating chat name: {str(e)}")
40
+
41
+ return None