harris1 commited on
Commit
c19f5de
1 Parent(s): b98550c

Update openai_client.py

Browse files
Files changed (1) hide show
  1. openai_client.py +26 -4
openai_client.py CHANGED
@@ -58,8 +58,19 @@ def refactor_code(code_snippet):
58
  },
59
  ],
60
  )
61
- refactored_code = response.choices[0].message.content
62
- return refactored_code
 
 
 
 
 
 
 
 
 
 
 
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
- error_removal_suggestions = response.choices[0].message.content
150
- return error_removal_suggestions
 
 
 
 
 
 
 
 
 
 
 
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."