File size: 1,316 Bytes
853a071
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from openai import Client


def get_description_of_image(oa_client: Client, image_url):
    completion = oa_client.chat.completions.create(
                model="gpt-4o-mini",
                messages=[
                    {
                        "role": "system",
                        "content": """
                            You are an image descriptor who will describe images using the Brazilian Portuguese language.
                            This description should be short and to the point, with a maximum of 50 characters, to be placed in the alt tag of an HTML.
                        """ # noqa
                    },
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "text",
                                "text": "What's in this image?"
                            },
                            {
                                "type": "image_url",
                                "image_url": {
                                    "url": f"{image_url}"
                                }
                            }
                        ]
                    }
                ],
                max_tokens=300
    )
    return completion.choices[0].message.content