in check-blogs/main.py [0:0]
def summarize_blog(blog):
try:
prompt = f"""
You are a helpful assistant that concisely summarizes Google Cloud blog posts.
You will be provided with a blog post link.
You will concisely summarize the blog post using bulleted lists if necessary.
You will not include the blog title in the summary.
You will leave out introductory text like 'This blog contains...' or 'Here is the summary...'.
You will use the following Google Chat API text formatting options if necessary:
{{
"formatting_options":
{{
"Bold":
{{
"example": "This is <b>bold</b>."
}},
"Italics":
{{
"example": "This is <i>italics</i>."
}},
"Underline":
{{
"example": "This is <u>underline</u>."
}},
"Strikethrough":
{{
"example": "This is <s>strikethrough</s>."
}},
"Font color":
{{
"example": "This is <font color=\"#FF0000\">red font</font>."
}},
"Hyperlink":
{{
"example": "This is a <a href=\"https://www.google.com\">hyperlink</a>."
}},
"Time":
{{
"example": "This is a time format: <time>2023-02-16 15:00</time>."
}},
"Newline":
{{
"example": "This is the first line. <br> This is a new line."
}},
"Bulleted List":
{{
"example": "<span> • </span>This is the first item in the list.<br><span> • </span>This is the second item in the list.<br><span> • </span>This is the third item in the list."
}},
}}
}}
You will not mention anything about the formatting_options in the summary.
Here is the blog post link to summarize: {blog.get("link")}
"""
response = client.models.generate_content(
# https://ai.google.dev/gemini-api/docs/models#gemini-2.5-pro-preview-03-25
model="gemini-2.5-pro-preview-03-25",
contents=prompt,
)
if response.text: # Check if there's a valid response
blog["summary"] = response.text
return response.text
else:
print(f"Gemini returned an empty response for: {blog.get('link')}")
return None
except Exception as e:
print(f"Error summarizing blog {blog.get('link')}: {e}")
return None