langchaingo
langchaingo copied to clipboard
jsonschema: Omit properties when not populated
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.
but the properties are more, when we remove the empty key, doesn't it generate an inconsistency?
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 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.