AI on demand: allenai/olmOCR-2-7B: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Calling the model == <syntaxhighlight lang="bash"> # Set your personal key: STONEY_KEY=sk-... # Set the desired model: MODEL=allenai/olmOCR-2-7B # Set your prompt: PROMPT='Hello.' # Set maximum amount of tokens: MAX_TOKENS=100 curl https://llm.stoney-cloud.com/v1/chat/completions \ --silent --fail --show-error \ --header "Authorization: Bearer $STONEY_KEY" \ --header 'Content-Type: application/json' \ --data '{ "mo...") |
|||
| Line 1: | Line 1: | ||
== Calling the model == | == Calling the model == | ||
[[Image:testocr.png|thumb|The image used in the example to run OCR against.]] | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# Set your personal key: | # Set your personal key: | ||
| Line 7: | Line 8: | ||
MODEL=allenai/olmOCR-2-7B | MODEL=allenai/olmOCR-2-7B | ||
# Set | # Set the desired document to run OCR against: | ||
FILE_PATH=document.png | |||
# | # Encode document contents with Base64 and detect MIME type: | ||
FILE_CONTENT_BASE64=$(base64 -w 0 < "$FILE_PATH") | |||
FILE_MIME_TYPE=$(file --brief --mime-type "$FILE_PATH") | |||
curl https://llm.stoney-cloud.com/v1/chat/completions \ | curl https://llm.stoney-cloud.com/v1/chat/completions \ | ||
--silent --fail --show-error \ | --silent --fail --show-error \ | ||
--header "Authorization: Bearer $STONEY_KEY" \ | --header "Authorization: Bearer $STONEY_KEY" \ | ||
--header 'Content-Type: application/json' | --header 'Content-Type: application/json' \ | ||
--data '{ | --data '{ | ||
"model": "'"$MODEL"'", | "model": "'"$MODEL"'", | ||
"messages": [ | "messages": [{ | ||
"role": "user", | |||
], | "content": [{ | ||
"max_tokens": | "type": "image_url", | ||
"image_url": { | |||
"url": "data:'"$FILE_MIME_TYPE"';base64,'"$FILE_CONTENT_BASE64"'" | |||
} | |||
}] | |||
}], | |||
"max_tokens": 4096, | |||
"temperature": 0.2, | |||
"top_p": 0.9 | |||
}' \ | }' \ | ||
| jq | | jq | ||
| Line 30: | Line 40: | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
{ | { | ||
"id": "chatcmpl- | "id": "chatcmpl-b96a0fa8d921c5ed", | ||
"object": "chat.completion", | "object": "chat.completion", | ||
"created": | "created": 1779956243, | ||
"model": "allenai/olmOCR-2-7B", | "model": "allenai/olmOCR-2-7B", | ||
"choices": [ | "choices": [ | ||
| Line 39: | Line 49: | ||
"message": { | "message": { | ||
"role": "assistant", | "role": "assistant", | ||
"content": " | "content": "This is a lot of 12 point text to test the ocr code and see if it works on all types of file format.\nThe quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox.", | ||
"refusal": null, | "refusal": null, | ||
"annotations": null, | "annotations": null, | ||
| Line 56: | Line 66: | ||
"system_fingerprint": null, | "system_fingerprint": null, | ||
"usage": { | "usage": { | ||
"prompt_tokens": | "prompt_tokens": 412, | ||
"total_tokens": | "total_tokens": 481, | ||
"completion_tokens": | "completion_tokens": 69, | ||
"prompt_tokens_details": null | "prompt_tokens_details": null | ||
}, | }, | ||
Latest revision as of 10:18, 28 May 2026
Calling the model
# Set your personal key:
STONEY_KEY=sk-...
# Set the desired model:
MODEL=allenai/olmOCR-2-7B
# Set the desired document to run OCR against:
FILE_PATH=document.png
# Encode document contents with Base64 and detect MIME type:
FILE_CONTENT_BASE64=$(base64 -w 0 < "$FILE_PATH")
FILE_MIME_TYPE=$(file --brief --mime-type "$FILE_PATH")
curl https://llm.stoney-cloud.com/v1/chat/completions \
--silent --fail --show-error \
--header "Authorization: Bearer $STONEY_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "'"$MODEL"'",
"messages": [{
"role": "user",
"content": [{
"type": "image_url",
"image_url": {
"url": "data:'"$FILE_MIME_TYPE"';base64,'"$FILE_CONTENT_BASE64"'"
}
}]
}],
"max_tokens": 4096,
"temperature": 0.2,
"top_p": 0.9
}' \
| jq
Example output:
{
"id": "chatcmpl-b96a0fa8d921c5ed",
"object": "chat.completion",
"created": 1779956243,
"model": "allenai/olmOCR-2-7B",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This is a lot of 12 point text to test the ocr code and see if it works on all types of file format.\nThe quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox.",
"refusal": null,
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": [],
"reasoning": null
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": null,
"token_ids": null
}
],
"service_tier": null,
"system_fingerprint": null,
"usage": {
"prompt_tokens": 412,
"total_tokens": 481,
"completion_tokens": 69,
"prompt_tokens_details": null
},
"prompt_logprobs": null,
"prompt_token_ids": null,
"kv_transfer_params": null
}