diff --git a/examples/openai-htr/Dockerfile b/examples/openai-htr/Dockerfile index 6b0ee50..ffb1eab 100644 --- a/examples/openai-htr/Dockerfile +++ b/examples/openai-htr/Dockerfile @@ -8,12 +8,12 @@ SHELL ["/bin/ash", "-o", "pipefail", "-c"] # hadolint ignore=DL3018 RUN --mount=type=bind,from=imagemagick,source=/packages,target=/packages \ --mount=type=bind,from=imagemagick,source=/etc/apk/keys,target=/etc/apk/keys \ - apk add --no-cache /packages/imagemagick-*.apk + apk add --no-cache /packages/imagemagick-*.apk jq==1.7.1-r0 RUN magick -list format | grep "JPEG-2000" ENV OPENAI_MODEL=gpt-4o-mini \ - PROMPT="Transcribe this image that contains handwritten text. Include all text you see in the image. In your response, say absolutely nothing except the text from the image" \ + PROMPT="Transcribe this image that contains handwritten text. Include all text you see in the image. In your response, say absolutely nothing except the text from the image." \ MAX_TOKENS=300 COPY scyllaridae.yml /app/scyllaridae.yml diff --git a/examples/openai-htr/cmd.sh b/examples/openai-htr/cmd.sh index b2a1dde..676fc13 100755 --- a/examples/openai-htr/cmd.sh +++ b/examples/openai-htr/cmd.sh @@ -9,27 +9,33 @@ magick - "$TMP_DIR/img.jpg" BASE64_IMAGE=$(base64 -w 0 "$TMP_DIR/img.jpg") -curl https://api.openai.com/v1/chat/completions \ +cat < "$TMP_DIR/payload.json" +{ + "model": "$OPENAI_MODEL", + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "$PROMPT" + }, + { + "type": "image_url", + "image_url": { + "url": "data:image/jpeg;base64,$BASE64_IMAGE" + } + } + ] + } + ], + "max_tokens": $MAX_TOKENS +} +EOF + +curl -s https://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "'"$OPENAI_MODEL"'", - "messages": [ - { - "role": "user", - "content": [ - { - "type": "text", - "text": "'"$PROMPT"'" - }, - { - "type": "image_url", - "image_url": { - "url": "data:image/jpeg;base64,'"$BASE64_IMAGE"'" - } - } - ] - } - ], - "max_tokens": '"$MAX_TOKENS"' - }' | jq -r .choices[0].message.content + -d "@$TMP_DIR/payload.json" | jq -r .choices[0].message.content + +rm -rf "$TMP_DIR"