Spaces:
Sleeping
Sleeping
Update openai_client.py
Browse files- openai_client.py +26 -4
openai_client.py
CHANGED
|
@@ -58,8 +58,19 @@ def refactor_code(code_snippet):
|
|
| 58 |
},
|
| 59 |
],
|
| 60 |
)
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
return "Sorry, an error occurred while refactoring your code. Please try again later."
|
| 65 |
|
|
@@ -146,7 +157,18 @@ def remove_code_errors(code_snippet):
|
|
| 146 |
},
|
| 147 |
],
|
| 148 |
)
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
return "Sorry, an error occurred while removing code errors. Please try again later."
|
|
|
|
| 58 |
},
|
| 59 |
],
|
| 60 |
)
|
| 61 |
+
refactor = response.text if hasattr(response, "text") else str(response)
|
| 62 |
+
|
| 63 |
+
# Check if feedback is a Message object and extract text if necessary
|
| 64 |
+
if hasattr(response, "content") and isinstance(response.content, list):
|
| 65 |
+
refactor = "\n\n".join(
|
| 66 |
+
[
|
| 67 |
+
text_block.text
|
| 68 |
+
for text_block in response.content
|
| 69 |
+
if hasattr(text_block, "text")
|
| 70 |
+
]
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
return refactor
|
| 74 |
except Exception as e:
|
| 75 |
return "Sorry, an error occurred while refactoring your code. Please try again later."
|
| 76 |
|
|
|
|
| 157 |
},
|
| 158 |
],
|
| 159 |
)
|
| 160 |
+
code_errors = response.text if hasattr(response, "text") else str(response)
|
| 161 |
+
|
| 162 |
+
# Check if feedback is a Message object and extract text if necessary
|
| 163 |
+
if hasattr(response, "content") and isinstance(response.content, list):
|
| 164 |
+
code_errors = "\n\n".join(
|
| 165 |
+
[
|
| 166 |
+
text_block.text
|
| 167 |
+
for text_block in response.content
|
| 168 |
+
if hasattr(text_block, "text")
|
| 169 |
+
]
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
return code_errors
|
| 173 |
except Exception as e:
|
| 174 |
return "Sorry, an error occurred while removing code errors. Please try again later."
|