-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_request
executable file
·68 lines (60 loc) · 1.59 KB
/
image_request
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Default values
MODEL="llava"
IMAGE_PATH="./image.jpg"
PROMPT="Describe this image in detail:"
# Function to display usage
usage() {
echo "Usage: $0 [-m MODEL] [-i IMAGE_PATH] [-p PROMPT]"
echo " -m MODEL Specify the model (default: llava)"
echo " -i IMAGE_PATH Specify the path to the image (default: ./image.jpg)"
echo " -p PROMPT Specify the prompt (default: 'Describe this image in detail:')"
echo " -h Display this help message"
exit 1
}
# Parse command line options
while getopts "m:i:p:h" opt; do
case ${opt} in
m )
MODEL=$OPTARG
;;
i )
IMAGE_PATH=$OPTARG
;;
p )
PROMPT=$OPTARG
;;
h )
usage
;;
\? )
usage
;;
esac
done
# Check if image file exists
if [ ! -f "$IMAGE_PATH" ]; then
echo "Error: Image file not found: $IMAGE_PATH"
exit 1
fi
# Encode image to base64
BASE64_IMAGE=$(base64 -w 0 "$IMAGE_PATH")
# Construct and execute the curl command
RESPONSE=$(curl -s http://localhost:11434/api/chat -d '{
"model": "'"$MODEL"'",
"messages": [
{
"role": "user",
"content": "'"$PROMPT"'",
"images": ["'"$BASE64_IMAGE"'"]
}
]
}')
# Extract and print the content using jq
echo "$RESPONSE" | jq -r '.message.content // empty'
# Check if the response was empty
if [ -z "$(echo "$RESPONSE" | jq -r '.message.content // empty')" ]; then
echo "Error: No response received or unable to parse response."
echo "Full response:"
echo "$RESPONSE"
fi