openai-java
openai-java copied to clipboard
When using the GPT-4V model in this library, GPT replied, "Sorry, I cannot access external URLs to view images." However, when I use the curl command, GPT can access image links
When using the GPT-4V model in this library, GPT replied, "Sorry, I cannot access external URLs to view images." However, when I use the curl command, GPT can access image links.
my curl commend
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxx" \
-d '{
"model":"gpt-4-vision-preview",
"messages":[
{
"role":"user",
"content":[
{
"type":"text",
"text":"What’s in this image?"
},
{
"type":"image_url",
"image_url":{
"url":"https://wework.qpic.cn/wwpic/xxxx",
"detail":"low"
}
}
]
}
],
"max_tokens":300
}'
and this is my code
String model = "gpt-4-vision-preview";
List<ChatMessage> messages = new ArrayList<>();
JSONArray contents = new JSONArray();
JSONObject textContent = new JSONObject();
textContent.put("type","text");
textContent.put("text","What’s in this image?");
contents.add(textContent);
JSONObject imageContent = new JSONObject();
imageContent.put("type","image_url");
JSONObject url = new JSONObject();
//url.put("url","https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/John_Everett_Millais_-_%22A_Reverie%22_from_The_Window%3B_or%2C_The_Song_of_the_Wrens.jpg/403px-John_Everett_Millais_-_%22A_Reverie%22_from_The_Window%3B_or%2C_The_Song_of_the_Wrens.jpg");
url.put("url","https://wework.qpic.cn/wwpic/xxxx");
url.put("detail","low");
imageContent.put("image_url",url);
contents.add(imageContent);
log.info("contents:{}",contents.toString());
messages.add(new ChatMessage(ChatMessageRole.USER.value(),contents.toString()));
log.info("===messages:{}",messages);
and I use ChatCompletionRequest
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
.model(model)
.messages(messages)
.maxTokens(300)
.n(1)
.build();
Can anyone help me solve this problem?
The PR #413 will be solved for this.
The PR #413 will be solved for this.
So, there is no support yet?When I replaced the link in the example with an image from Wikipedia, I was able to successfully obtain a response. I thought I didn't know how to use it. Thank you so much.
Hi @yangleimiao
try using this library it has support for Vision - https://github.com/namankhurpia/Easy-open-ai