汉字叔叔花了多少钱做网站,赶集招聘网,造价工程建设协会网站,网站前台空白现在只要有额度#xff0c;大家都可以调用OpenAI的多模态大模型了#xff0c;例如GPT-4o和GPT-4 Turbo#xff0c;我一年多前总结过一些OpenAI API的用法#xff0c;发现现在稍微更新了一下。主要参考了这里#xff1a;https://platform.openai.com/docs/guides/vision
其…现在只要有额度大家都可以调用OpenAI的多模态大模型了例如GPT-4o和GPT-4 Turbo我一年多前总结过一些OpenAI API的用法发现现在稍微更新了一下。主要参考了这里https://platform.openai.com/docs/guides/vision
其实也是比较简单的就是本地图片需要用base 64先编码然后再上传。我举个例子大家应该一看就清楚图片放在Processed文件夹里面
from openai import OpenAI
import os
import base64client OpenAI(api_keyYour_API_Key
)# Function to encode the image
def encode_image(image_path):with open(image_path, rb) as image_file:return base64.b64encode(image_file.read()).decode(utf-8)fig_pathProcessedfor filename in os.listdir(fig_path):if filename.endswith(.png):image_pathos.path.join(fig_path, filename)print(image_path)base64_image encode_image(image_path)messages[{role: user, content: [{type:text, text:Whats in this image?},{type:image_url,image_url:{url:fdata:image/png;base64,{base64_image}}}]}]completion client.chat.completions.create(modelgpt-4o,messagesmessages)chat_response completionanswer chat_response.choices[0].message.contentprint(fChatGPT: {answer})
当然大家用的时候还是要注意花费现在感觉还是有点贵的。