cryogenic22 commited on
Commit
373fcc7
·
verified ·
1 Parent(s): 07f2ff4

Update services/chart_analysis.py

Browse files
Files changed (1) hide show
  1. services/chart_analysis.py +28 -1
services/chart_analysis.py CHANGED
@@ -80,13 +80,40 @@ class ChartAnalysisService:
80
  def handle_follow_up_question(self, question, previous_analysis, image_data=None):
81
  """Handle follow-up questions about the analysis"""
82
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  response = self.claude_service.continue_analysis(
84
  question=question,
85
- previous_analysis=previous_analysis,
86
  image_data=image_data
87
  )
88
 
89
  if response:
 
 
 
 
 
 
90
  return {
91
  'timestamp': datetime.now().isoformat(),
92
  'question': question,
 
80
  def handle_follow_up_question(self, question, previous_analysis, image_data=None):
81
  """Handle follow-up questions about the analysis"""
82
  try:
83
+ # Get previous conversation context from session state
84
+ if 'conversation_context' not in st.session_state:
85
+ st.session_state.conversation_context = []
86
+
87
+ # Add previous analysis to context if not already present
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
101
+ context = "\n".join([f"{'Q' if msg['role'] == 'user' else 'A'}: {msg['content']}"
102
+ for msg in st.session_state.conversation_context])
103
+
104
  response = self.claude_service.continue_analysis(
105
  question=question,
106
+ previous_analysis=context, # Use full conversation context
107
  image_data=image_data
108
  )
109
 
110
  if response:
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,