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

json: cannot unmarshal object into Go struct field ChatCompletionResponseFormatJSONSchema.response_format.json_schema.schema of type json.Marshaler #884

Open
nodelrd opened this issue Oct 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@nodelrd
Copy link

nodelrd commented Oct 22, 2024

json: cannot unmarshal object into Go struct field ChatCompletionResponseFormatJSONSchema.response_format.json_schema.schema of type json.Marshaler

github.com/sashabaranov/go-openai v1.32.3

@nodelrd nodelrd added the bug Something isn't working label Oct 22, 2024
@lei-lei-shanda
Copy link

lei-lei-shanda commented Nov 6, 2024

I can confirm the bug. this is a minimal working example, taken from openai example:

package main

import (
	"encoding/json"

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

const request = `
{
    "model": "gpt-4o-2024-08-06",
    "stream": true,
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful math tutor. Guide the user through the solution step by step."
      },
      {
        "role": "user",
        "content": "how can I solve 8x + 7 = -23"
      }
    ],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "math_reasoning",
        "schema": {
          "type": "object",
          "properties": {
            "steps": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "explanation": { "type": "string" },
                  "output": { "type": "string" }
                },
                "required": ["explanation", "output"],
                "additionalProperties": false
              }
            },
            "final_answer": { "type": "string" }
          },
          "required": ["steps", "final_answer"],
          "additionalProperties": false
        },
        "strict": true
      }
    }
  }
`

func main() {
	ccr := &goopenai.ChatCompletionRequest{}
	err := json.Unmarshal([]byte(request), ccr)
	if err != nil {
		panic(err)
	}
}

the issue here is that json.Marshaler is an interface. It would be better if this is jsonschema.Definition or json.RawMessage.

@lei-lei-shanda
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants