diff --git a/examples/openai-htr/Dockerfile b/examples/openai-htr/Dockerfile index 221f69e..6b0ee50 100644 --- a/examples/openai-htr/Dockerfile +++ b/examples/openai-htr/Dockerfile @@ -1,8 +1,20 @@ ARG TAG=main ARG DOCKER_REPOSITORY=lehighlts +FROM islandora/imagemagick:alpine-3.20.2-imagemagick-7.1.1.36-r0 AS imagemagick FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG} +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 + +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" \ MAX_TOKENS=300 + COPY scyllaridae.yml /app/scyllaridae.yml +COPY cmd.sh /app/cmd.sh diff --git a/examples/openai-htr/cmd.sh b/examples/openai-htr/cmd.sh index 37e16f3..b2a1dde 100755 --- a/examples/openai-htr/cmd.sh +++ b/examples/openai-htr/cmd.sh @@ -2,6 +2,13 @@ set -eou pipefail +TMP_DIR=$(mktemp -d) + +# convert service file to jpg +magick - "$TMP_DIR/img.jpg" + +BASE64_IMAGE=$(base64 -w 0 "$TMP_DIR/img.jpg") + curl https://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ @@ -18,7 +25,7 @@ curl https://api.openai.com/v1/chat/completions \ { "type": "image_url", "image_url": { - "url": "'"$1"'" + "url": "data:image/jpeg;base64,'"$BASE64_IMAGE"'" } } ] diff --git a/examples/openai-htr/scyllaridae.yml b/examples/openai-htr/scyllaridae.yml index a527b7e..36d1b3a 100644 --- a/examples/openai-htr/scyllaridae.yml +++ b/examples/openai-htr/scyllaridae.yml @@ -3,5 +3,3 @@ allowedMimeTypes: cmdByMimeType: default: cmd: /app/cmd.sh - args: - - "%source-uri" diff --git a/examples/parry/scyllaridae.yml b/examples/parry/scyllaridae.yml index 9a264f0..4b1c553 100644 --- a/examples/parry/scyllaridae.yml +++ b/examples/parry/scyllaridae.yml @@ -9,6 +9,3 @@ queueMiddlewares: - queueName: islandora-merge-pdf url: http://mergepdf:8080 consumers: 3 - - queueName: islandora-openai-htr - url: http://openai-htr:8080 - consumers: 3