docling-project / docling-project/docling
openai VLM
- Dominant language
- Python
- Stars
- 66.4k
- Forks
- 4.8k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 84
Description
### Question
why chatgpt vlm is not working ? am i using it wrong ? because i am getting empty result
```
import json
import logging
import os
from pathlib import Path
from typing import Optional
import requests
from docling_core.types.doc.page import SegmentedPage
from dotenv import load_dotenv
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import VlmPipelineOptions
from docling.datamodel.pipeline_options_vlm_model import ApiVlmOptions, ResponseFormat
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.pipeline.vlm_pipeline import VlmPipeline
def openai_vlm_options(model: str = "gpt-4.1-nano-2025-04-14", prompt: str = "OCR the full page to markdown. Extract all visible text exactly as it appears. Preserve symbols, formatting, and layout.", api_key: str = None):
"""Configure OpenAI's remote API for VLM processing"""
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
raise ValueError("OpenAI API key not found. Set OPENAI_API_KEY environment variable or pass api_key parameter.")
options = ApiVlmOptions(
url="https://api.openai.com/v1/chat/completions",
params=dict(
model=model,
max_tokens=4096,
),
headers={"Authorization": f"Bearer {api_key}"},
prompt=prompt,
timeout=120,
scale=2.0, # Full resolution
temperature=0.1, # Low temperature for consistent OCR results
response_format=ResponseFormat.DOCTAGS,
)
return options
# Simple example for quick testing
import os
from pathlib import Path
# Configure for OpenAI
pipeline_options = VlmPipelineOptions(enable_remote_services=True)
pipeline_options.vlm_options = openai_vlm_options(model="gpt-4o", prompt="Convert this page to docling")
# Create converter
converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(
pipeline_options=pipeline_options,
pipeline_cls=VlmPipeline,
)
}
)
# Process your PDF
result = converter.convert("./test_medical.pdf")
with open("./vlm_output.md", "w") as f:
f.write(result.document.export_to_markdown())
```
...
Contributor guide
Assessment
This issue has not been assessed yet.