Switched voice to litellm

This commit is contained in:
Paul Gauthier 2024-04-18 14:13:26 -07:00
parent cf2a48b21f
commit f1c09ececf
2 changed files with 14 additions and 4 deletions

View file

@ -1,9 +1,11 @@
import os
import re import re
import subprocess import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
import git import git
import openai
from prompt_toolkit.completion import Completion from prompt_toolkit.completion import Completion
from aider import prompts, voice from aider import prompts, voice
@ -547,8 +549,11 @@ class Commands:
"Record and transcribe voice input" "Record and transcribe voice input"
if not self.voice: if not self.voice:
if "OPENAI_API_KEY" not in os.environ:
self.io.tool_error("To use /voice you must provide an OpenAI API key.")
return
try: try:
self.voice = voice.Voice(self.coder.client) self.voice = voice.Voice()
except voice.SoundDeviceError: except voice.SoundDeviceError:
self.io.tool_error( self.io.tool_error(
"Unable to import `sounddevice` and/or `soundfile`, is portaudio installed?" "Unable to import `sounddevice` and/or `soundfile`, is portaudio installed?"
@ -572,7 +577,12 @@ class Commands:
history.reverse() history.reverse()
history = "\n".join(history) history = "\n".join(history)
try:
text = self.voice.record_and_transcribe(history, language=self.voice_language) text = self.voice.record_and_transcribe(history, language=self.voice_language)
except openai.OpenAIError as err:
self.io.tool_error(f"Unable to use OpenAI whisper model: {err}")
return
if text: if text:
self.io.add_to_input_history(text) self.io.add_to_input_history(text)
print() print()

View file

@ -3,6 +3,7 @@ import queue
import tempfile import tempfile
import time import time
import litellm
import numpy as np import numpy as np
try: try:
@ -86,9 +87,8 @@ class Voice:
while not self.q.empty(): while not self.q.empty():
file.write(self.q.get()) file.write(self.q.get())
# TODO: fix client!
with open(filename, "rb") as fh: with open(filename, "rb") as fh:
transcript = self.client.audio.transcriptions.create( transcript = litellm.transcription(
model="whisper-1", file=fh, prompt=history, language=language model="whisper-1", file=fh, prompt=history, language=language
) )