Skip to content

Commit

Permalink
fix: api_base, api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
EndangeredF1sh committed Oct 23, 2024
1 parent de70d9a commit ee51502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __pycache__
*.pyc
*.pyo
*.swp
.env
.env
*.mp3
7 changes: 4 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,10 @@ class Dialogue(BaseModel):
scratchpad: str
dialogue: List[DialogueItem]

def get_mp3(text: str, voice: str, audio_model: str, api_key: str = None) -> bytes:
def get_mp3(text: str, voice: str, audio_model: str, api_key: str = None, api_base: str = None) -> bytes:
client = OpenAI(
api_key=api_key or os.getenv("OPENAI_API_KEY"),
base_url=api_base or os.getenv("OPENAI_BASE_URL"),
)

with client.audio.speech.with_streaming_response.create(
Expand All @@ -515,7 +516,7 @@ def conditional_llm(model, api_base=None, api_key=None):
"""
def decorator(func):
if api_base:
return llm(model=model, api_base=api_base)(func)
return llm(model=model, api_base=api_base, api_key=api_key)(func)
else:
return llm(model=model, api_key=api_key)(func)
return decorator
Expand Down Expand Up @@ -614,7 +615,7 @@ def generate_dialogue(text: str, intro_instructions: str, text_instructions: str
for line in llm_output.dialogue:
transcript_line = f"{line.speaker}: {line.text}"
voice = speaker_1_voice if line.speaker == "speaker-1" else speaker_2_voice
future = executor.submit(get_mp3, line.text, voice, audio_model, openai_api_key)
future = executor.submit(get_mp3, line.text, voice, audio_model, openai_api_key, api_base)
futures.append((future, transcript_line))
characters += len(line.text)

Expand Down

0 comments on commit ee51502

Please sign in to comment.