caption_system_prompt = '''
Your goal is to generate short, descriptive captions for images of items.
You will be provided with an item image and the name of that item and you will output a caption that captures the most important information about the item.
If there are multiple items depicted, refer to the name provided to understand which item you should describe.
Your generated caption should be short (1 sentence), and include only the most important information about the item.
The most important information could be: the type of item, the style (if mentioned), the material or color if especially relevant and/or any distinctive features.
Keep it short and to the point.
'''
def get_caption(img_url, title):
response = client.chat.completions.create(
model="gpt-4o-mini",
temperature=0.2,
max_tokens=300,
messages=[
{
"role": "system",
"content": caption_system_prompt
},
{
"role": "user",
"content": [
{
"type": "text",
"text": title
},
# The content type should be "image_url" to use gpt-4-turbo's vision capabilities
{
"type": "image_url",
"image_url": {
"url": img_url
}
},
],
}
]
)
return response.choices[0].message.content