def understand_image_with_gpt()

in seed/util/preprocess.py [0:0]


def understand_image_with_gpt(client, deployment_name, image_path, caption="", max_tokens=1024, language="Korean"):

    data_url = local_image_to_data_url(image_path)
    if caption == "":
        prompt = f"Describe this image in {language} language. " 
    else: 
        prompt = f"Describe this image in {language} language (note: it has image caption: {caption})."

    response = client.chat.completions.create(
            model=deployment_name,
            messages=[
                { "role": "system", "content": "You are a helpful assistant." },
                { "role": "user", "content": [  
                    { 
                        "type": "text", 
                        "text": prompt
                    },
                    { 
                        "type": "image_url",
                        "image_url": {
                            "url": data_url
                        }
                    }
                ] } 
            ],
            max_tokens=max_tokens
        )

    img_description = response.choices[0].message.content
    
    return img_description