| |
|
|
| import base64 |
| from openai import OpenAI |
|
|
| |
| image_path = "0375.jpg" |
| with open(image_path, "rb") as f: |
| image_data = base64.b64encode(f.read()).decode("utf-8") |
|
|
| |
| client = OpenAI( |
| base_url="https://www.autodl.art/api/v1", |
| api_key="", |
| ) |
|
|
| |
| stream = client.chat.completions.create( |
| model="qwen3.6-plus", |
| messages=[ |
| { |
| "role": "user", |
| "content": [ |
| { |
| "type": "text", |
| "text": "提取图片中的文字,按阅读顺序输出" |
| }, |
| { |
| "type": "image_url", |
| "image_url": { |
| "url": f"data:image/jpeg;base64,{image_data}" |
| } |
| } |
| ] |
| } |
| ], |
| stream=True, |
| ) |
|
|
| |
| for chunk in stream: |
| if chunk.choices and chunk.choices[0].delta.content: |
| print(chunk.choices[0].delta.content, end="") |