mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
progress bar for gpt editing
This commit is contained in:
parent
6b0f9e1afb
commit
099ace0836
1 changed files with 15 additions and 6 deletions
17
coder.py
17
coder.py
|
@ -9,6 +9,7 @@ import random
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import readline
|
import readline
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -211,9 +212,9 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
print(err)
|
print(err)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def send(self, messages):
|
def send(self, messages, show_progress = 0):
|
||||||
for msg in messages:
|
#for msg in messages:
|
||||||
dump(msg)
|
# dump(msg)
|
||||||
|
|
||||||
completion = openai.ChatCompletion.create(
|
completion = openai.ChatCompletion.create(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
|
@ -223,12 +224,19 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
stream = True,
|
stream = True,
|
||||||
)
|
)
|
||||||
resp = []
|
resp = []
|
||||||
|
|
||||||
|
if show_progress:
|
||||||
|
pbar = tqdm(total = show_progress)
|
||||||
|
|
||||||
for chunk in completion:
|
for chunk in completion:
|
||||||
try:
|
try:
|
||||||
text = chunk.choices[0].delta.content
|
text = chunk.choices[0].delta.content
|
||||||
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()
|
||||||
|
|
||||||
|
@ -294,7 +302,8 @@ Just the content of the file!
|
||||||
dict(role = 'system', content = sys_prompt),
|
dict(role = 'system', content = sys_prompt),
|
||||||
dict(role = 'user', content = prompt),
|
dict(role = 'user', content = prompt),
|
||||||
]
|
]
|
||||||
res = self.send(messages)
|
res = self.send(messages, show_progress = len(content))
|
||||||
|
|
||||||
res = res.splitlines()
|
res = res.splitlines()
|
||||||
if res[0].strip == str(fname):
|
if res[0].strip == str(fname):
|
||||||
res = res[1:]
|
res = res[1:]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue