-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
205 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"python.formatting.provider": "black", | ||
"python.formatting.provider": "none", | ||
"python.formatting.blackArgs": ["--line-length", "120"], | ||
"python.linting.pylintUseMinimalCheckers": false, | ||
"editor.showUnused": true | ||
"editor.showUnused": true, | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
import logging | ||
import argparse | ||
import tempfile | ||
import os | ||
from llm_convo.agents import OpenAIChat, TerminalInPrintOut | ||
from llm_convo.conversation import run_conversation | ||
|
||
|
||
def main(model): | ||
agent_a = OpenAIChat( | ||
system_prompt="You are a machine learning assistant. Answer the users questions about machine learning with short rhymes. Ask follow up questions when needed to help clarify their question.", | ||
init_phrase="Hello! Welcome to the Machine Learning hotline, how can I help?", | ||
model=model, | ||
) | ||
agent_b = TerminalInPrintOut() | ||
run_conversation(agent_a, agent_b) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--model", type=str, default="gpt-3.5-turbo") | ||
args = parser.parse_args() | ||
main(args.model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
import logging | ||
import argparse | ||
import tempfile | ||
import os | ||
import time | ||
from llm_convo.agents import OpenAIChat, TwilioCaller | ||
from llm_convo.audio_input import get_whisper_model | ||
from llm_convo.twilio_io import TwilioServer | ||
from llm_convo.conversation import run_conversation | ||
from pyngrok import ngrok | ||
|
||
|
||
def main(port, remote_host, start_ngrok): | ||
if start_ngrok: | ||
ngrok_http = ngrok.connect(port) | ||
remote_host = ngrok_http.public_url.split("//")[1] | ||
|
||
static_dir = os.path.join(tempfile.gettempdir(), "twilio_static") | ||
os.makedirs(static_dir, exist_ok=True) | ||
|
||
logging.info(f"Starting server at {remote_host} from local:{port}, serving static content from {static_dir}") | ||
logging.info(f"Set call webhook to https://{remote_host}/incoming-voice") | ||
|
||
tws = TwilioServer(remote_host=remote_host, port=port, static_dir=static_dir) | ||
tws.start() | ||
agent_a = OpenAIChat( | ||
system_prompt="You are a machine learning assistant. Answer the users questions about machine learning with short rhymes. Ask follow up questions when needed to help clarify their question.", | ||
init_phrase="Hello! Welcome to the Machine Learning hotline, how can I help?", | ||
) | ||
|
||
def run_chat(sess): | ||
agent_b = TwilioCaller(sess, thinking_phrase="One moment.") | ||
while not agent_b.session.media_stream_connected(): | ||
time.sleep(0.1) | ||
run_conversation(agent_a, agent_b) | ||
|
||
tws.on_session = run_chat | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.getLogger().setLevel(logging.INFO) | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--preload_whisper", action="store_true") | ||
parser.add_argument("--start_ngrok", action="store_true") | ||
parser.add_argument("--port", type=int, default=8080) | ||
parser.add_argument("--remote_host", type=str, default="localhost") | ||
args = parser.parse_args() | ||
if args.preload_whisper: | ||
get_whisper_model() | ||
main(args.port, args.remote_host, args.start_ngrok) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
import logging | ||
import argparse | ||
import tempfile | ||
import os | ||
import time | ||
import sys | ||
from llm_convo.agents import OpenAIChat, TwilioCaller | ||
from llm_convo.audio_input import get_whisper_model | ||
from llm_convo.twilio_io import TwilioServer | ||
from llm_convo.conversation import run_conversation | ||
from pyngrok import ngrok | ||
|
||
|
||
def main(port, remote_host, start_ngrok, phone_number): | ||
if start_ngrok: | ||
ngrok_http = ngrok.connect(port) | ||
remote_host = ngrok_http.public_url.split("//")[1] | ||
|
||
static_dir = os.path.join(tempfile.gettempdir(), "twilio_static") | ||
os.makedirs(static_dir, exist_ok=True) | ||
|
||
logging.info( | ||
f"Starting server at {remote_host} from local:{port}, serving static content from {static_dir}, will call {phone_number}" | ||
) | ||
logging.info(f"Set call webhook to https://{remote_host}/incoming-voice") | ||
|
||
input(" >>> Press enter to start the call after ensuring the webhook is set. <<< ") | ||
|
||
tws = TwilioServer(remote_host=remote_host, port=port, static_dir=static_dir) | ||
tws.start() | ||
agent_a = OpenAIChat( | ||
system_prompt=""" | ||
You are an ordering bot that is going to call a pizza place an order a pizza. | ||
When you need to say numbers space them out (e.g. 1 2 3) and do not respond with abbreviations. | ||
If they ask for information not known, make something up that's reasonable. | ||
The customer's details are: | ||
* Address: 1234 Candyland Road, Apt 506 | ||
* Credit Card: 1234 5555 8888 9999 (CVV: 010) | ||
* Name: Bob Joe | ||
* Order: 1 large pizza with only pepperoni | ||
""", | ||
init_phrase="Hi, I would like to order a pizza.", | ||
) | ||
|
||
def run_chat(sess): | ||
agent_b = TwilioCaller(sess, thinking_phrase="One moment.") | ||
while not agent_b.session.media_stream_connected(): | ||
time.sleep(0.1) | ||
run_conversation(agent_a, agent_b) | ||
sys.exit(0) | ||
|
||
tws.on_session = run_chat | ||
tws.start_call(phone_number) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.getLogger().setLevel(logging.INFO) | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--phone_number", type=str) | ||
parser.add_argument("--preload_whisper", action="store_true") | ||
parser.add_argument("--start_ngrok", action="store_true") | ||
parser.add_argument("--port", type=int, default=8080) | ||
parser.add_argument("--remote_host", type=str, default="localhost") | ||
args = parser.parse_args() | ||
if args.preload_whisper: | ||
get_whisper_model() | ||
main(args.port, args.remote_host, args.start_ngrok, args.phone_number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
black==23.1.0 | ||
|
||
gTTS | ||
openai | ||
|
||
git+https://github.com/openai/whisper.git | ||
SpeechRecognition | ||
pyaudio | ||
pydub | ||
--extra-index-url https://download.pytorch.org/whl/cu116 | ||
torch | ||
torchaudio | ||
black~=23.1 | ||
gTTS~=2.3 | ||
openai~=0.28 | ||
SpeechRecognition~=3.10 | ||
pyaudio~=0.2 | ||
pydub~=0.25 | ||
pyngrok~=6.1.0 | ||
gevent~=23.9.1 | ||
twilio~=8.8.0 | ||
flask~=2.3 | ||
flask_sock~=0.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters