> ## Documentation Index
> Fetch the complete documentation index at: https://ppio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# DeepSeek-OCR 使用

## 功能介绍

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

## 推荐的预设提示词

```bash theme={null}
# 将文档内容转换为 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.` 预设提示词完成图像文本识别为例

```python theme={null}
from openai import OpenAI

client = OpenAI(
    base_url="https://api.ppio.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)
```

示例图片

<Frame>
  <img src="https://mintcdn.com/ppinfra/pHYssb3U2Vr4mh_4/images/guide/ocr_input.jpg?fit=max&auto=format&n=pHYssb3U2Vr4mh_4&q=85&s=19df7eda9040e50fb22fe8c0d15ff6c9" alt="OCR 图片" width="722" height="260" data-path="images/guide/ocr_input.jpg" />
</Frame>

示例输出

```
<|/ref|><|det|>[[33, 116, 228, 212]]<|/det|>
<|ref|>BaseURL:<|/ref|><|det|>[[34, 105, 227, 209]]<|/det|>
<|ref|>https://api.ppio.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|>
```
