This commit is contained in:
Paul Gauthier 2023-04-08 14:14:30 -07:00
parent 2fbf57e22c
commit 9d7643bacb

View file

@ -237,10 +237,28 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
temperature=0, temperature=0,
stream = True, stream = True,
) )
resp = []
if show_progress: if show_progress:
return self.show_send_progress(completion)
else:
return self.show_send_output(completion)
def show_send_progress(self, completion):
resp = []
pbar = tqdm(total = show_progress) pbar = tqdm(total = show_progress)
for chunk in completion:
try:
text = chunk.choices[0].delta.content
resp.append(text)
except AttributeError:
continue
pbar.update(len(text))
resp = ''.join(resp)
return resp
def show_send_output(self, completion):
resp = []
for chunk in completion: for chunk in completion:
try: try:
@ -248,16 +266,10 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
resp.append(text) resp.append(text)
except AttributeError: except AttributeError:
continue continue
if show_progress:
pbar.update(len(text))
else:
sys.stdout.write(text) sys.stdout.write(text)
sys.stdout.flush() sys.stdout.flush()
if show_progress:
pbar.update(show_progress)
pbar.close()
resp = ''.join(resp) resp = ''.join(resp)
return resp return resp