go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

How to get JSON mode working for Open AI Vision

Open mingsterism opened this issue 11 months ago • 2 comments

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,
			//},
		},
	)

mingsterism avatar Mar 05 '24 10:03 mingsterism

has the error been fixed?

HelloTQ avatar May 06 '24 09:05 HelloTQ

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

rasmusviben avatar May 18 '24 15:05 rasmusviben