File size: 949 Bytes
add92ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
# /skills/image_analysis.py

import base64
from groq import Groq

# Function to encode the image
def encode_image(image_file):
    return base64.b64encode(image_file.read()).decode('utf-8')

def get_chat_completion(query, image_file=None):
    client = Groq()

    messages = [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": query},
            ],
        }
    ]

    if image_file:
        base64_image = encode_image(image_file)
        messages[0]["content"].append(
            {
                "type": "image_url",
                "image_url": {
                    "url": f"data:image/jpeg;base64,{base64_image}",
                },
            }
        )

    chat_completion = client.chat.completions.create(
        messages=messages,
        model="llama-3.2-11b-vision-preview",
    )

    return chat_completion.choices[0].message.content