def get_typed_kwargs_from_simple_json_schema(
simple_json_schema: dict | str
) -> TypedKwargs:
if isinstance(simple_json_schema, str):
simple_json_schema = json.loads(simple_json_schema)
typed_kwargs_dict = {}
try:
for name, type_ in simple_json_schema.items():
if isinstance(type_, str):
typed_kwargs_dict[name] = STRING_TO_TYPE_MAP[type_.lower()]
if isinstance(type_, dict):
for type_1, type_2 in type_.items():
typed_kwargs_dict[name] = Dict[
string_to_type_or_error(type_1),
string_to_type_or_error(type_2)
]
break
if isinstance(type_, list):
if len(type_) > 0:
typed_kwargs_dict[name] = List[
string_to_type_or_error(type_[0])
]
else:
typed_kwargs_dict[name] = list
except KeyError as error:
message = f'Type {simple_json_schema} is not recognized'
raise TypingRecoverableException(message) from error
return TypedKwargs(typed_kwargs_dict)