heymenn commited on
Commit
bee2a16
·
verified ·
1 Parent(s): e7e1393

Update kig_core/planner.py

Browse files
Files changed (1) hide show
  1. kig_core/planner.py +38 -38
kig_core/planner.py CHANGED
@@ -156,45 +156,45 @@ def generate_structured_issues(state: PlannerState) -> Dict[str, Any]:
156
 
157
  chain = prompt | issue_llm | output_parser
158
 
159
- try:
160
- structured_issues_obj = invoke_llm(chain, {
161
- "user_query": user_query,
162
- "context": full_context
163
- })
164
- print(f"structured_issues_obj => type : {type(structured_issues_obj)}, value : {structured_issues_obj}")
165
-
166
- # If the output is a dict with a key 'key_issues', extract it
167
- if isinstance(structured_issues_obj, dict) and 'key_issues' in structured_issues_obj:
168
- issues_data = structured_issues_obj['key_issues']
169
- else:
170
- issues_data = structured_issues_obj # Assume it's already a list of dicts
171
-
172
- # Always convert to KeyIssueInvoke objects
173
- key_issues_list = [KeyIssueInvoke(**issue_dict) for issue_dict in issues_data]
174
-
175
- # Ensure IDs are sequential if the LLM didn't assign them correctly
176
- for i, issue in enumerate(key_issues_list):
177
- issue.id = i + 1
178
-
179
- logger.info(f"Successfully generated {len(key_issues_list)} structured key issues.")
180
- final_message = f"Generated {len(key_issues_list)} Key Issues based on the query '{user_query}'."
181
- return {
182
- "key_issues": key_issues_list,
183
- "messages": [AIMessage(content=final_message)],
184
- "error": None
185
- }
186
- except Exception as e:
187
- logger.error(f"Failed to generate or parse structured key issues: {e}", exc_info=True)
188
- # Attempt to get raw output for debugging if possible
189
- raw_output = "Could not retrieve raw output."
190
  try:
191
- raw_chain = prompt | issue_llm | StrOutputParser()
192
- raw_output = invoke_llm(raw_chain, {"user_query": user_query, "context": full_context})
193
- logger.debug(f"Raw output from failed JSON parsing:\n{raw_output}")
194
- except Exception as raw_e:
195
- logger.error(f"Could not even get raw output: {raw_e}")
196
-
197
- return {"error": f"Failed to generate structured key issues: {e}. Raw output hint: {raw_output[:500]}..."}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
 
200
  # --- Conditional Edges ---
 
156
 
157
  chain = prompt | issue_llm | output_parser
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  try:
160
+ structured_issues_obj = invoke_llm(chain, {
161
+ "user_query": user_query,
162
+ "context": full_context
163
+ })
164
+ print(f"structured_issues_obj => type : {type(structured_issues_obj)}, value : {structured_issues_obj}")
165
+
166
+ # If the output is a dict with a key 'key_issues', extract it
167
+ if isinstance(structured_issues_obj, dict) and 'key_issues' in structured_issues_obj:
168
+ issues_data = structured_issues_obj['key_issues']
169
+ else:
170
+ issues_data = structured_issues_obj # Assume it's already a list of dicts
171
+
172
+ # Always convert to KeyIssueInvoke objects
173
+ key_issues_list = [KeyIssueInvoke(**issue_dict) for issue_dict in issues_data]
174
+
175
+ # Ensure IDs are sequential if the LLM didn't assign them correctly
176
+ for i, issue in enumerate(key_issues_list):
177
+ issue.id = i + 1
178
+
179
+ logger.info(f"Successfully generated {len(key_issues_list)} structured key issues.")
180
+ final_message = f"Generated {len(key_issues_list)} Key Issues based on the query '{user_query}'."
181
+ return {
182
+ "key_issues": key_issues_list,
183
+ "messages": [AIMessage(content=final_message)],
184
+ "error": None
185
+ }
186
+ except Exception as e:
187
+ logger.error(f"Failed to generate or parse structured key issues: {e}", exc_info=True)
188
+ # Attempt to get raw output for debugging if possible
189
+ raw_output = "Could not retrieve raw output."
190
+ try:
191
+ raw_chain = prompt | issue_llm | StrOutputParser()
192
+ raw_output = invoke_llm(raw_chain, {"user_query": user_query, "context": full_context})
193
+ logger.debug(f"Raw output from failed JSON parsing:\n{raw_output}")
194
+ except Exception as raw_e:
195
+ logger.error(f"Could not even get raw output: {raw_e}")
196
+
197
+ return {"error": f"Failed to generate structured key issues: {e}. Raw output hint: {raw_output[:500]}..."}
198
 
199
 
200
  # --- Conditional Edges ---