GuglielmoTor commited on
Commit
8bbd5a5
·
verified ·
1 Parent(s): 4ffa7e5

Update services/agentic_handlers.py

Browse files
Files changed (1) hide show
  1. services/agentic_handlers.py +42 -13
services/agentic_handlers.py CHANGED
@@ -49,8 +49,8 @@ class AgenticHandlers:
49
 
50
  # Initial "waiting" status updates
51
  initial_report_status = "Pipeline AI: In attesa dei dati necessari..."
52
- initial_okr_choices = []
53
- initial_okr_value = []
54
  initial_okr_interactive = False
55
  initial_okr_details = "Pipeline AI: In attesa dei dati necessari..."
56
  initial_orchestration_results = self.orchestration_raw_results_st.value # Preserve if re-running
@@ -61,7 +61,9 @@ class AgenticHandlers:
61
  report_status_md_update = gr.update(value=initial_report_status) if self.report_components.get("agentic_pipeline_status_md") else gr.update()
62
  report_display_md_update = gr.update() # No change to report display yet
63
 
64
- okrs_cbg_update = gr.update(choices=initial_okr_choices, value=initial_okr_value, interactive=initial_okr_interactive) if self.okrs_components.get("key_results_cbg") else gr.update()
 
 
65
  okrs_detail_md_update = gr.update(value=initial_okr_details) if self.okrs_components.get("okr_detail_display_md") else gr.update()
66
 
67
  if not current_token_state_val or not current_token_state_val.get("token"):
