41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import base64
|
|
from openai import OpenAI
|
|
api_key='sk-83c3ebe6b1b04bdf93c3c4be9b17736d'
|
|
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")
|
|
files = client.files.list()
|
|
for f in files.data:
|
|
print(f.id, f.filename)
|
|
with open("zky.png", "rb") as f:
|
|
b64 = base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
response = client.chat.completions.create(
|
|
model="deepseek-flash",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": [
|
|
{"type": "text", "text": "这张图片里有什么?"},
|
|
{
|
|
"type": "image_url",
|
|
"image_url": {"url": f"data:image/jpeg;base64,{b64}"},
|
|
},
|
|
],
|
|
}
|
|
],
|
|
)
|
|
print(response.choices[0].message.content)
|
|
|
|
|
|
response = client.chat.completions.create(
|
|
model="deepseek-flash",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": [
|
|
{"type": "text", "text": "这张图片里有什么?"},
|
|
{"type": "file", "file_id": "file-api-01ab723a-0bd1-4e38-b373-a25278eb3baf"},
|
|
],
|
|
}
|
|
],
|
|
)
|
|
print(response.choices[0].message.content) |