Skip to content

Commit

Permalink
Send service files like normal derivative streams, and foward using O…
Browse files Browse the repository at this point in the history
…penAI base64
  • Loading branch information
joecorall committed Dec 6, 2024
1 parent 5d1be8a commit 9a712fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions examples/openai-htr/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion examples/openai-htr/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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"'"
}
}
]
Expand Down
2 changes: 0 additions & 2 deletions examples/openai-htr/scyllaridae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ allowedMimeTypes:
cmdByMimeType:
default:
cmd: /app/cmd.sh
args:
- "%source-uri"
3 changes: 0 additions & 3 deletions examples/parry/scyllaridae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a712fa

Please sign in to comment.