22
22
23
23
24
24
class BedrockResponse :
25
+ """
26
+ Contains the response body, status code, content type, and optional attributes
27
+ for session management and knowledge base configuration.
28
+ """
25
29
def __init__ (
26
30
self ,
27
31
body : Any = None ,
@@ -38,9 +42,6 @@ def __init__(
38
42
self .prompt_session_attributes = prompt_session_attributes
39
43
self .knowledge_bases_configuration = knowledge_bases_configuration
40
44
41
- def is_json (self ) -> bool :
42
- return self .content_type == "application/json"
43
-
44
45
def to_dict (self ) -> dict [str , Any ]:
45
46
return {
46
47
"body" : self .body ,
@@ -53,6 +54,11 @@ def to_dict(self) -> dict[str, Any]:
53
54
54
55
55
56
class BedrockResponseBuilder (ResponseBuilder ):
57
+ """
58
+ Bedrock Response Builder. This builds the response dict to be returned by Lambda when using Bedrock Agents.
59
+
60
+ Since the payload format is different from the standard API Gateway Proxy event, we override the build method.
61
+ """
56
62
@override
57
63
def build (self , event : BedrockAgentEvent , * args ) -> dict [str , Any ]:
58
64
self ._route (event , None )
@@ -89,7 +95,7 @@ def build(self, event: BedrockAgentEvent, *args) -> dict[str, Any]:
89
95
if bedrock_response .prompt_session_attributes :
90
96
response ["promptSessionAttributes" ] = bedrock_response .prompt_session_attributes
91
97
if bedrock_response .knowledge_bases_configuration :
92
- response ["knowledgeBasesConfiguration" ] = bedrock_response .knowledge_bases_configuration # type: ignore
98
+ response ["knowledgeBasesConfiguration" ] = bedrock_response .knowledge_bases_configuration # type: ignore
93
99
94
100
return response
95
101
0 commit comments