Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created December 27, 2024 20:16
Show Gist options
  • Select an option

  • Save KyMidd/66d55849e4aa1cb4142082b2919a88db to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/66d55849e4aa1cb4142082b2919a88db to your computer and use it in GitHub Desktop.
def handle_message_event(client, body, say, bedrock_client, app, token):
...
response = ai_request(bedrock_client, conversation)
# Get response
response_body = response["body"].read().decode("utf-8")
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ Response body:", response_body)
# Conver to JSON
response_json = json.loads(response_body)
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ response_json['content']:", response_json["content"])
# Check if response content is empty
if response_json["content"] == []:
print("πŸš€ Response content is empty, setting response_text to blank")
response_text = ""
else:
# There is content in the response, set response_text to the text content
response_text = response_json.get("content", [{}])[0].get("text", "")
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ response_text:", response_text)
# Check if unsupported_file_type_found
if unsupported_file_type_found == True:
# If true, prepend error to response text
response_text = f"> `Error`: Unsupported file type found, please ensure you are sending a supported file type. Supported file types are: images (png, jpeg, gif, webp).\n{
response_text}"
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ Response text after adding errors:", response_text)
# Return response in the thread
say(
# text=f"Oh hi <@{user_id}>!\n\n{response_text}",
text=f"{response_text}",
thread_ts=thread_ts,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment