AI on demand: opendatalab/MinerU2.5-2509-1.2B: Difference between revisions

From MediaWiki
Jump to navigation Jump to search
m (Sst-yde moved page AI on Demand: MinerU to AI on demand: MinerU)
No edit summary
 
(26 intermediate revisions by 3 users not shown)
Line 1: Line 1:
stepping stone AG is proud to serve customers with current Language Models and OCR solutions.
== Calling the model ==
All of our LLM services are reachable from https://llm.stoney-cloud.com/
<syntaxhighlight lang="bash">
# Set your personal key:
STONEY_KEY=sk-...


== Calling a model ==
# Set the desired document to run OCR against:
We assume you've received your API key from us in our usual manner. The route above is available in the usual OpenAI-compatible manner.
FILE_PATH=document.png
For instance, receiving a list of available model is done via https://llm.stoney-cloud.com/v1/models which requires you to provide your key.
As an initial service we provide access to some OCR models.


<syntaxhighlight lang="bash">
# Set the desired model:
STONEY_KEY=<your-key-here>
MODEL=opendatalab/MinerU2.5-2509-1.2B
MODEL_NAME=<hosted-model-name-here>
 
# 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
</syntaxhighlight>


curl -s https://llm.stoney-cloud.com/v1/chat/completions \
Example output:
   -H "Authorization: Bearer $STONEY_KEY" \
<syntaxhighlight lang="json">
   -H "Content-Type: application/json" \
{
   -d "{
   "id": "chatcmpl-834171fda5956922",
    \"model\":\"${MODEL_NAME}\",
   "object": "chat.completion",
     \"messages\":[
   "created": 1788347006,
       {\"role\":\"user\",\"content\":\"Describe an imaginary document.\"}
  "model": "opendatalab/MinerU2.5-2509-1.2B",
     ],
  "choices": [
     \"max_tokens\":2000}" | jq .
     {
      "index": 0,
       "message": {
        "role": "assistant",
        "content": "This is a lot of 12 point text to test theOCR code and see if it works on all types of file format. 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. The quick brown dog jumped over the lazy fox.",
        "refusal": null,
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [],
        "reasoning": null,
        "reasoning_content": null
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": null,
      "token_ids": null
     }
  ],
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "prompt_tokens": 412,
    "total_tokens": 480,
     "completion_tokens": 68,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null,
  "prompt_token_ids": null,
  "kv_transfer_params": null
}
</syntaxhighlight>
</syntaxhighlight>


== Inspecting your usage ==
== Calling the model - PDF text extraction ==
 
Extracting text from a PDF via the API requires a few additional steps.
 
This is a pure text extraction from a PDF. The model does not analyse the content. 


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
curl -s https://llm.stoney-cloud.com/v1/usage  -H "Authorization: Bearer $STONEY_KEY" | jq .
# Set your personal key:
STONEY_KEY=sk-...
 
# Set the file path to desired pdf:
FILE_PATH='path/to/file/document.pdf'
 
# Set the desired model:
MODEL='opendatalab/MinerU2.5-2509-1.2B'
 
#Set where to save the extracted text.
OUTPUT_DIR='/home/user/Desktop/results'
 
#Call the model and extract text
(
 
  PREFIX="$OUTPUT_DIR/mineru-$(date +%Y%m%d-%H%M%S)-$$"
 
  # Convert PDF pages into images.
  pdftoppm -r 150 -png "$FILE_PATH" "$PREFIX"
 
  for PAGE in "$PREFIX"-*.png; do
    # Encode the page and submit it to MinerU.
    base64 -w 0 < "$PAGE" |
    jq -Rs --arg model "$MODEL" '{
      model: $model,
      messages: [{
        role: "user",
        content: [{
          type: "image_url",
          image_url: {url: ("data:image/png;base64," + .)}
        }]
      }],
      max_tokens: 4096,
      temperature: 0.2,
      top_p: 0.9
    }' |
    curl --silent --fail-with-body --show-error \
      --connect-timeout 5 --max-time 180 \
      https://llm.stoney-cloud.com/v1/chat/completions \
      --header "Authorization: Bearer $STONEY_KEY" \
      --header 'Content-Type: application/json' \
      --data-binary @- \
      --output "${PAGE%.png}.json"
  done
 
  # Combine page results and sum token usage.
  jq -s '{
    model: .[0].model,
    pages: map({
      id,
      text: .choices[0].message.content,
      finish_reason: .choices[0].finish_reason,
      usage
    }),
    usage: {
      prompt_tokens: (map(.usage.prompt_tokens) | add),
      completion_tokens: (map(.usage.completion_tokens) | add),
      total_tokens: (map(.usage.total_tokens) | add)
    },
    extraction_complete: all(.[]; .choices[0].finish_reason == "stop")
  }' "$PREFIX"-*.json > "$OUTPUT_DIR/result.json"
 
  jq -r '.pages[].text' "$OUTPUT_DIR/result.json" \
    > "$OUTPUT_DIR/document.txt"
 
  jq . "$OUTPUT_DIR/result.json"
)
</syntaxhighlight>
</syntaxhighlight>


We issue one key per model for now. The usage is thus per-model-per-key.
Example output:


<syntaxhighlight lang="bash">
{
  "model": "opendatalab/MinerU2.5-2509-1.2B",
  "pages": [
    {
      "id": "chatcmpl-86c1cdeb2f40eeca",
      "text": "This is a test do read out text in a PDF format. It is meant to test and verify access to the Service. A recipe for Chocolate Cake can not be provided. Random gugus is part of it.  \nAnyone asks,  \nsay you're of English descent  \nlike my father, not like her  \nI nod, another thing to know  \nlike keep your dress down  \nso your underpants don't show,  \ndon't talk about vomit at the supper table,  \ndon't say you're Indian.  \nI place the fork carefully,  \none on the left side of each plate,  \nas I've been taught.",
      "finish_reason": "stop",
      "usage": {
        "prompt_tokens": 2035,
        "total_tokens": 2166,
        "completion_tokens": 131,
        "prompt_tokens_details": null
      }
    }
  ],
  "usage": {
    "prompt_tokens": 2035,
    "completion_tokens": 131,
    "total_tokens": 2166
  },
  "extraction_complete": true
}
</syntaxhighlight>


[[Category:AI on Demand]]
[[Category: AI on Demand]]
[[Category: OCR models]]

Latest revision as of 10:30, 12 November 2026

Calling the model

# Set your personal key:
STONEY_KEY=sk-...

# Set the desired document to run OCR against:
FILE_PATH=document.png

# Set the desired model:
MODEL=opendatalab/MinerU2.5-2509-1.2B

# 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-834171fda5956922",
  "object": "chat.completion",
  "created": 1788347006,
  "model": "opendatalab/MinerU2.5-2509-1.2B",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "This is a lot of 12 point text to test theOCR code and see if it works on all types of file format. 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. The quick brown dog jumped over the lazy fox.",
        "refusal": null,
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [],
        "reasoning": null,
        "reasoning_content": null
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": null,
      "token_ids": null
    }
  ],
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "prompt_tokens": 412,
    "total_tokens": 480,
    "completion_tokens": 68,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null,
  "prompt_token_ids": null,
  "kv_transfer_params": null
}

Calling the model - PDF text extraction

Extracting text from a PDF via the API requires a few additional steps.

This is a pure text extraction from a PDF. The model does not analyse the content.

# Set your personal key:
STONEY_KEY=sk-...

# Set the file path to desired pdf:
FILE_PATH='path/to/file/document.pdf'

# Set the desired model:
MODEL='opendatalab/MinerU2.5-2509-1.2B'

#Set where to save the extracted text.
OUTPUT_DIR='/home/user/Desktop/results'

#Call the model and extract text
(
  
  PREFIX="$OUTPUT_DIR/mineru-$(date +%Y%m%d-%H%M%S)-$$"

  # Convert PDF pages into images.
  pdftoppm -r 150 -png "$FILE_PATH" "$PREFIX"

  for PAGE in "$PREFIX"-*.png; do
    # Encode the page and submit it to MinerU.
    base64 -w 0 < "$PAGE" |
    jq -Rs --arg model "$MODEL" '{
      model: $model,
      messages: [{
        role: "user",
        content: [{
          type: "image_url",
          image_url: {url: ("data:image/png;base64," + .)}
        }]
      }],
      max_tokens: 4096,
      temperature: 0.2,
      top_p: 0.9
    }' |
    curl --silent --fail-with-body --show-error \
      --connect-timeout 5 --max-time 180 \
      https://llm.stoney-cloud.com/v1/chat/completions \
      --header "Authorization: Bearer $STONEY_KEY" \
      --header 'Content-Type: application/json' \
      --data-binary @- \
      --output "${PAGE%.png}.json"
  done

  # Combine page results and sum token usage.
  jq -s '{
    model: .[0].model,
    pages: map({
      id,
      text: .choices[0].message.content,
      finish_reason: .choices[0].finish_reason,
      usage
    }),
    usage: {
      prompt_tokens: (map(.usage.prompt_tokens) | add),
      completion_tokens: (map(.usage.completion_tokens) | add),
      total_tokens: (map(.usage.total_tokens) | add)
    },
    extraction_complete: all(.[]; .choices[0].finish_reason == "stop")
  }' "$PREFIX"-*.json > "$OUTPUT_DIR/result.json"

  jq -r '.pages[].text' "$OUTPUT_DIR/result.json" \
    > "$OUTPUT_DIR/document.txt"

  jq . "$OUTPUT_DIR/result.json"
)

Example output:

{
  "model": "opendatalab/MinerU2.5-2509-1.2B",
  "pages": [
    {
      "id": "chatcmpl-86c1cdeb2f40eeca",
      "text": "This is a test do read out text in a PDF format. It is meant to test and verify access to the Service. A recipe for Chocolate Cake can not be provided. Random gugus is part of it.   \nAnyone asks,   \nsay you're of English descent   \nlike my father, not like her   \nI nod, another thing to know   \nlike keep your dress down   \nso your underpants don't show,   \ndon't talk about vomit at the supper table,   \ndon't say you're Indian.   \nI place the fork carefully,   \none on the left side of each plate,   \nas I've been taught.",
      "finish_reason": "stop",
      "usage": {
        "prompt_tokens": 2035,
        "total_tokens": 2166,
        "completion_tokens": 131,
        "prompt_tokens_details": null
      }
    }
  ],
  "usage": {
    "prompt_tokens": 2035,
    "completion_tokens": 131,
    "total_tokens": 2166
  },
  "extraction_complete": true
}