def try_cast(
    inp: Union[str, bool, float, Prompt, ChatCompletion],
    to_type: Union[
        Type[Union[str, bool, float, Prompt, ChatCompletion]],
        List[Type[Union[str, bool, float, Prompt, ChatCompletion]]],
    ],
) -> Union[str, bool, float, Prompt, ChatCompletion]:

source code