MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / _remove_title_recursively

Function _remove_title_recursively

camel/toolkits/function_tool.py:45–67  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43
44
45def _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
70def get_openai_function_schema(func: Callable) -> Dict[str, Any]:

Callers 1

get_openai_tool_schemaFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected