Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
* fix: cleanup model respose, exception logic for ami

* fix: changed info to debug on few log statements
  • Loading branch information
quixoticmonk authored Sep 7, 2024
1 parent 8eeb9df commit cde1f25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.1
v0.0.2
24 changes: 18 additions & 6 deletions lambda/runtask_fulfillment/ai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import re

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

analysis_response_text = json.loads(analysis_response["content"][0]["text"])[
"resources"
]
logger.debug("Analysis response: {}".format(analysis_response))

analysis_response_text= clean_response(analysis_response["content"][0]["text"])["resources"]

logger.debug("Analysis response Text: {}".format(analysis_response_text))

#####################################################################
######## Secondly, evaluate AMIs per analysis ########
Expand Down Expand Up @@ -150,9 +153,11 @@ def eval(tf_plan_json):
release_details = GetECSAmisReleases().execute(
tool["input"]["image_ids"]
)
release_details_info = release_details if release_details else "No release notes were found the ami."

tool_result = {
"toolUseId": tool["toolUseId"],
"content": [{"json": {"release_detail": release_details}}],
"content": [{"json": {"release_detail": release_details_info}}],
}

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

else:
return True, "Guardrail inspection skipped"
return True, "Guardrail inspection skipped"

def clean_response(json_str):
# Remove any tags in the format <tag> or </tag>
cleaned_str = re.sub(r'<\/?[\w\s]+>', '', json_str)
last_brace_index = cleaned_str.rfind('}')
cleaned_str = cleaned_str[:last_brace_index + 1]
return json.loads(cleaned_str)
8 changes: 1 addition & 7 deletions lambda/runtask_fulfillment/tools/get_ami_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
ami_data.append({"name": self.get_ami_name_from_id(ami_id), "id": ami_id})

for ami in ami_data:
found_release = False
for release in response_json:
details = markdown_to_json.dictify(release["body"])
for os_name in details.keys():
Expand All @@ -34,7 +33,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
logger.info(
f"Found release notes for {ami['id']}: {ami['name']}"
)
found_release = True
releases_info.append(
{
"ami_id": ami["id"],
Expand All @@ -50,7 +48,6 @@ def get_ecs_amis_releases_info(self, ami_ids):
logger.info(
f"Found release notes for {ami['id']}: {ami['name']}"
)
found_release = True
releases_info.append(
{
"ami_id": ami["id"],
Expand All @@ -63,10 +60,7 @@ def get_ecs_amis_releases_info(self, ami_ids):
}
)
break
if not found_release:
raise Exception(
f"No release notes were found for {ami['id']}: {ami['name']}"
)

return releases_info

def get_ami_name_from_id(self, ami_id):
Expand Down

0 comments on commit cde1f25

Please sign in to comment.