Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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
|
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 |
-
|
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}"
|