mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
pass the input history as a prompt to whisper
This commit is contained in:
parent
9815d14368
commit
b6b271b70c
3 changed files with 30 additions and 5 deletions
|
@ -442,7 +442,25 @@ class Commands:
|
||||||
self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?")
|
self.io.tool_error("Unable to import `sounddevice`, is portaudio installed?")
|
||||||
return
|
return
|
||||||
|
|
||||||
text = v.record_and_transcribe()
|
history_iter = self.io.get_input_history()
|
||||||
|
|
||||||
|
history = []
|
||||||
|
size = 0
|
||||||
|
for line in history_iter:
|
||||||
|
if line.startswith("/"):
|
||||||
|
continue
|
||||||
|
if line in history:
|
||||||
|
continue
|
||||||
|
if size + len(line) > 1024:
|
||||||
|
break
|
||||||
|
size += len(line)
|
||||||
|
history.append(line)
|
||||||
|
|
||||||
|
history.reverse()
|
||||||
|
history = "\n".join(history)
|
||||||
|
dump(history)
|
||||||
|
|
||||||
|
text = v.record_and_transcribe(history)
|
||||||
if text:
|
if text:
|
||||||
self.io.add_to_input_history(text)
|
self.io.add_to_input_history(text)
|
||||||
print()
|
print()
|
||||||
|
|
|
@ -236,6 +236,13 @@ class InputOutput:
|
||||||
return
|
return
|
||||||
FileHistory(self.input_history_file).append_string(inp)
|
FileHistory(self.input_history_file).append_string(inp)
|
||||||
|
|
||||||
|
def get_input_history(self):
|
||||||
|
if not self.input_history_file:
|
||||||
|
return []
|
||||||
|
|
||||||
|
fh = FileHistory(self.input_history_file)
|
||||||
|
return fh.load_history_strings()
|
||||||
|
|
||||||
def user_input(self, inp, log_only=True):
|
def user_input(self, inp, log_only=True):
|
||||||
if not log_only:
|
if not log_only:
|
||||||
style = dict(style=self.user_input_color) if self.user_input_color else dict()
|
style = dict(style=self.user_input_color) if self.user_input_color else dict()
|
||||||
|
|
|
@ -54,13 +54,13 @@ class Voice:
|
||||||
dur = time.time() - self.start_time
|
dur = time.time() - self.start_time
|
||||||
return f"Recording, press ENTER when done... {dur:.1f}sec {bar}"
|
return f"Recording, press ENTER when done... {dur:.1f}sec {bar}"
|
||||||
|
|
||||||
def record_and_transcribe(self):
|
def record_and_transcribe(self, history=None):
|
||||||
try:
|
try:
|
||||||
return self.raw_record_and_transcribe()
|
return self.raw_record_and_transcribe(history)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
|
|
||||||
def raw_record_and_transcribe(self):
|
def raw_record_and_transcribe(self, history):
|
||||||
self.q = queue.Queue()
|
self.q = queue.Queue()
|
||||||
|
|
||||||
filename = tempfile.mktemp(suffix=".wav")
|
filename = tempfile.mktemp(suffix=".wav")
|
||||||
|
@ -77,7 +77,7 @@ class Voice:
|
||||||
file.write(self.q.get())
|
file.write(self.q.get())
|
||||||
|
|
||||||
with open(filename, "rb") as fh:
|
with open(filename, "rb") as fh:
|
||||||
transcript = openai.Audio.transcribe("whisper-1", fh)
|
transcript = openai.Audio.transcribe("whisper-1", fh, prompt=history)
|
||||||
|
|
||||||
text = transcript["text"]
|
text = transcript["text"]
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue