Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,15 @@ import re
|
|
| 8 |
API_URL = "https://deployment.datasaur.ai/api/deployment/8/2723/chat/completions"
|
| 9 |
API_TOKEN = os.environ["DATASAUR_API_KEY"]
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def magic_function(input_text):
|
| 12 |
"""
|
| 13 |
Sends text to the Datasaur deployment API and returns the processed text.
|
|
@@ -30,12 +39,9 @@ def magic_function(input_text):
|
|
| 30 |
# This may need adjustment if the API has a different format.
|
| 31 |
content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
content
|
| 36 |
-
content = content.replace("`", "")
|
| 37 |
-
|
| 38 |
-
return content.strip()
|
| 39 |
|
| 40 |
except requests.exceptions.RequestException as e:
|
| 41 |
return f"API Request Error: {e}"
|
|
|
|
| 8 |
API_URL = "https://deployment.datasaur.ai/api/deployment/8/2723/chat/completions"
|
| 9 |
API_TOKEN = os.environ["DATASAUR_API_KEY"]
|
| 10 |
|
| 11 |
+
def extract_suggestion_with_regex(xml_string):
|
| 12 |
+
"""Extract content of <suggestion> tag using regex."""
|
| 13 |
+
pattern = r"<suggestion>(.*?)</suggestion>"
|
| 14 |
+
match = re.search(pattern, xml_string, re.DOTALL)
|
| 15 |
+
if match:
|
| 16 |
+
return match.group(1).strip()
|
| 17 |
+
else:
|
| 18 |
+
raise ValueError("No <suggestion> tag found")
|
| 19 |
+
|
| 20 |
def magic_function(input_text):
|
| 21 |
"""
|
| 22 |
Sends text to the Datasaur deployment API and returns the processed text.
|
|
|
|
| 39 |
# This may need adjustment if the API has a different format.
|
| 40 |
content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
|
| 41 |
|
| 42 |
+
content = extract_suggestion_with_regex(content)
|
| 43 |
+
|
| 44 |
+
return content.strip()
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
except requests.exceptions.RequestException as e:
|
| 47 |
return f"API Request Error: {e}"
|