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

fix: invalid schema for function 'func_name': None is not of type 'object' (#429)(#432) #434

Merged

Conversation

vvatanabe
Copy link
Collaborator

@vvatanabe vvatanabe commented Jul 10, 2023

Describe the change
The problem recurs when Parameters is a value instead of a pointer. MarshalJSON in Definition does not execute MarshalJSON if Definition is a value because the receiver is a pointer.

func (d *Definition) MarshalJSON() ([]byte, error)

Refs:

error message:

 invalid schema for function 'func_name': None is not of type 'object' 

request to reproduce:

	req := openai.ChatCompletionRequest{
		Model: openai.GPT3Dot5Turbo,
		Messages: []openai.ChatCompletionMessage{
			{
				Role:    openai.ChatMessageRoleUser,
				Content: "What is the weather like in Boston?",
			},
		},
		Functions: []openai.FunctionDefinition{{
			Name: "get_current_weather",
			Parameters: jsonschema.Definition{ // <= The problem recurs when Parameters is a value instead of a pointer.
				Type: jsonschema.Object,
				Properties: map[string]jsonschema.Definition{
					"location": {
						Type:        jsonschema.String,
						Description: "The city and state, e.g. San Francisco, CA",
					},
					"unit": {
						Type: jsonschema.String,
						Enum: []string{"celsius", "fahrenheit"},
					},
				},
				Required: []string{"location"},
			},
		}},
	}

Describe your solution

  • MarshalJSON method is executed whether jsonschema.Definition in Parameters is a pointer or a value
  • Initialization with an empty map if Properties is nil.

Tests

  • Test MarshalJSON with both value and pointer.
  • add integration test for function call.

Additional context
Issue: #429, #432

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #434 (df10cf3) into master (f028c28) will not change coverage.
The diff coverage is n/a.

❗ Current head df10cf3 differs from pull request most recent head f793e8b. Consider uploading reports for the commit f793e8b to get more accurate results

@@           Coverage Diff           @@
##           master     #434   +/-   ##
=======================================
  Coverage   97.02%   97.02%           
=======================================
  Files          17       17           
  Lines         705      705           
=======================================
  Hits          684      684           
  Misses         15       15           
  Partials        6        6           

@vvatanabe
Copy link
Collaborator Author

@sashabaranov Please check it.

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

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