We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
No response
参考链接: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)`
#通过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] } )
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] } )
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] } )
The text was updated successfully, but these errors were encountered:
No branches or pull requests
起始日期 | 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
The text was updated successfully, but these errors were encountered: