matinsn2000 commited on
Commit
1cb8b50
·
1 Parent(s): 9f1f56b

Trying to handle the inference generatoin remaining incomplete

Browse files
cloudzy/agents/image_analyzer.py CHANGED
@@ -76,12 +76,20 @@ result: {
76
 
77
  # Try to extract JSON-like dict from model output
78
  try:
79
- if "{" not in text_content or "}" not in text_content:
80
- raise ValueError("Response does not contain valid JSON structure (missing braces)")
81
 
82
  start = text_content.index("{")
83
- end = text_content.rindex("}") + 1
84
- json_str = text_content[start:end]
 
 
 
 
 
 
 
 
85
  result = json.loads(json_str)
86
  except ValueError as ve:
87
  raise ValueError(f"Failed to parse model output: {text_content}\nError: {ve}")
 
76
 
77
  # Try to extract JSON-like dict from model output
78
  try:
79
+ if "{" not in text_content:
80
+ raise ValueError("Response does not contain valid JSON structure (missing opening brace)")
81
 
82
  start = text_content.index("{")
83
+
84
+ # Try to find closing brace
85
+ if "}" not in text_content[start:]:
86
+ # No closing brace found, try adding one
87
+ print(f"[Warning] No closing brace found in response, attempting to add closing brace...")
88
+ json_str = text_content[start:] + "}"
89
+ else:
90
+ end = text_content.rindex("}") + 1
91
+ json_str = text_content[start:end]
92
+
93
  result = json.loads(json_str)
94
  except ValueError as ve:
95
  raise ValueError(f"Failed to parse model output: {text_content}\nError: {ve}")
cloudzy/agents/image_analyzer_2.py CHANGED
@@ -101,14 +101,19 @@ result: {
101
  response_text = str(response) if response is not None else ""
102
 
103
  # Extract JSON part from response
104
- # Look for the pattern: result: { ... }
105
- match = re.search(r'result:\s*(\{[\s\S]*\})', response_text)
106
 
107
  if not match:
108
  raise ValueError(f"Could not find JSON in response: {response_text}")
109
 
110
  json_str = match.group(1)
111
 
 
 
 
 
 
112
  try:
113
  # Parse the JSON string into a dictionary
114
  result_dict = json.loads(json_str)
 
101
  response_text = str(response) if response is not None else ""
102
 
103
  # Extract JSON part from response
104
+ # Look for the pattern: result: { ... } (or { ... if closing brace is missing)
105
+ match = re.search(r'result:\s*(\{[\s\S]*)', response_text)
106
 
107
  if not match:
108
  raise ValueError(f"Could not find JSON in response: {response_text}")
109
 
110
  json_str = match.group(1)
111
 
112
+ # If the extracted JSON doesn't end with }, try adding it
113
+ if not json_str.rstrip().endswith("}"):
114
+ print(f"[Warning] No closing brace found in JSON, attempting to add closing brace...")
115
+ json_str = json_str + "}"
116
+
117
  try:
118
  # Parse the JSON string into a dictionary
119
  result_dict = json.loads(json_str)