api key configs

This commit is contained in:
Ajay Raj 2023-03-20 20:19:33 -07:00
commit dfb249e13d
5 changed files with 29 additions and 15 deletions

View file

@ -4,4 +4,4 @@ from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("VOCODE_API_KEY")
base_url = os.getenv("VOCODE_BASE_URL", "api.vocode.dev")
base_url = os.getenv("VOCODE_BASE_URL", "api.vocode.dev")

View file

@ -1,4 +1,6 @@
import os
from typing import Optional
import openai
from langchain.prompts import (
ChatPromptTemplate,
MessagesPlaceholder,
@ -16,12 +18,16 @@ class ChatGPTAgent(BaseAgent):
def __init__(
self,
system_prompt: str,
api_key: Optional[str] = None,
initial_message: Optional[str] = None,
model_name: str = "gpt-3.5-turbo",
temperature: float = 0.7,
max_tokens: int = 100,
):
super().__init__(initial_message=initial_message)
openai.api_key = os.getenv("OPENAI_API_KET", api_key)
if not openai.api_key:
raise ValueError("OpenAI API key not provided")
self.prompt = ChatPromptTemplate.from_messages(
[
SystemMessagePromptTemplate.from_template(system_prompt),

View file

@ -1,19 +1,22 @@
import os
from dotenv import load_dotenv
from typing import Optional
import azure.cognitiveservices.speech as speechsdk
from pydub import AudioSegment
from vocode.turn_based.synthesizer.base_synthesizer import BaseSynthesizer
load_dotenv()
class AzureSynthesizer(BaseSynthesizer):
def __init__(self, sampling_rate: int):
def __init__(
self,
sampling_rate: int,
api_key: Optional[str] = None,
region: Optional[str] = None,
):
self.sampling_rate = sampling_rate
speech_config = speechsdk.SpeechConfig(
subscription=os.environ.get("AZURE_SPEECH_KEY"),
region=os.environ.get("AZURE_SPEECH_REGION"),
subscription=os.getenv("AZURE_SPEECH_KEY", api_key),
region=os.getenv("AZURE_SPEECH_REGION", region),
)
if self.sampling_rate == 44100:
speech_config.set_speech_synthesis_output_format(

View file

@ -1,17 +1,18 @@
from typing import Optional
from pydub import AudioSegment
import io
import os
from dotenv import load_dotenv
import openai
from vocode.turn_based.transcriber.base_transcriber import BaseTranscriber
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
class WhisperTranscriber(BaseTranscriber):
def __init__(self, api_key: Optional[str] = None):
openai.api_key = os.getenv("OPENAI_API_KEY", api_key)
if not openai.api_key:
raise ValueError("OpenAI API key not provided")
def transcribe(self, audio_segment: AudioSegment) -> str:
in_memory_wav = io.BytesIO()
audio_segment.export(in_memory_wav, format="wav")