# Retrieve multimodal chunks with images
CHUNKS=$(curl -s -X POST "${MORPHIK_API_URL}/retrieve/chunks" \
-H "Content-Type: application/json" \
-d '{
"query": "What are the key takeaways?",
"use_colpali": true,
"k": 4,
"filters": {"demo_variant": "multimodal"}
}')
# Build multimodal content (requires jq processing for proper JSON)
# For simplicity, here's a Python example:
cat > query_openai.py << 'EOF'
import os
import json
import requests
chunks = requests.post(
f"{os.environ['MORPHIK_API_URL']}/retrieve/chunks",
json={
"query": os.environ["QUESTION"],
"use_colpali": True,
"k": 4,
"filters": {"demo_variant": "multimodal"}
}
).json()
# Build multimodal message content
content = [{"type": "text", "text": f"Answer using these sources.\n\nQuestion: {os.environ['QUESTION']}"}]
for chunk in chunks:
if chunk.get("download_url") and chunk.get("content_type", "").startswith("image/"):
content.append({
"type": "image_url",
"image_url": {"url": chunk["download_url"]}
})
# Send to OpenAI
response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}"},
json={
"model": "gpt-4o",
"messages": [{"role": "user", "content": content}]
}
)
print(response.json()["choices"][0]["message"]["content"])
EOF
python query_openai.py