generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 463
Open
Labels
feature-requestfeature requestfeature requesttriagePending triage from maintainersPending triage from maintainers
Description
Use case
Are there any plans to support response streaming for Api Gateway resolver?
It was introduced a week ago, ref. Amazon API Gateway now supports response streaming for REST APIs
Solution/User Experience
Equivalent of this fastapi sample code
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from strands import Agent
import asyncio
import json
app = FastAPI()
strands_agent = Agent(
model="us.amazon.nova-lite-v1:0",
system_prompt="You are a helpful AI assistant.",
)
# Based on https://aws.amazon.com/blogs/opensource/introducing-strands-agents-1-0-production-ready-multi-agent-orchestration-made-simple/
async def streamer(request: str):
async for event in strands_agent.stream_async(request):
if "data" in event:
yield event['data']
@app.get("/{request_path:path}")
async def catch_all(request: Request, request_path: str):
# Catch-all route to handle all GET requests
return
@app.post("/{request_path:path}")
async def index(request: Request):
# Get the JSON payload from the POST body
body = await request.body()
payload = json.loads(body.decode('utf-8'))
request_param = payload.get("request")
return StreamingResponse(streamer(request_param))Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Metadata
Metadata
Assignees
Labels
feature-requestfeature requestfeature requesttriagePending triage from maintainersPending triage from maintainers
Type
Projects
Status
Triage