doggie
1
import requests
import base64
url = "https://api.siliconflow.cn/v1/chat/completions"
payload = {
"model": "deepseek-ai/DeepSeek-OCR",
"messages": [
{
"role": "user",
"content": [
{
"image_url": {
"url": "data:application/pdf;base64," + base64.b64encode(
open("test_image.jpg", "rb").read()).decode("utf-8")
},
"type": "image_url"
},
{
"type": "text",
# text 是提示词,根据要识别的东西写合适的提示词
"text": "TABLE_EXTRACTION = '\u003cimage\u003e\\n\u003c|grounding|\u003eExtract tables from this document and convert to markdown format.'"
}
]
}
],
# "max_tokens": 8002,
"stream": False,
"response_format": { "type": "text" }
}
headers = {
"Authorization": "Bearer 你的 API 密钥",
# 比如 "Authorization": "Bearer testtesttest", (bearer和apikey之间加上空格)
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
# 提取content内容
result = response.json()
content = result['choices'][0]['message']['content']
print(content)