You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import os
from openai import OpenAI
client = OpenAI(
# 若没有配置环境变量请用百炼API Key将下行替换为api_key="sk-xxx",
api_key='sk-f6da0c787eff4b0389e4ad03a35a911f',
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen-vl-ocr-latest",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": "https://img.alicdn.com/imgextra/i2/O1CN01ktT8451iQutqReELT_!!6000000004408-0-tps-689-487.jpg",
# 输入图像的最小像素阈值小于该值图像会按原比例放大直到总像素大于min_pixels
"min_pixels": 28 * 28 * 4,
# 输入图像的最大像素阈值超过该值图像会按原比例缩小直到总像素低于max_pixels
"max_pixels": 28 * 28 * 8192
},
# qwen-vl-ocr-latest支持在以下text字段中传入Prompt若未传入则会使用默认的PromptPlease output only the text content from the image without any additional descriptions or formatting.
# 如调用qwen-vl-ocr-1028模型会使用固定PromptRead all the text in the image.不支持用户在text中传入自定义Prompt
{"type": "text",
"text": "请提取车票图像中的发票号码、车次、起始站、终点站、发车日期和时间点、座位号、席别类型、票价、身份证号码、购票人姓名。要求准确无误的提取上述关键信息、不要遗漏和捏造虚假信息,模糊或者强光遮挡的单个文字可以用英文问号?代替。返回数据格式以json方式输出格式为{'发票号码''xxx', '车次''xxx', '起始站''xxx', '终点站''xxx', '发车日期和时间点''xxx', '座位号''xxx', '席别类型''xxx','票价':'xxx', '身份证号码''xxx', '购票人姓名''xxx'"},
]
}
])
print(completion.choices[0].message.content)