Skip to content

Commit cde1f25

Browse files
authored
v0.0.2
* fix: cleanup model respose, exception logic for ami * fix: changed info to debug on few log statements
1 parent 8eeb9df commit cde1f25

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.1
1+
v0.0.2

lambda/runtask_fulfillment/ai.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34

45
import boto3
56
import botocore
@@ -35,7 +36,7 @@ def eval(tf_plan_json):
3536
List the resources that will be created, modified or deleted in the following terraform plan using the following rules:
3637
1. Think step by step using the "thinking" json field
3738
2. For AMI changes, include the old and new AMI ID
38-
3. Use the following schema
39+
3. Use the following schema. Skip the preamble:
3940
<schema>
4041
{
4142
"$id": "https://example.com/arrays.schema.json",
@@ -85,9 +86,11 @@ def eval(tf_plan_json):
8586
bedrock_client, model_id, messages, system_text
8687
)
8788

88-
analysis_response_text = json.loads(analysis_response["content"][0]["text"])[
89-
"resources"
90-
]
89+
logger.debug("Analysis response: {}".format(analysis_response))
90+
91+
analysis_response_text= clean_response(analysis_response["content"][0]["text"])["resources"]
92+
93+
logger.debug("Analysis response Text: {}".format(analysis_response_text))
9194

9295
#####################################################################
9396
######## Secondly, evaluate AMIs per analysis ########
@@ -150,9 +153,11 @@ def eval(tf_plan_json):
150153
release_details = GetECSAmisReleases().execute(
151154
tool["input"]["image_ids"]
152155
)
156+
release_details_info = release_details if release_details else "No release notes were found the ami."
157+
153158
tool_result = {
154159
"toolUseId": tool["toolUseId"],
155-
"content": [{"json": {"release_detail": release_details}}],
160+
"content": [{"json": {"release_detail": release_details_info}}],
156161
}
157162

158163
tool_result_message = {
@@ -257,4 +262,11 @@ def guardrail_inspection(input_text, input_mode = 'OUTPUT'):
257262
return True, "No Guardrail action required"
258263

259264
else:
260-
return True, "Guardrail inspection skipped"
265+
return True, "Guardrail inspection skipped"
266+
267+
def clean_response(json_str):
268+
# Remove any tags in the format <tag> or </tag>
269+
cleaned_str = re.sub(r'<\/?[\w\s]+>', '', json_str)
270+
last_brace_index = cleaned_str.rfind('}')
271+
cleaned_str = cleaned_str[:last_brace_index + 1]
272+
return json.loads(cleaned_str)

lambda/runtask_fulfillment/tools/get_ami_releases.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
2424
ami_data.append({"name": self.get_ami_name_from_id(ami_id), "id": ami_id})
2525

2626
for ami in ami_data:
27-
found_release = False
2827
for release in response_json:
2928
details = markdown_to_json.dictify(release["body"])
3029
for os_name in details.keys():
@@ -34,7 +33,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
3433
logger.info(
3534
f"Found release notes for {ami['id']}: {ami['name']}"
3635
)
37-
found_release = True
3836
releases_info.append(
3937
{
4038
"ami_id": ami["id"],
@@ -50,7 +48,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
5048
logger.info(
5149
f"Found release notes for {ami['id']}: {ami['name']}"
5250
)
53-
found_release = True
5451
releases_info.append(
5552
{
5653
"ami_id": ami["id"],
@@ -63,10 +60,7 @@ def get_ecs_amis_releases_info(self, ami_ids):
6360
}
6461
)
6562
break
66-
if not found_release:
67-
raise Exception(
68-
f"No release notes were found for {ami['id']}: {ami['name']}"
69-
)
63+
7064
return releases_info
7165

7266
def get_ami_name_from_id(self, ami_id):

0 commit comments

Comments
 (0)