sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
8.72k stars 1.32k forks source link

How to get JSON mode working for Open AI Vision #676

Open mingsterism opened 4 months ago

mingsterism commented 4 months ago

is there any support for JSON mode in vision preview? i've tried to get it working with GPT4Turbo1106 as well but it does not work. below is my example

    resp, err := client.CreateChatCompletion(
        context.Background(),
        openai.ChatCompletionRequest{
            Model:     openai.GPT4Turbo1106,
            MaxTokens: 1000,
            Messages: []openai.ChatCompletionMessage{
                {
                    Role: openai.ChatMessageRoleUser,
                    MultiContent: []openai.ChatMessagePart{
                        {
                            Type: openai.ChatMessagePartTypeText,
                            Text: text,
                        },
                        {
                            Type: openai.ChatMessagePartTypeImageURL,
                            ImageURL: &openai.ChatMessageImageURL{
                                URL:    imgString2,
                                Detail: openai.ImageURLDetailLow,
                            },
                        },
                    },
                },
            },
            Tools: []openai.Tool{t},
            //ResponseFormat: &openai.ChatCompletionResponseFormat{
            //  Type: openai.ChatCompletionResponseFormatTypeJSONObject,
            //},
        },
    )
HelloTQ commented 2 months ago

has the error been fixed?

rasmusviben commented 2 months ago

Working for me with the new GPT4o model and if I specify in the "text" that the output should be json.