cryogenic22 commited on
Commit
0c4880f
·
verified ·
1 Parent(s): 6e94685

Update services/chart_analysis.py

Browse files
Files changed (1) hide show
  1. services/chart_analysis.py +22 -4
services/chart_analysis.py CHANGED
@@ -88,13 +88,15 @@ class ChartAnalysisService:
88
  if previous_analysis and not st.session_state.conversation_context:
89
  st.session_state.conversation_context.append({
90
  'role': 'assistant',
91
- 'content': previous_analysis
 
92
  })
93
 
94
  # Add current question to context
95
  st.session_state.conversation_context.append({
96
  'role': 'user',
97
- 'content': question
 
98
  })
99
 
100
  # Create a conversation-aware prompt
@@ -111,20 +113,36 @@ class ChartAnalysisService:
111
  # Add response to context
112
  st.session_state.conversation_context.append({
113
  'role': 'assistant',
114
- 'content': response
 
 
 
 
 
 
 
 
 
 
 
115
  })
116
 
117
  return {
118
  'timestamp': datetime.now().isoformat(),
119
  'question': question,
120
  'analysis': response,
121
- 'analysis_type': 'Follow-up'
 
122
  }
123
  return None
124
  except Exception as e:
125
  st.error(f"Error handling follow-up question: {str(e)}")
126
  return None
127
 
 
 
 
 
128
  def create_comparison_prompt(self, individual_analyses, comparison_type, expertise_level="Novice"):
129
  """Create a prompt for comparing multiple charts"""
130
  expertise_adjustments = {
 
88
  if previous_analysis and not st.session_state.conversation_context:
89
  st.session_state.conversation_context.append({
90
  'role': 'assistant',
91
+ 'content': previous_analysis,
92
+ 'timestamp': datetime.now().isoformat()
93
  })
94
 
95
  # Add current question to context
96
  st.session_state.conversation_context.append({
97
  'role': 'user',
98
+ 'content': question,
99
+ 'timestamp': datetime.now().isoformat()
100
  })
101
 
102
  # Create a conversation-aware prompt
 
113
  # Add response to context
114
  st.session_state.conversation_context.append({
115
  'role': 'assistant',
116
+ 'content': response,
117
+ 'timestamp': datetime.now().isoformat()
118
+ })
119
+
120
+ # Add to followups for UI display
121
+ if 'followups' not in st.session_state:
122
+ st.session_state.followups = []
123
+
124
+ st.session_state.followups.append({
125
+ 'question': question,
126
+ 'response': response,
127
+ 'timestamp': datetime.now().isoformat()
128
  })
129
 
130
  return {
131
  'timestamp': datetime.now().isoformat(),
132
  'question': question,
133
  'analysis': response,
134
+ 'analysis_type': 'Follow-up',
135
+ 'context_length': len(st.session_state.conversation_context)
136
  }
137
  return None
138
  except Exception as e:
139
  st.error(f"Error handling follow-up question: {str(e)}")
140
  return None
141
 
142
+ def get_conversation_context(self):
143
+ """Get the current conversation context"""
144
+ return st.session_state.get('conversation_context', [])
145
+
146
  def create_comparison_prompt(self, individual_analyses, comparison_type, expertise_level="Novice"):
147
  """Create a prompt for comparing multiple charts"""
148
  expertise_adjustments = {