harris1 commited on
Commit
11e9350
1 Parent(s): bcc709a

Update openai_client.py

Browse files
Files changed (1) hide show
  1. openai_client.py +7 -10
openai_client.py CHANGED
@@ -58,20 +58,17 @@ def refactor_code(code_snippet):
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
- return st.code(refactor, language='python')
75
  except Exception as e:
76
  return "Sorry, an error occurred while refactoring your code. Please try again later."
77
 
 
58
  },
59
  ],
60
  )
 
 
61
  # Check if feedback is a Message object and extract text if necessary
62
  if hasattr(response, "content") and isinstance(response.content, list):
63
+ # Join the text blocks into a single string with line breaks
64
+ refactor = "\n".join(
65
+ [text_block.text for text_block in response.content if hasattr(text_block, "text")]
 
 
 
66
  )
67
+ else:
68
+ refactor = response.text if hasattr(response, "text") else str(response)
69
 
70
+ # Return the formatted string, ensuring it maintains line breaks
71
+ return refactor.strip()
72
  except Exception as e:
73
  return "Sorry, an error occurred while refactoring your code. Please try again later."
74