@@ -69,8 +71,8 @@ class AgenticHandlers:
69
  yield (
70
  report_status_md_update, # For agentic_pipeline_status_md
71
  report_display_md_update, # For agentic_report_display_md (no change yet)
72
- okrs_cbg_update, # For key_results_cbg
73
- okrs_detail_md_update, # For okr_detail_display_md
74
  initial_orchestration_results, # For orchestration_raw_results_st
75
  initial_selected_krs, # For selected_key_result_ids_st
76
  initial_krs_for_selection # For key_results_for_selection_st
@@ -84,6 +86,7 @@ class AgenticHandlers:
84
  if self.okrs_components.get("okr_detail_display_md"): # Also update OKR detail placeholder
85
  okrs_detail_md_update = gr.update(value="Dettagli OKR (Sempre) in corso di generazione...")
86
 
 
87
  yield (
88
  report_status_md_update, report_display_md_update, okrs_cbg_update, okrs_detail_md_update,
89
  initial_orchestration_results, initial_selected_krs, initial_krs_for_selection
@@ -96,6 +99,12 @@ class AgenticHandlers:
96
  report_status_md_update = gr.update(value=error_status)
97
  if self.report_components.get("agentic_report_display_md"):
98
  report_display_md_update = gr.update(value=error_status) # Update report display too
 
 
 
 
 
 
99
  if self.okrs_components.get("okr_detail_display_md"):
100
  okrs_detail_md_update = gr.update(value=error_status) # Update OKR detail too
101
 
@@ -137,9 +146,19 @@ class AgenticHandlers:
137
  krs_for_ui_selection_list = extract_key_results_for_selection(actionable_okrs)
138
  krs_for_selection_update_val = krs_for_ui_selection_list # Store for CBG change handler
139
 
140
- kr_choices_for_cbg = [(kr['kr_description'], kr['unique_kr_id']) for kr in krs_for_ui_selection_list]
 
 
 
 
 
141
  if self.okrs_components.get("key_results_cbg"):
142
- okrs_cbg_update = gr.update(choices=kr_choices_for_cbg, value=[], interactive=True)
 
 
 
 
 
143
 
144
  # Display all OKRs initially (before any KR selection)
145
  all_okrs_md_parts = []
@@ -159,8 +178,11 @@ class AgenticHandlers:
159
  final_status_text = "Pipeline AI (Sempre): Nessun risultato prodotto."
160
  if self.report_components.get("agentic_report_display_md"):
161
  report_display_md_update = gr.update(value="Nessun report generato dalla pipeline AI (Sempre).")
 
 
162
  if self.okrs_components.get("key_results_cbg"):
163
- okrs_cbg_update = gr.update(choices=[], value=[], interactive=False)
 
164
  if self.okrs_components.get("okr_detail_display_md"):
165
  okrs_detail_md_update = gr.update(value="Nessun OKR generato o errore nella pipeline AI (Sempre).")
166
 
@@ -179,8 +201,11 @@ class AgenticHandlers:
179
  report_status_md_update = gr.update(value=error_status_text)
180
  if self.report_components.get("agentic_report_display_md"):
181
  report_display_md_update = gr.update(value=f"Errore generazione report AI (Sempre): {str(e)}")
 
 
182
  if self.okrs_components.get("key_results_cbg"):
183
- okrs_cbg_update = gr.update(choices=[], value=[], interactive=False)
 
184
  if self.okrs_components.get("okr_detail_display_md"):
185
  okrs_detail_md_update = gr.update(value=f"Errore generazione OKR AI (Sempre): {str(e)}")
186
 
@@ -262,12 +287,17 @@ class AgenticHandlers:
262
  return
263
 
264
  if self.okrs_components.get("key_results_cbg"):
 
 
 
 
 
265
  self.okrs_components['key_results_cbg'].change(
266
  fn=self.update_okr_display_on_kr_selection,
267
  inputs=[
268
- self.okrs_components['key_results_cbg'], # Current value of checkbox group
269
- self.orchestration_raw_results_st, # State
270
- self.key_results_for_selection_st # State
271
  ],
272
  outputs=[self.okrs_components['okr_detail_display_md']],
273
  api_name="update_okr_display_on_kr_selection"
@@ -275,4 +305,3 @@ class AgenticHandlers:
275
  logging.info("Agentic OKR selection handler setup complete.")
276
  else:
277
  logging.warning("key_results_cbg component not found for agentic OKR handler setup.")
278
-
 
49
 
50
  # Initial "waiting" status updates
51
  initial_report_status = "Pipeline AI: In attesa dei dati necessari..."
52
+ # initial_okr_choices = [] # No longer used directly for okrs_cbg_update if it's Markdown
53
+ initial_okr_value_for_markdown = "" # Assuming this component is Markdown, value should be string
54
  initial_okr_interactive = False
55
  initial_okr_details = "Pipeline AI: In attesa dei dati necessari..."
56
  initial_orchestration_results = self.orchestration_raw_results_st.value # Preserve if re-running
 
61
  report_status_md_update = gr.update(value=initial_report_status) if self.report_components.get("agentic_pipeline_status_md") else gr.update()
62
  report_display_md_update = gr.update() # No change to report display yet
63
 
64
+ # If key_results_cbg is the Markdown component causing the error, its update should not have 'choices'.
65
+ # Its value should be a string.
66
+ okrs_cbg_update = gr.update(value=initial_okr_value_for_markdown, interactive=initial_okr_interactive) if self.okrs_components.get("key_results_cbg") else gr.update()
67
  okrs_detail_md_update = gr.update(value=initial_okr_details) if self.okrs_components.get("okr_detail_display_md") else gr.update()
68
 
69
  if not current_token_state_val or not current_token_state_val.get("token"):
 
71
  yield (
72
  report_status_md_update, # For agentic_pipeline_status_md
73
  report_display_md_update, # For agentic_report_display_md (no change yet)
74
+ okrs_cbg_update, # For key_results_cbg (now updated as if it's Markdown)
75
+ okrs_detail_md_update, # For okr_detail_display_md
76
  initial_orchestration_results, # For orchestration_raw_results_st
77
  initial_selected_krs, # For selected_key_result_ids_st
78
  initial_krs_for_selection # For key_results_for_selection_st
 
86
  if self.okrs_components.get("okr_detail_display_md"): # Also update OKR detail placeholder
87
  okrs_detail_md_update = gr.update(value="Dettagli OKR (Sempre) in corso di generazione...")
88
 
89
+ # okrs_cbg_update remains as initially defined (waiting state, no choices)
90
  yield (
91
  report_status_md_update, report_display_md_update, okrs_cbg_update, okrs_detail_md_update,
92
  initial_orchestration_results, initial_selected_krs, initial_krs_for_selection
 
99
  report_status_md_update = gr.update(value=error_status)
100
  if self.report_components.get("agentic_report_display_md"):
101
  report_display_md_update = gr.update(value=error_status) # Update report display too
102
+
103
+ # If key_results_cbg is Markdown, update its value to reflect the error.
104
+ # No choices argument here.
105
+ if self.okrs_components.get("key_results_cbg"):
106
+ okrs_cbg_update = gr.update(value=error_status, interactive=False) # Value is string, interactive is False
107
+
108
  if self.okrs_components.get("okr_detail_display_md"):
109
  okrs_detail_md_update = gr.update(value=error_status) # Update OKR detail too
110
 
 
146
  krs_for_ui_selection_list = extract_key_results_for_selection(actionable_okrs)
147
  krs_for_selection_update_val = krs_for_ui_selection_list # Store for CBG change handler
148
 
149
+ # kr_choices_for_cbg = [(kr['kr_description'], kr['unique_kr_id']) for kr in krs_for_ui_selection_list] # Original
150
+ # If key_results_cbg is Markdown, we don't set choices.
151
+ # We might set its value to a string representation of these KRs, or leave it to be handled by selection logic.
152
+ # For now, setting value to a generic message or empty if it's Markdown.
153
+ # If it were a CBG, value=[] would be appropriate for selection reset.
154
+ # For Markdown, value should be a string.
155
  if self.okrs_components.get("key_results_cbg"):
156
+ # If this component is Markdown, it cannot take choices.
157
+ # Its value should be a string. For now, an empty string or a placeholder.
158
+ # If you want to display the KRs as text, you'd format them here.
159
+ okrs_cbg_update = gr.update(value="Key Results available for selection (display as Markdown)", interactive=True)
160
+ # Example string value if it's Markdown.
161
+ # Or simply value=""
162
 
163
  # Display all OKRs initially (before any KR selection)
164
  all_okrs_md_parts = []
 
178
  final_status_text = "Pipeline AI (Sempre): Nessun risultato prodotto."
179
  if self.report_components.get("agentic_report_display_md"):
180
  report_display_md_update = gr.update(value="Nessun report generato dalla pipeline AI (Sempre).")
181
+
182
+ # If key_results_cbg is Markdown
183
  if self.okrs_components.get("key_results_cbg"):
184
+ okrs_cbg_update = gr.update(value="Nessun Key Result (Markdown display)", interactive=False) # String value
185
+
186
  if self.okrs_components.get("okr_detail_display_md"):
187
  okrs_detail_md_update = gr.update(value="Nessun OKR generato o errore nella pipeline AI (Sempre).")
188
 
 
201
  report_status_md_update = gr.update(value=error_status_text)
202
  if self.report_components.get("agentic_report_display_md"):
203
  report_display_md_update = gr.update(value=f"Errore generazione report AI (Sempre): {str(e)}")
204
+
205
+ # If key_results_cbg is Markdown
206
  if self.okrs_components.get("key_results_cbg"):
207
+ okrs_cbg_update = gr.update(value=f"Errore Key Results (Markdown): {str(e)}", interactive=False) # String value
208
+
209
  if self.okrs_components.get("okr_detail_display_md"):
210
  okrs_detail_md_update = gr.update(value=f"Errore generazione OKR AI (Sempre): {str(e)}")
211
 
 
287
  return
288
 
289
  if self.okrs_components.get("key_results_cbg"):
290
+ # The input 'key_results_cbg' provides the selected IDs.
291
+ # If it's truly a Markdown component now, this .change handler might not behave as expected
292
+ # for selection, as Markdown isn't typically an input component this way.
293
+ # However, the function signature of update_okr_display_on_kr_selection expects selected_kr_unique_ids.
294
+ # This setup might need further review if key_results_cbg is indeed Markdown and meant to be interactive.
295
  self.okrs_components['key_results_cbg'].change(
296
  fn=self.update_okr_display_on_kr_selection,
297
  inputs=[
298
+ self.okrs_components['key_results_cbg'], # Current value of checkbox group (or Markdown if changed)
299
+ self.orchestration_raw_results_st, # State
300
+ self.key_results_for_selection_st # State
301
  ],
302
  outputs=[self.okrs_components['okr_detail_display_md']],
303
  api_name="update_okr_display_on_kr_selection"
 
305
  logging.info("Agentic OKR selection handler setup complete.")
306
  else:
307
  logging.warning("key_results_cbg component not found for agentic OKR handler setup.")