Skip to content

fix(client): register union for response_format#413

Open
topenkoff wants to merge 1 commit intoopenai:mainfrom
topenkoff:response-format-union
Open

fix(client): register union for response_format#413
topenkoff wants to merge 1 commit intoopenai:mainfrom
topenkoff:response-format-union

Conversation

@topenkoff
Copy link
Copy Markdown

Hi. I noticed that unmarshaling response_format field in ChatCompletionNewParams is incorrect due to a forgotten union registration.

package main

import (
	"fmt"

	"github.com/openai/openai-go"
)

func main() {
	body := `
	{
		"model": "my_model"
		"response_format": {
			"type": "json_schema",
			"json_schema": {
				"name": "MySchema",
				"schema": {
					"type":"object",
					"properties":{
						"name":{
							"type": "string",
							"description": "The name"
						}
					},
					"additionalProperties":false,
					"required":["name"]
				}
			}
		}
	}
	`
	var params openai.ChatCompletionNewParams
	params.UnmarshalJSON([]byte(body))
	fmt.Println(params.ResponseFormat.OfText)
	raw, _ := params.MarshalJSON()
	fmt.Println(string(raw))
}
❯ go run main.go
&{json_schema {{<nil>}}}
{"model":"my_model","response_format":{"type":"json_schema"}}

@topenkoff topenkoff requested a review from a team as a code owner June 4, 2025 10:01
@khaag-apple
Copy link
Copy Markdown

@jacobzim-stl would y'all be able to take a look at this please?

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

Successfully merging this pull request may close these issues.

2 participants