Compare commits

...

1 Commits

Author SHA1 Message Date
Kwindla Hultman Kramer
487f5b47bf ctrl-c for simple-sample.py 2023-12-31 19:35:52 -08:00

View File

@@ -4,6 +4,8 @@ from re import A
import requests import requests
import time import time
import urllib.parse import urllib.parse
import signal
from dailyai.async_processor.async_processor import ( from dailyai.async_processor.async_processor import (
LLMResponse, LLMResponse,
@@ -14,7 +16,15 @@ from dailyai.message_handler.message_handler import MessageHandler
from dailyai.services.ai_services import AIServiceConfig from dailyai.services.ai_services import AIServiceConfig
from dailyai.services.azure_ai_services import AzureImageGenService, AzureTTSService, AzureLLMService from dailyai.services.azure_ai_services import AzureImageGenService, AzureTTSService, AzureLLMService
orchestrator = None
message_handler = None
services = None
def add_bot_to_room(room_url, token, expiration) -> None: def add_bot_to_room(room_url, token, expiration) -> None:
global orchestrator
global message_handler
global services
# A simple prompt for a simple sample. # A simple prompt for a simple sample.
message_handler = MessageHandler( message_handler = MessageHandler(
@@ -51,24 +61,37 @@ def add_bot_to_room(room_url, token, expiration) -> None:
expiration=expiration, expiration=expiration,
) )
# khk note: my expectation was that we'd join the Daily session below
# when we call orchestrator.start(), but we actually join it here.
#
orchestrator = Orchestrator( orchestrator = Orchestrator(
orchestrator_config, orchestrator_config,
services, services,
message_handler, message_handler,
) )
orchestrator.start()
orchestrator.start()
print("simple-sample.py should be finished now")
def keyboard_interrupt_handler(signal, frame):
print("keyboard interrupt handler: shutting down gracefully")
orchestrator.stop()
orchestrator.participant_left = True
print("we called orchestrator.stop() and set participant_left to True")
# When the orchestrator's done, we need to shut it down, # When the orchestrator's done, we need to shut it down,
# and the various services and handlers we've created. # and the various services and handlers we've created.
orchestrator.stop()
message_handler.shutdown() message_handler.shutdown()
services.tts.close() services.tts.close()
services.llm.close() services.llm.close()
print("we got past services.llm.close()")
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Simple Daily Bot Sample") parser = argparse.ArgumentParser(description="Simple Daily Bot Sample")
parser.add_argument("-u", "--url", type=str, required=True, help="URL of the Daily room") parser.add_argument("-u", "--url", type=str,
required=True, help="URL of the Daily room")
parser.add_argument( parser.add_argument(
"-k", "--apikey", type=str, required=True, help="Daily API Key (needed to create token)" "-k", "--apikey", type=str, required=True, help="Daily API Key (needed to create token)"
) )
@@ -88,8 +111,10 @@ if __name__ == "__main__":
) )
if res.status_code != 200: if res.status_code != 200:
raise Exception(f'Failed to create meeting token: {res.status_code} {res.text}') raise Exception(
f'Failed to create meeting token: {res.status_code} {res.text}')
token: str = res.json()['token'] token: str = res.json()['token']
signal.signal(signal.SIGINT, keyboard_interrupt_handler)
add_bot_to_room(args.url, token, expiration) add_bot_to_room(args.url, token, expiration)