Trying to invoke agentcore.
This commit is contained in:
@@ -5,12 +5,14 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from http import HTTPMethod
|
from http import HTTPMethod
|
||||||
from typing import Any, Dict, List, Optional, TypedDict, Union
|
from typing import Any, Dict, List, Optional, TypedDict, Union
|
||||||
|
|
||||||
|
import boto3
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import BackgroundTasks, FastAPI, Request, Response
|
from fastapi import BackgroundTasks, FastAPI, Request, Response
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
@@ -30,6 +32,9 @@ app.mount("/client", SmallWebRTCPrebuiltUI)
|
|||||||
# In-memory store of active sessions: session_id -> session info
|
# In-memory store of active sessions: session_id -> session info
|
||||||
active_sessions: Dict[str, Dict[str, Any]] = {}
|
active_sessions: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
|
# Initialize Bedrock client
|
||||||
|
bedrock = boto3.client("bedrock-agent-runtime")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/", include_in_schema=False)
|
@app.get("/", include_in_schema=False)
|
||||||
async def root_redirect():
|
async def root_redirect():
|
||||||
@@ -37,12 +42,23 @@ async def root_redirect():
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/api/offer")
|
@app.post("/api/offer")
|
||||||
async def offer(request: SmallWebRTCRequest):
|
async def offer(request: Request):
|
||||||
"""Handle WebRTC offer requests via SmallWebRTCRequestHandler."""
|
"""Handle WebRTC offer requests via SmallWebRTCRequestHandler."""
|
||||||
print(f"Received offer:{request}")
|
# Parse JSON body (expecting something like {"input": "..."} )
|
||||||
# TODO need to send this to agentcore
|
data = await request.json()
|
||||||
answer = None
|
print(f"Received offer: {data}")
|
||||||
return answer
|
|
||||||
|
response = bedrock.invoke_agent(
|
||||||
|
# TODO: create a custom randon id, maybe based on the pc_id
|
||||||
|
agentId="network_test-11111111",
|
||||||
|
agentAliasId="Network Test Agent",
|
||||||
|
sessionId="user-123456-conversation-11111",
|
||||||
|
inputText=json.dumps({"input": data}),
|
||||||
|
)
|
||||||
|
|
||||||
|
result = response["body"].read().decode("utf-8")
|
||||||
|
|
||||||
|
return {"result": result}
|
||||||
|
|
||||||
|
|
||||||
@app.patch("/api/offer")
|
@app.patch("/api/offer")
|
||||||
|
|||||||
Reference in New Issue
Block a user