跳转到主要内容

功能介绍

DeepSeek-OCR 聚焦于文档识别及图像转文本场景,探索视觉与文本压缩的极限。该模型可将长文本渲染为高压缩比图像,在 10 倍无损压缩下能实现 97% 的 OCR 准确率,即使压缩到 20 倍也能保持约 60% 的准确率。需要注意的是,该模型仅支持单轮独立识别任务,暂不支持多轮对话,每次仅能上传一张图像,需使用预设提示词调用以获得最佳效果

推荐的预设提示词

# 将文档内容转换为 markdown 格式
<|grounding|>Convert the document to markdown.

# 对该图像进行文本识别
<|grounding|>OCR this image.

# 不考虑版式,直接提取所有文本
Free OCR.

# 解析文档中的图形或表格内容
Parse the figure.

# 详细描述图片内容
Describe this image in detail.

# 在图像中定位 <|ref|>xxxx<|/ref|> 的位置
Locate <|ref|>xxxx<|/ref|> in the image.

调用示例

以使用 <|grounding|>OCR this image. 预设提示词完成图像文本识别为例
from openai import OpenAI

client = OpenAI(
    base_url="https://api.ppinfra.com/openai",
    api_key="<Your API Key>",
)

response = client.chat.completions.create(
    model="deepseek/deepseek-ocr",
    messages=[
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "https://example.com/image.png"
            }
          },
          {
            "type": "text",
            "text": "<|grounding|>OCR this image."
          }
        ]
      }
    ],
    stream=False,
    max_tokens=4096
)

content = response.choices[0].message.content

print(content)
示例图片
OCR 图片
示例输出
<|/ref|><|det|>[[33, 116, 228, 212]]<|/det|>
<|ref|>BaseURL:<|/ref|><|det|>[[34, 105, 227, 209]]<|/det|>
<|ref|>https://api.ppinfra.com/openai<|/ref|><|det|>[[335, 103, 888, 215]]<|/det|>
<|ref|>API Endpoints:<|/ref|><|det|>[[34, 336, 302, 449]]<|/det|>
<|ref|>/v1/chat/completions<|/ref|><|det|>[[353, 347, 682, 427]]<|/det|>
<|ref|>Model ID:<|/ref|><|det|>[[37, 563, 208, 661]]<|/det|>
<|ref|>deepseek/deepseek-ocr<|/ref|><|det|>[[331, 575, 781, 665]]<|/det|>
<|ref|>API Key:<|/ref|><|det|>[[32, 779, 190, 899]]<|/det|>
<|ref|>创建&查询您的APIEy<|/ref|><|det|>[[334, 780, 771, 896]]<|/det|>
I