Skip to content

读图用哪个接口? #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wengzhenquan opened this issue Apr 9, 2025 · 8 comments
Open

读图用哪个接口? #375

wengzhenquan opened this issue Apr 9, 2025 · 8 comments

Comments

@wengzhenquan
Copy link

需求是分析图片元素。
所以上传一张图片,然后告知ai需要分析的内容。
ai把分析结果回复给我,是以文字的形式,不需要生成新的图片。
比如说:这张图片里面有几只羊?
我看到gpt-4o-mini的介绍,有读图功能。
但是怎么用?

我尝试调用/chat/completions接口,把图片转成base64再以文本的方式发送,回复我消息过长403。

然后我尝试把请求头改成multipart/form-data,以文件的形式发送(文字描述放prompt里面),报500。
role: "system",
image: outputFile,
prompt:message

500 {'error':{'message':'服务器繁忙,请稍后再试!','type':'chatanywhere_error','param':null,'code':'500 INTERNAL_SERVER_ERROR'}}

尝试将接口换成/images/edits,也是500

我该怎么办?

@ynpl
Copy link

ynpl commented Apr 9, 2025

from openai import OpenAI

client = OpenAI(
    # 输入转发API Key
    api_key="sk-xxxxx",
    base_url="https://api.chatanywhere.tech/v1"
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "介绍一下这张图"},
                {
                    "type": "image_url",
                    "image_url": {
                                                "url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
                                                "detail": "high" #low high两个选项
                    }
                },
            ],
        }
    ],
    max_tokens=300,
    stream=False  # # 是否开启流式输出
)
# 非流式输出获取结果
print(response.choices[0].message)
# 流式输出获取结果
# for chunk in response:
#     print(chunk.choices[0].delta)

@wengzhenquan
Copy link
Author

from openai import OpenAI

client = OpenAI(
# 输入转发API Key
api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)

response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。
不过。。。
403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

@ynpl
Copy link

ynpl commented Apr 9, 2025

from openai import OpenAI
client = OpenAI(

输入转发API Key

api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。 不过。。。 403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

是的, 免费的不支持读图. 因为读图的费用比较高一些. 如果您需要使用读图功能可以在https://api.chatanywhere.tech/#/shop这里面购买付费api

@wengzhenquan
Copy link
Author

from openai import OpenAI
client = OpenAI(

输入转发API Key

api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。 不过。。。 403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

是的, 免费的不支持读图. 因为读图的费用比较高一些. 如果您需要使用读图功能可以在https://api.chatanywhere.tech/#/shop这里面购买付费api

好的。
还有几个问题想确认一下。
{ type: "image_url", image_url: { url: "data:image/png;base64," + base64Image, detail: "high" } }
1、base64这样写对吗?
url: "data:image/png;base64," + base64Image
base64Image这个对象是很长的字符串。
图片是png格式。

2、另外,我这里的脚本不能引入
from openai import OpenAI。
所以只能直接调用api,一开始我尝试调v1,提示404。
用v1/chat/completions之后才正常,所以还要确认一下是/chat/completions这个api吗?

3、detail这个参数是有什么含义?

@ynpl
Copy link

ynpl commented Apr 9, 2025

from openai import OpenAI
client = OpenAI(

输入转发API Key

api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。 不过。。。 403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

是的, 免费的不支持读图. 因为读图的费用比较高一些. 如果您需要使用读图功能可以在https://api.chatanywhere.tech/#/shop这里面购买付费api

好的。 还有几个问题想确认一下。 { type: "image_url", image_url: { url: "data:image/png;base64," + base64Image, detail: "high" } } 1、base64这样写对吗? url: "data:image/png;base64," + base64Image base64Image这个对象是很长的字符串。 图片是png格式。

2、另外,我这里的脚本不能引入 from openai import OpenAI。 所以只能直接调用api,一开始我尝试调v1,提示404。 用v1/chat/completions之后才正常,所以还要确认一下是/chat/completions这个api吗?

3、detail这个参数是有什么含义?

1.对
2.对
3.细节的意思你可以理解为注重细节的程度

@wengzhenquan
Copy link
Author

from openai import OpenAI
client = OpenAI(

输入转发API Key

api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。 不过。。。 403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

是的, 免费的不支持读图. 因为读图的费用比较高一些. 如果您需要使用读图功能可以在https://api.chatanywhere.tech/#/shop这里面购买付费api

好的。 还有几个问题想确认一下。 { type: "image_url", image_url: { url: "data:image/png;base64," + base64Image, detail: "high" } } 1、base64这样写对吗? url: "data:image/png;base64," + base64Image base64Image这个对象是很长的字符串。 图片是png格式。
2、另外,我这里的脚本不能引入 from openai import OpenAI。 所以只能直接调用api,一开始我尝试调v1,提示404。 用v1/chat/completions之后才正常,所以还要确认一下是/chat/completions这个api吗?
3、detail这个参数是有什么含义?

1.对 2.对 3.细节的意思你可以理解为注重细节的程度

感谢解答

@ynpl
Copy link

ynpl commented Apr 9, 2025

from openai import OpenAI
client = OpenAI(

输入转发API Key

api_key="sk-xxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "介绍一下这张图"},
{
"type": "image_url",
"image_url": {
"url": "https://lmg.jj20.com/up/allimg/1114/0G020114924/200G0114924-11-1200.jpg",#如果非图片url需要把本地图片转为Base64后,然后把base64的字符串放到这个参数上
"detail": "high" #low high两个选项
}
},
],
}
],
max_tokens=300,
stream=False # # 是否开启流式输出
)

非流式输出获取结果

print(response.choices[0].message)

流式输出获取结果

for chunk in response:

print(chunk.choices[0].delta)

感谢,调用确实成功了。 不过。。。 403 {'error':{'message':'免费API不支持多模态功能(图片分析),如有更多需求,请访问 https://api.chatanywhere.tech/#/shop 购买付费API

是的, 免费的不支持读图. 因为读图的费用比较高一些. 如果您需要使用读图功能可以在https://api.chatanywhere.tech/#/shop这里面购买付费api

好的。 还有几个问题想确认一下。 { type: "image_url", image_url: { url: "data:image/png;base64," + base64Image, detail: "high" } } 1、base64这样写对吗? url: "data:image/png;base64," + base64Image base64Image这个对象是很长的字符串。 图片是png格式。
2、另外,我这里的脚本不能引入 from openai import OpenAI。 所以只能直接调用api,一开始我尝试调v1,提示404。 用v1/chat/completions之后才正常,所以还要确认一下是/chat/completions这个api吗?
3、detail这个参数是有什么含义?

1.对 2.对 3.细节的意思你可以理解为注重细节的程度

感谢解答

客气, 如没其他问题记得Close一下哈

Repository owner deleted a comment Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@wengzhenquan @ynpl and others