datasaur-dev commited on
Commit
3c6b3a3
·
verified ·
1 Parent(s): 5271f8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -25,14 +25,14 @@ def extract_suggestion_value(text):
25
  try:
26
  parsed = json.loads(text)
27
  if "suggestion" in parsed:
28
- return {"suggestion": parsed["suggestion"]}
29
  except json.JSONDecodeError:
30
  pass # Fall back to regex if not valid JSON
31
 
32
  # Fallback: use regex to extract suggestion value
33
  match = re.search(r'"suggestion"\s*:\s*"([^"]+)"', text)
34
  if match:
35
- return {"suggestion": match.group(1)}
36
 
37
  return None
38
 
@@ -59,15 +59,9 @@ def magic_function(input_text):
59
  # This may need adjustment if the API has a different format.
60
  content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
61
 
62
- print(content)
63
-
64
  content = extract_suggestion_value(content)
65
 
66
- print("----")
67
-
68
- print(content)
69
-
70
- return content
71
 
72
  except requests.exceptions.RequestException as e:
73
  return f"API Request Error: {e}"
 
25
  try:
26
  parsed = json.loads(text)
27
  if "suggestion" in parsed:
28
+ return parsed["suggestion"]
29
  except json.JSONDecodeError:
30
  pass # Fall back to regex if not valid JSON
31
 
32
  # Fallback: use regex to extract suggestion value
33
  match = re.search(r'"suggestion"\s*:\s*"([^"]+)"', text)
34
  if match:
35
+ return match.group(1)
36
 
37
  return None
38
 
 
59
  # This may need adjustment if the API has a different format.
60
  content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
61
 
 
 
62
  content = extract_suggestion_value(content)
63
 
64
+ return content.strip()
 
 
 
 
65
 
66
  except requests.exceptions.RequestException as e:
67
  return f"API Request Error: {e}"