r"""Recursively removes the 'title' key from all levels of a nested dictionary, except when 'title' is an argument name in the schema.
(data, parent_key=None)
| 43 | |
| 44 | |
| 45 | def _remove_title_recursively(data, parent_key=None): |
| 46 | r"""Recursively removes the 'title' key from all levels of a nested |
| 47 | dictionary, except when 'title' is an argument name in the schema. |
| 48 | """ |
| 49 | if isinstance(data, dict): |
| 50 | # Only remove 'title' if it's not an argument name |
| 51 | if parent_key not in [ |
| 52 | "properties", |
| 53 | "$defs", |
| 54 | "items", |
| 55 | "allOf", |
| 56 | "oneOf", |
| 57 | "anyOf", |
| 58 | ]: |
| 59 | data.pop("title", None) |
| 60 | |
| 61 | # Recursively process each key-value pair |
| 62 | for key, value in data.items(): |
| 63 | _remove_title_recursively(value, parent_key=key) |
| 64 | elif isinstance(data, list): |
| 65 | # Recursively process each element in the list |
| 66 | for item in data: |
| 67 | _remove_title_recursively(item, parent_key=parent_key) |
| 68 | |
| 69 | |
| 70 | def get_openai_function_schema(func: Callable) -> Dict[str, Any]: |
no outgoing calls
no test coverage detected