Refactoring the bots
This commit is contained in:
@@ -29,7 +29,7 @@ from pipecat.services.deepgram.stt import DeepgramSTTService
|
|||||||
from pipecat.services.llm_service import FunctionCallParams
|
from pipecat.services.llm_service import FunctionCallParams
|
||||||
from pipecat.services.openai.llm import OpenAILLMService
|
from pipecat.services.openai.llm import OpenAILLMService
|
||||||
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
||||||
from pipecat.transports.daily.transport import DailyParams, DailyTransport
|
from pipecat.transports.daily.transport import DailyLogLevel, DailyParams, DailyTransport
|
||||||
|
|
||||||
app = BedrockAgentCoreApp()
|
app = BedrockAgentCoreApp()
|
||||||
|
|
||||||
@@ -82,19 +82,6 @@ transport_params = {
|
|||||||
async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
||||||
logger.info(f"Starting bot")
|
logger.info(f"Starting bot")
|
||||||
|
|
||||||
daily_transport: DailyTransport = transport
|
|
||||||
daily_transport._client._client.set_ice_config(
|
|
||||||
{
|
|
||||||
"iceServers": [
|
|
||||||
{
|
|
||||||
"urls": ["turn:turn.cloudflare.com:3478?transport=tcp"],
|
|
||||||
"username": "YOUR_TURN_USERNAME",
|
|
||||||
"credential": "YOUR_TURN_CREDENTIAL",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
public_ip = await get_public_ip()
|
public_ip = await get_public_ip()
|
||||||
if public_ip:
|
if public_ip:
|
||||||
logger.info(f"Public IP address: {public_ip}")
|
logger.info(f"Public IP address: {public_ip}")
|
||||||
@@ -218,6 +205,26 @@ async def agentcore_bot(payload, context):
|
|||||||
DailyRunnerArguments(room_url=room_url),
|
DailyRunnerArguments(room_url=room_url),
|
||||||
transport_params,
|
transport_params,
|
||||||
)
|
)
|
||||||
|
if isinstance(transport, DailyTransport):
|
||||||
|
transport.set_log_level(DailyLogLevel.Info)
|
||||||
|
turn_username = os.getenv("TURN_USERNAME")
|
||||||
|
turn_credential = os.getenv("TURN_CREDENTIAL")
|
||||||
|
transport._client._client.set_ice_config(
|
||||||
|
{
|
||||||
|
"placement": "replace",
|
||||||
|
"iceServers": [
|
||||||
|
{
|
||||||
|
"urls": [
|
||||||
|
"turn:turn.cloudflare.com:80?transport=tcp",
|
||||||
|
"turns:turn.cloudflare.com:443?transport=tcp",
|
||||||
|
],
|
||||||
|
"username": turn_username,
|
||||||
|
"credential": turn_credential,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
async for result in run_bot(transport, RunnerArguments()):
|
async for result in run_bot(transport, RunnerArguments()):
|
||||||
yield result
|
yield result
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import aioice
|
import aioice
|
||||||
from bedrock_agentcore import BedrockAgentCoreApp
|
from bedrock_agentcore import BedrockAgentCoreApp
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
app = BedrockAgentCoreApp()
|
app = BedrockAgentCoreApp()
|
||||||
|
|
||||||
@@ -79,45 +83,48 @@ def comprehensive_network_test():
|
|||||||
# Test basic UDP connectivity
|
# Test basic UDP connectivity
|
||||||
results["udp_stun"] = test_udp()
|
results["udp_stun"] = test_udp()
|
||||||
|
|
||||||
|
turn_username = os.getenv("TURN_USERNAME")
|
||||||
|
turn_credential = os.getenv("TURN_CREDENTIAL")
|
||||||
|
|
||||||
# TURN test list
|
# TURN test list
|
||||||
turn_servers = [
|
turn_servers = [
|
||||||
(
|
(
|
||||||
"turn.cloudflare.com", # cleaned
|
"turn.cloudflare.com", # cleaned
|
||||||
3478,
|
3478,
|
||||||
"g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0",
|
turn_username,
|
||||||
"d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3",
|
turn_credential,
|
||||||
"udp",
|
"udp",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"turn.cloudflare.com", # cleaned
|
"turn.cloudflare.com", # cleaned
|
||||||
5349,
|
5349,
|
||||||
"g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0",
|
turn_username,
|
||||||
"d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3",
|
turn_credential,
|
||||||
"tcp",
|
"tcp",
|
||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"turn.cloudflare.com", # cleaned
|
"turn.cloudflare.com", # cleaned
|
||||||
443,
|
443,
|
||||||
"g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0",
|
turn_username,
|
||||||
"d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3",
|
turn_credential,
|
||||||
"tcp",
|
"tcp",
|
||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"turn.cloudflare.com", # cleaned
|
"turn.cloudflare.com", # cleaned
|
||||||
80,
|
80,
|
||||||
"g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0",
|
turn_username,
|
||||||
"d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3",
|
turn_credential,
|
||||||
"tcp",
|
"tcp",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"turn.cloudflare.com", # cleaned
|
"turn.cloudflare.com", # cleaned
|
||||||
3478,
|
3478,
|
||||||
"g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0",
|
turn_username,
|
||||||
"d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3",
|
turn_credential,
|
||||||
"tcp",
|
"tcp",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
@@ -180,6 +187,10 @@ def my_agent(payload):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
if os.getenv("PIPECAT_LOCAL_DEV") == "1":
|
||||||
#results = comprehensive_network_test()
|
# Running locally
|
||||||
#print(results)
|
results = comprehensive_network_test()
|
||||||
|
print(results)
|
||||||
|
else:
|
||||||
|
# Running on AgentCore Runtime
|
||||||
|
app.run()
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
OPENAI_API_KEY=...
|
OPENAI_API_KEY=...
|
||||||
DEEPGRAM_API_KEY=...
|
DEEPGRAM_API_KEY=...
|
||||||
CARTESIA_API_KEY=...
|
CARTESIA_API_KEY=...
|
||||||
DAILY_SAMPLE_ROOM_URL=https://<your-domain>.daily.co/<room-name>
|
|
||||||
|
PIPECAT_LOCAL_DEV=...
|
||||||
|
TURN_USERNAME=
|
||||||
|
TURN_CREDENTIAL=
|
||||||
|
|||||||
Reference in New Issue
Block a user