Skip to content

Made some properties of Bedrock's Event optional. #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lambda-events/src/event/bedrock_agent_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ pub struct AgentEvent {
/// The method of the API operation, as defined in the OpenAPI schema.
pub http_method: String,
/// Contains a list of objects. Each object contains the name, type, and value of a parameter in the API operation, as defined in the OpenAPI schema.
pub parameters: Vec<Parameter>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<Vec<Parameter>>,
/// Contains the request body and its properties, as defined in the OpenAPI schema.
pub request_body: RequestBody,
#[serde(skip_serializing_if = "Option::is_none")]
pub request_body: Option<RequestBody>,
/// Contains session attributes and their values.
pub session_attributes: HashMap<String, String>,
/// Contains prompt attributes and their values.
Expand Down Expand Up @@ -91,4 +93,22 @@ mod tests {
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "bedrock-agent-runtime")]
fn example_bedrock_agent_runtime_event_without_parameters() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "bedrock-agent-runtime")]
fn example_bedrock_agent_runtime_event_without_request_body() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"messageVersion": "1.0",
"agent": {
"name": "AgentName",
"id": "AgentID",
"alias": "AgentAlias",
"version": "AgentVersion"
},
"inputText": "InputText",
"sessionId": "SessionID",
"actionGroup": "ActionGroup",
"apiPath": "/api/path",
"httpMethod": "POST",
"requestBody": {
"content": {
"application/json": {
"properties": [
{
"name": "prop1",
"type": "string",
"value": "value1"
}
]
}
}
},
"sessionAttributes": {
"attr1": "value1"
},
"promptSessionAttributes": {
"promptAttr1": "value1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"messageVersion": "1.0",
"agent": {
"name": "AgentName",
"id": "AgentID",
"alias": "AgentAlias",
"version": "AgentVersion"
},
"inputText": "InputText",
"sessionId": "SessionID",
"actionGroup": "ActionGroup",
"apiPath": "/api/path",
"httpMethod": "POST",
"parameters": [
{
"name": "param1",
"type": "string",
"value": "value1"
}
],
"sessionAttributes": {
"attr1": "value1"
},
"promptSessionAttributes": {
"promptAttr1": "value1"
}
}