Skip to content

Instantly share code, notes, and snippets.

@saahityaedams
Created October 21, 2024 04:27
Show Gist options
  • Select an option

  • Save saahityaedams/d0a94380d5670b465a6e627f5e23ea26 to your computer and use it in GitHub Desktop.

Select an option

Save saahityaedams/d0a94380d5670b465a6e627f5e23ea26 to your computer and use it in GitHub Desktop.
# wrapper for calling LLM with an image
# eg. make_moondream_ollama_request /tmp/out.jpeg "is the image black and white ? "
# eg. make_moondream_ollama_request /tmp/out.jpeg
make_moondream_ollama_request() {
local file_path=$1
local model="moondream"
local prompt=${2:-"Describe the image?"}
local api_url="http://localhost:11434/api/generate"
# Generate base64 string without newlines
base64_string=$(base64 -w 0 "$file_path")
# Perform the curl request
curl -s "$api_url" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$model"'",
"prompt": "'"$prompt"'",
"stream": false,
"images": ["'"$base64_string"'"]
}' | jq .response
}
@saahityaedams
Copy link
Author

saahityaedams commented Oct 21, 2024

TODO

  • Support url instead of filepath
  • Print a tiny preview of image in terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment