diff --git a/examples/multi-transport-chatbot/server/Dockerfile b/examples/multi-transport-chatbot/Dockerfile similarity index 100% rename from examples/multi-transport-chatbot/server/Dockerfile rename to examples/multi-transport-chatbot/Dockerfile diff --git a/examples/multi-transport-chatbot/server/README.md b/examples/multi-transport-chatbot/README copy.md similarity index 94% rename from examples/multi-transport-chatbot/server/README.md rename to examples/multi-transport-chatbot/README copy.md index a0dd8064d..0d2d1f6e9 100644 --- a/examples/multi-transport-chatbot/server/README.md +++ b/examples/multi-transport-chatbot/README copy.md @@ -1,4 +1,4 @@ -# Simple Chatbot Server +# Multi-Transport Chatbot Server A Pipecat bot.py file that is built to be deployed to Pipecat Cloud. diff --git a/examples/multi-transport-chatbot/README.md b/examples/multi-transport-chatbot/README.md new file mode 100644 index 000000000..56d1049aa --- /dev/null +++ b/examples/multi-transport-chatbot/README.md @@ -0,0 +1,64 @@ +# Multi-Transport Chatbot for Pipecat and Pipecat Cloud + +This project demonstrates a bot architecture that allows you to use different transports with the same bot, depending on how you run the botfile. This can be really useful for starting with one transport for early development and then transitioning to a different transport in production. + +Here's how to use this bot with each of the supported transports. + +## Step 1: Local development with SmallWebRTCTransport + +To get started, let's run the bot with SmallWebRTCTransport, which makes a direct peer-to-peer WebRTC connection between your browser and the bot. + +```bash +# Start with the standard venv setup: +python3 -m venv venv +source venv/bin/activate +pip install -r requirements.txt + +# Rename the env example and add your keys: +mv example.env .env + +# Now run the included webserver: +python server.py +``` + +Open a browser pointed at `http://localhost:7860` and click the **Connect** button to talk to the bot. + +`server.py` helps set up the WebRTC connection, and then calls the `local_webrtc` function in bot.py with this line of code: + +```python + background_tasks.add_task(local_webrtc, pipecat_connection) +``` + +In `bot.py`, you can see that the `local_webrtc` function creates a `SmallWebRTCTransport` instance and passes it to the `main()` function. + +## Step 2: Local development with Daily + +After step 1, you can run the same bot using the Daily transport. Add a `DAILY_API_KEY` to your .env file. If you have a Daily account already, you can get your API key from https://dashboard.daily.co/developers. If you have a Pipecat Cloud account, you have a Daily API key available at https://pipecat.daily.co//settings/daily. + +Run the bot using a different entrypoint: + +```bash +LOCAL_RUN=1 python bot.py +``` + +This uses the `local_daily()` function in `bot.py`, which creates a `DailyTransport`. + +### Step 3: Deploy to Pipecat Cloud + +This repo already includes a Dockerfile you can use to build an image that works with Pipecat Cloud. You can do it in two steps: + +```bash +./build.sh +pcc deploy + +# Then start a session with your bot +pcc agent start multi-transport-chatbot --use-daily +``` + +This will give you a URL you can open in your browser to talk to the bot using Daily Prebuilt. + +Behind the scenes, Pipecat Cloud loads your botfile and calls its `bot()` function. Since you used the `--use-daily` option, the `args` argument is a `DailySessionArguments` instance that includes the Daily room URL and token, so the bot uses a `DailyTransport`. + +## Step 4: Use a Twilio phone number and websocket + +Follow the [Pipecat Cloud Twilio docs](https://docs.pipecat.daily.co/pipecat-in-production/twilio-mediastreams) to configure a TwiML Bin that points one of your phone numbers to Pipecat Cloud. When you dial that number, Pipecat Cloud will start a session with your bot that includes a `WebsocketArguments` object, so the `bot()` function will start your bot with a `FastAPIWebsocketTransport`. diff --git a/examples/multi-transport-chatbot/server/bot.py b/examples/multi-transport-chatbot/bot.py similarity index 100% rename from examples/multi-transport-chatbot/server/bot.py rename to examples/multi-transport-chatbot/bot.py diff --git a/examples/multi-transport-chatbot/server/build.sh b/examples/multi-transport-chatbot/build.sh similarity index 100% rename from examples/multi-transport-chatbot/server/build.sh rename to examples/multi-transport-chatbot/build.sh diff --git a/examples/multi-transport-chatbot/env.example b/examples/multi-transport-chatbot/env.example new file mode 100644 index 000000000..75852e398 --- /dev/null +++ b/examples/multi-transport-chatbot/env.example @@ -0,0 +1,3 @@ +OPENAI_API_KEY=sk-PL... +CARTESIA_API_KEY=aeb... +GLADIA_API_KEY=54e... \ No newline at end of file diff --git a/examples/multi-transport-chatbot/image.png b/examples/multi-transport-chatbot/image.png new file mode 100644 index 000000000..93814fd1e Binary files /dev/null and b/examples/multi-transport-chatbot/image.png differ diff --git a/examples/multi-transport-chatbot/server/index.html b/examples/multi-transport-chatbot/index.html similarity index 100% rename from examples/multi-transport-chatbot/server/index.html rename to examples/multi-transport-chatbot/index.html diff --git a/examples/multi-transport-chatbot/server/local_runner.py b/examples/multi-transport-chatbot/local_runner.py similarity index 100% rename from examples/multi-transport-chatbot/server/local_runner.py rename to examples/multi-transport-chatbot/local_runner.py diff --git a/examples/multi-transport-chatbot/server/pcc-deploy.toml b/examples/multi-transport-chatbot/pcc-deploy.toml similarity index 100% rename from examples/multi-transport-chatbot/server/pcc-deploy.toml rename to examples/multi-transport-chatbot/pcc-deploy.toml diff --git a/examples/multi-transport-chatbot/server/requirements.txt b/examples/multi-transport-chatbot/requirements.txt similarity index 100% rename from examples/multi-transport-chatbot/server/requirements.txt rename to examples/multi-transport-chatbot/requirements.txt diff --git a/examples/multi-transport-chatbot/server/server.py b/examples/multi-transport-chatbot/server.py similarity index 100% rename from examples/multi-transport-chatbot/server/server.py rename to examples/multi-transport-chatbot/server.py diff --git a/examples/multi-transport-chatbot/server/.gitignore b/examples/multi-transport-chatbot/server/.gitignore deleted file mode 100644 index 0d298d282..000000000 --- a/examples/multi-transport-chatbot/server/.gitignore +++ /dev/null @@ -1,51 +0,0 @@ -# Python -__pycache__/ -*.py[cod] -*$py.class -*.so -.Python -build/ -dist/ -*.egg-info/ -.installed.cfg -*.egg -.pytest_cache/ -.coverage -.coverage.* -.env -.venv -env/ -venv/ -ENV/ -.mypy_cache/ -.dmypy.json -dmypy.json - -# JavaScript/Node.js -node_modules/ -dist/ -dist-ssr/ -*.local -.env.local -.env.development.local -.env.test.local -.env.production.local - -# Logs -logs/ -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - -# Editor/IDE -.vscode/* -!.vscode/extensions.json -.idea/ -*.swp -*.swo -.DS_Store - -# Project specific -runpod.toml \ No newline at end of file diff --git a/examples/multi-transport-chatbot/server/env.example b/examples/multi-transport-chatbot/server/env.example deleted file mode 100644 index 246d16443..000000000 --- a/examples/multi-transport-chatbot/server/env.example +++ /dev/null @@ -1,2 +0,0 @@ -OPENAI_API_KEY=sk-PL... -CARTESIA_API_KEY=aeb... \ No newline at end of file