langchaingo icon indicating copy to clipboard operation
langchaingo copied to clipboard

jsonschema: Omit properties when not populated

Open tmc opened this issue 1 year ago • 3 comments

While populating "properties" for non-object types is OK it is possible that this would confuse some parsers, so we should only output properties when it's populated.

tmc avatar Feb 25 '24 01:02 tmc

but the properties are more, when we remove the empty key, doesn't it generate an inconsistency?

devalexandre avatar Mar 08 '24 16:03 devalexandre

An initial idea

func removeEmptyKeys(originalMap map[string]Definition) map[string]Definition {
	filteredMap := make(map[string]Definition)

	for key, value := range originalMap {
		if key != "" {
			if value.Properties != nil {
				value.Properties = removeEmptyKeys(value.Properties)
			}
			filteredMap[key] = value
		}
	}

	return filteredMap
}

devalexandre avatar Mar 08 '24 16:03 devalexandre

@devalexandre I was considering something as simple as:

-       Properties map[string]Definition `json:"properties"`
+       Properties map[string]Definition `json:"properties,omitempty"`

I was adding support for fireworks.ai and the above fix seems sufficient to get function invocations with them working fine/better.

tmc avatar Mar 13 '24 23:03 tmc