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

How to use gpt-4-vision-preview ? #7

Open
sbetzin opened this issue Nov 23, 2023 · 3 comments
Open

How to use gpt-4-vision-preview ? #7

sbetzin opened this issue Nov 23, 2023 · 3 comments

Comments

@sbetzin
Copy link

sbetzin commented Nov 23, 2023

Hi There,

love your work and this repo!
Tried to use gpt-4-vision-preview but only got an exception:
var result = await client.GetChatCompletions(message, model: "gpt-4-vision-preview");

And I got:
image

Thank you
Sebastian

@sbetzin
Copy link
Author

sbetzin commented Nov 23, 2023

Btw: Trying to test if I can get the vision to work via api:

var json = JsonSerializer.Serialize(new { type = "image_url", image_url = new { url = base64} });

var message = Dialog.StartAsSystem("Return image description.").ThenUser(json);

@rodion-m
Copy link
Owner

rodion-m commented Dec 11, 2023

Hey @sbetzin ! Sorry for the late response. Vision feature isn't supported yet.

@sbetzin
Copy link
Author

sbetzin commented Feb 2, 2024

Hi, yes it is :) It was able to implement it with my own code

private static object CreateÎmageMessages(string systemPrompt, string prompt, double temperature, int maxTokens,
    string base64Image)
{
    // via https://platform.openai.com/docs/guides/vision
    var payload = new
    {
        model = "gpt-4-vision-preview",
        messages = new object[]
        {
                new
                {
                    role = "system",
                    content = new object[]
                    {
                        new
                        {
                            type = "text",
                            text = systemPrompt
                        }
                    }
                },
                new
                {
                    role = "user",
                    content = new object[]
                    {
                        new
                        {
                            type = "text",
                            text = prompt
                        },
                        new
                        {
                            type = "image_url",
                            image_url = new
                            {
                                url = "data:image/jpeg;base64," + base64Image,
                                detail = "auto"
                            }
                        }
                    }
                }
        },
        max_tokens = maxTokens,
        temperature = temperature
    };
    return payload;
}

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

No branches or pull requests

2 participants