Skip to content

fix(client): register union for response_format #413

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

topenkoff
Copy link

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
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.

1 participant