diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2023-10-13 19:57:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 19:57:14 -0600 |
commit | 413675d42e4480eeab76d326bd2f706191e836c5 (patch) | |
tree | bc3aa43c748e212f074bc82fa3621a7fbdec13a0 /main.py | |
parent | 2c670084b3ea2628e9b4d874f3b858e7945ed737 (diff) | |
parent | b919f2dcabc8dcba41f7e309b2d4eccd8cc0d87e (diff) |
Merge pull request #1 from navanchauhan/deepgram-stt
ooga chaga
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -0,0 +1,74 @@ +import logging +import os +from fastapi import FastAPI +from vocode.streaming.models.telephony import TwilioConfig +from pyngrok import ngrok +from vocode.streaming.telephony.config_manager.redis_config_manager import ( + RedisConfigManager, +) +from vocode.streaming.models.agent import ChatGPTAgentConfig +from vocode.streaming.models.message import BaseMessage +from vocode.streaming.models.synthesizer import ElevenLabsSynthesizerConfig +from vocode.streaming.telephony.server.base import ( + TwilioInboundCallConfig, + TelephonyServer, +) + +from speller_agent import SpellerAgentFactory +import sys + +# if running from python, this will load the local .env +# docker-compose will load the .env file by itself +from dotenv import load_dotenv + +load_dotenv() + +app = FastAPI(docs_url=None) + +logging.basicConfig() +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +config_manager = RedisConfigManager() + +BASE_URL = os.getenv("BASE_URL") + +if not BASE_URL: + ngrok_auth = os.environ.get("NGROK_AUTH_TOKEN") + if ngrok_auth is not None: + ngrok.set_auth_token(ngrok_auth) + port = sys.argv[sys.argv.index("--port") + 1] if "--port" in sys.argv else 6789 + + # Open a ngrok tunnel to the dev server + BASE_URL = ngrok.connect(port).public_url.replace("https://", "") + logger.info('ngrok tunnel "{}" -> "http://127.0.0.1:{}"'.format(BASE_URL, port)) + +if not BASE_URL: + raise ValueError("BASE_URL must be set in environment if not using pyngrok") + +telephony_server = TelephonyServer( + base_url=BASE_URL, + config_manager=config_manager, + inbound_call_configs=[ + TwilioInboundCallConfig( + url="/inbound_call", + agent_config=ChatGPTAgentConfig( + initial_message=BaseMessage(text="What up"), + prompt_preamble="Have a pleasant conversation about life", + generate_responses=True, + ), + twilio_config=TwilioConfig( + account_sid=os.environ["TWILIO_ACCOUNT_SID"], + auth_token=os.environ["TWILIO_AUTH_TOKEN"], + ), + synthesizer_config=ElevenLabsSynthesizerConfig.from_telephone_output_device( + api_key=os.getenv("ELEVENLABS_API_KEY"), + voice_id=os.getenv("YOUR VOICE ID") + ) + ) + ], + agent_factory=SpellerAgentFactory(), + logger=logger, +) + +app.include_router(telephony_server.get_router())
\ No newline at end of file |