Redmind commited on
Commit
29bcfc5
·
verified ·
1 Parent(s): e0721fb

Update chat.py

Browse files
Files changed (1) hide show
  1. chat.py +9 -8
chat.py CHANGED
@@ -338,16 +338,17 @@ def unstructured_text_to_df(text):
338
  # Debugging: Print raw response to check its format
339
  print("Raw Response:", response_content)
340
 
341
- # Try to parse the response as JSON
342
- try:
343
- # Find the JSON-like section and load it
344
- start_index = response_content.find("{")
345
- json_part = response_content[start_index:] # Extract starting from the first '{'
346
- structured_data = json.loads(json_part) # Parse the JSON part
347
 
 
 
 
348
  print("Parsed JSON:", structured_data)
349
- except (json.JSONDecodeError, ValueError) as e:
350
- print(f"Error: {e}")
 
351
 
352
 
353
  # Convert the structured data into a DataFrame
 
338
  # Debugging: Print raw response to check its format
339
  print("Raw Response:", response_content)
340
 
341
+ # Step 1: Extract the JSON part from the markdown
342
+ # Split the response content to isolate the JSON part
343
+ json_part = response_content.split("```json\n")[1].split("\n```")[0]
 
 
 
344
 
345
+ # Step 2: Parse the JSON content
346
+ try:
347
+ structured_data = json.loads(json_part) # Parse the JSON content
348
  print("Parsed JSON:", structured_data)
349
+ except json.JSONDecodeError:
350
+ print("Error: Response content is not valid JSON.")
351
+
352
 
353
 
354
  # Convert the structured data into a DataFrame