Closed matthewsinclair closed 8 months ago
Thanks for reporting, let me look into that.
Just checking - have you tried the latest main branch? I've just on the weekend updated the docs to fit the latest OpenAI state
No probs. Happy to help! Thanks for putting the effort into this awesome lib! I have not checked the main branch, but I'll give it a go today and see if that works. Thanks.
Here you go, did a quick test in iex and it works on latest head. Just a bit weirdly formatted :)
Code:
msgs = [
%ExOpenAI.Components.ChatCompletionRequestUserMessage{role: :user,
content: [%ExOpenAI.Components.ChatCompletionRequestMessageContentPartImage{
type: :image_url,
image_url: "https://lh3.googleusercontent.com/wAPeTvxh_EwOisF8kMR2L2eOrIOzjfA5AjE28W5asyfGeH85glwrO6zyqL71dCC26R63chADTO7DLOjnqRoXXOAB8t2f4C3QnU6o0BA"
}
]},
]
ExOpenAI.Chat.create_chat_completion(msgs, "gpt-4-vision-preview")
{:ok,
%ExOpenAI.Components.CreateChatCompletionResponse{
id: "chatcmpl-8KNhE1XbdgD1TqdXOugxUk494QkZA",
created: 1699868340,
object: "chat.completion",
model: "gpt-4-1106-vision-preview",
choices: [
%{
index: 0,
message: %{
role: "assistant",
content: "You've shared an image of the Google Cloud Platform (GCP) logo."
},
finish_details: %{type: "max_tokens"}
}
],
usage: %{prompt_tokens: 262, total_tokens: 278, completion_tokens: 16},
system_fingerprint: nil
}}
You don't need to encode the messages through Jason, just follow the typespec should be sufficient
What if the image is local (ie just available via File.load!
) and not a URL?
I’m on my phone and can’t try it but you should be able load it like you did, then pass into the image_url param as URI with the code I sent above
https://github.com/dvcrn/ex_openai/blob/main/lib/ex_openai/docs/docs.yaml#L5580
Hmm, it wasn't working, and then I made one small change to the image_url
param to add in "data:image/jpeg;base64,"
in front of the base64 encoded image data:
...
msgs = [
%ExOpenAI.Components.ChatCompletionRequestUserMessage{
role: :user,
content: [
%ExOpenAI.Components.ChatCompletionRequestMessageContentPartImage{
type: :image_url,
image_url: "data:image/jpeg;base64," <> image64
}
]
}
]
dbg(msgs)
And now it works! Thanks!
PS: I also needed to add in the max-tokens: 1_000
option at the end of the call to create_chat_completion
like this:
... ExOpenAI.Chat.create_chat_completion(msgs, "gpt-4-vision-preview", max_tokens: 1_000)
Glad to hear it worked! 👍
Hi everyone. I am not quite sure where or who to ask about this one, but I’ll start here. I am trying to use OpenAI’s new “gpt-4-vision-preview” model. I have two bits of code, one using a RAW post via HTTPPoison and the other using ExElixir. The raw call works, but the ExElixir one doesn’t. As far as I can tell, I am sending in exactly the same params, but I’m obviously doing something dumb because one call works and the other does not. Is there anything obvious here that would lead to the error in the second case?
This call (using a raw post via httppoison) works:
This one (using ex_openai) does not:
The error in the second case is:
There is obviously something a bit weird (or different) in how
ExOpenAI.Completions.create_completion
wraps up the params that I am not understanding or misconfiguring somehow.Any ideas would be very helpful! Thanks.