Amazon Bedrock AgentCore exploration, cont'd
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
from bedrock_agentcore import BedrockAgentCoreApp
|
from bedrock_agentcore import BedrockAgentCoreApp
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -35,6 +36,22 @@ app = BedrockAgentCoreApp()
|
|||||||
load_dotenv(override=True)
|
load_dotenv(override=True)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_public_ip():
|
||||||
|
"""Retrieve public IP from AWS metadata service or external service."""
|
||||||
|
try:
|
||||||
|
# Fallback to external service
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get(
|
||||||
|
"https://api.ipify.org", timeout=aiohttp.ClientTimeout(total=5)
|
||||||
|
) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
return await response.text()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def fetch_weather_from_api(params: FunctionCallParams):
|
async def fetch_weather_from_api(params: FunctionCallParams):
|
||||||
await params.result_callback({"conditions": "nice", "temperature": "75"})
|
await params.result_callback({"conditions": "nice", "temperature": "75"})
|
||||||
|
|
||||||
@@ -65,6 +82,14 @@ 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")
|
||||||
|
|
||||||
|
public_ip = await get_public_ip()
|
||||||
|
if public_ip:
|
||||||
|
logger.info(f"Public IP address: {public_ip}")
|
||||||
|
else:
|
||||||
|
logger.warning("Could not retrieve public IP address")
|
||||||
|
|
||||||
|
yield {"status": "initializing", "ip": public_ip}
|
||||||
|
|
||||||
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
|
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
|
||||||
|
|
||||||
tts = CartesiaTTSService(
|
tts = CartesiaTTSService(
|
||||||
@@ -162,13 +187,14 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
|
|
||||||
app.complete_async_task(task_id)
|
app.complete_async_task(task_id)
|
||||||
|
|
||||||
return {"status": "success"}
|
yield {"status": "completed"}
|
||||||
|
|
||||||
|
|
||||||
async def bot(runner_args: RunnerArguments):
|
async def bot(runner_args: RunnerArguments):
|
||||||
"""Bot entry point for running locally and on Pipecat Cloud."""
|
"""Bot entry point for running locally and on Pipecat Cloud."""
|
||||||
transport = await create_transport(runner_args, transport_params)
|
transport = await create_transport(runner_args, transport_params)
|
||||||
await run_bot(transport, runner_args)
|
async for result in run_bot(transport, runner_args):
|
||||||
|
pass # Consume the stream
|
||||||
|
|
||||||
|
|
||||||
@app.entrypoint
|
@app.entrypoint
|
||||||
@@ -179,7 +205,8 @@ async def agentcore_bot(payload, context):
|
|||||||
DailyRunnerArguments(room_url=room_url),
|
DailyRunnerArguments(room_url=room_url),
|
||||||
transport_params,
|
transport_params,
|
||||||
)
|
)
|
||||||
await run_bot(transport, RunnerArguments())
|
async for result in run_bot(transport, RunnerArguments()):
|
||||||
|
yield result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ version = "0.1.0"
|
|||||||
description = "Example for building Pipecat bots deployable to Amazon Bedrock AgentCore"
|
description = "Example for building Pipecat bots deployable to Amazon Bedrock AgentCore"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aiohttp",
|
||||||
"bedrock-agentcore",
|
"bedrock-agentcore",
|
||||||
"pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner]",
|
"pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner]",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
|
aiohttp
|
||||||
bedrock-agentcore
|
bedrock-agentcore
|
||||||
pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner]
|
pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner]
|
||||||
Reference in New Issue
Block a user