Skip to content
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

[vllm] - <title> vllm 部署了API接口,示例里边有单张图片的推理,但是多张图片的推理,有参考示例吗? #674

Open
lh3707 opened this issue Nov 19, 2024 · 1 comment
Labels
question Further information is requested

Comments

@lh3707
Copy link

lh3707 commented Nov 19, 2024

起始日期 | Start Date

No response

实现PR | Implementation PR

No response

相关Issues | Reference Issues

No response

摘要 | Summary

参考链接:https://modelbest.feishu.cn/wiki/LZxLwp4Lzi29vXklYLFchwN5nCf
`from openai import OpenAI
openai_api_key = "token-abc123" # your api key set in launch server
openai_api_base = "http://localhost:8000/v1" # http id
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)

用于传本地图片

with open('your/local/pic/path','rb') as file:
image = "data:image/jpeg;base64,"+ base64.b64encode(file.read()).decode('utf-8')

chat_response = client.chat.completions.create(
model="/root/ld/ld_model_pretrained/Minicpmv2_6", # model_local_path or huggingface id
messages=[{
"role": "user",
"content": [
# NOTE: 使用图像令牌 的提示格式是不必要的,因为提示将由API服务器自动处理。
# 由于提示将由API服务器自动处理,因此不需要使用包含 图像令牌的提示格式。
{"type": "text", "text": "请描述这张图片"},
{
"type": "image_url",
"image_url": {
"url": image,
},
},
],
}],
extra_body={
"stop_token_ids": [151645, 151643]
}
)
print("Chat response:", chat_response)
print("Chat response content:", chat_response.choices[0].message.content)`

基本示例 | Basic Example

#通过API的方式的单张图片推理的部分代码
chat_response = client.chat.completions.create( model="/root/openbmb/MiniCPM-V-2_6", # model_local_path or huggingface id messages=[{ "role": "user", "content": [ # NOTE: 使用图像令牌 <image> 的提示格式是不必要的,因为提示将由API服务器自动处理。 # 由于提示将由API服务器自动处理,因此不需要使用包含 <image> 图像令牌的提示格式。 {"type": "text", "text": "请描述这张图片"}, { "type": "image_url", "image_url": { "url": image, }, }, ], }], extra_body={ "stop_token_ids": [151645, 151643] } )

缺陷 | Drawbacks

参考多张图片,结果说是不支持,可以怎么处理呢?

chat_response = client.chat.completions.create( model="/root/openbmb/MiniCPM-V-2_6", # model_local_path or huggingface id messages=[{ "role": "user", "content": [ # NOTE: 使用图像令牌 <image> 的提示格式是不必要的,因为提示将由API服务器自动处理。 # 由于提示将由API服务器自动处理,因此不需要使用包含 <image> 图像令牌的提示格式。 {"type": "text", "text": "请描述这张图片"}, { "type": "image_url", "image_url": { "url": imag1, }, }, { "type": "image_url", "image_url": { "url": image2, }, }, ], }], extra_body={ "stop_token_ids": [151645, 151643] } )

未解决问题 | Unresolved questions

No response

@lh3707 lh3707 added the question Further information is requested label Nov 19, 2024
@LDLINGLINGLING
Copy link
Collaborator

这个可能要使用我们开源的vllm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants