¿Es GitHub Copilot una bendición o una maldición?

Recorrido

def tar_dir(dir, dest):
"Tar and optionally compress directory `dir` to `dest` in bz2, xz, or gzip format"
if dest.endswith('.bz2'):
with tarfile.open(dest,'w:bz2') as f: f.add(dir, arcname=os.path.basename(dir))
elif dest.endswith('.xz'):
with tarfile.open(dest,'w:xz') as f: f.add(dir, arcname=os.path.basename(dir))
elif dest.endswith('.gz'):
with tarfile.open(dest,'w:gz') as f: f.add(dir, arcname=os.path.basename(dir))
else: raise ValueError('bad dest: {}'.format(dest))
with TemporaryDirectory() as tmp:
write_text(os.path.join(tmp,'a.txt'),'hello')
write_text(os.path.join(tmp,'b.txt'),'world')
tar_dir(tmp,'out.tar.bz2')
assert os.path.exists('out.tar.bz2')
with tarfile.open('out.tar.bz2') as f:
assert f.getnames()==['a.txt','b.txt']

Problemas de código

def tar_dir(dir, dest):
"Tar and optionally compress directory `dir` to `dest` in bz2, xz, or gzip format"
suf = ':' + Path(dest).suffix[1:]
if suf==':tar': suf=''
with tarfile.open(dest,f'w{suf}') as f: f.add(dir, arcname=dir)

Por qué Copilot escribe código incorrecto

Los problemas con el código generado automáticamente

def finetune(folder, model):
"""fine tune pytorch model using images from folder and report results on validation set"""

Analizar Python con una expresión regular

code_str = """def connect(
host:str, # host to connect to
port:int=80, # port to connect to
ssl:bool=True, # whether to use SSL
) -> socket.socket: # the connected socket
"""
# regex to extract comments from strings looking like code_str
comment_re = re.compile(r'^\s*#.*$', re.MULTILINE)
code_str = """def find_tags(
input_str:str, # the string to search for tags
tag_prefix:str="#" # prefix marking the start of a tag
) -> List[str]: # list of all tags found

Programación de par de IA y sesgo cognitivo

Ejemplos de uso de Stack Overflow, Google y API

Conclusiones

--

--

bootcampai.org

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store