Skip to content

Commit da3dba0

Browse files
committed
Add additional safety checks.
1 parent 8e25447 commit da3dba0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/agent.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,14 @@ def rename_variable(self, response: str) -> None:
189189
raise TypeError('No instruction was saved in the Agent instance.')
190190
if response is None or response == '':
191191
raise TypeError(f'No response was returned from OpenAI; got type {type(response)}.')
192-
# Get just one word from the response.
193-
response = response.split()[0]
192+
# Get just one word from the response. Remove spaces and quotes.
193+
try:
194+
response = response.split()[0]
195+
response = response.replace(' ', '')
196+
response = response.replace('"', '')
197+
response = response.replace('\'', '')
198+
except IndexError as error:
199+
raise IndexError(f'Could not split the response: `{response}`.') from error
194200
# Assign the variable name to the response.
195201
log.log_debug(f'Renaming variable in expression {self.instruction} to {response}.')
196202
self.instruction.dest.name = response

0 commit comments

Comments
 (0)