@@ -1145,37 +1145,34 @@ def get_placeholders_dict(placeholders: list, model_name: str) -> dict:
1145
1145
place_holder_value = getattr (
1146
1146
getattr (auto_module , PLACEHOLDER_TO_AUTO_MODULE [placeholder ][0 ]),
1147
1147
PLACEHOLDER_TO_AUTO_MODULE [placeholder ][1 ],
1148
- )[model_name ]
1149
- if isinstance (place_holder_value , (list , tuple )):
1150
- place_holder_value = place_holder_value [0 ]
1151
- placeholders_dict [placeholder ] = place_holder_value
1148
+ ).get (model_name , None )
1149
+ if place_holder_value is not None :
1150
+ if isinstance (place_holder_value , (list , tuple )):
1151
+ place_holder_value = place_holder_value [0 ]
1152
+ placeholders_dict [placeholder ] = place_holder_value
1153
+ else :
1154
+ placeholders_dict [placeholder ] = placeholder
1152
1155
1153
1156
return placeholders_dict
1154
1157
1155
1158
1156
- def format_args_docstring (args , model_name ):
1159
+ def format_args_docstring (docstring , model_name ):
1157
1160
"""
1158
1161
Replaces placeholders such as {image_processor_class} in the docstring with the actual values,
1159
1162
deducted from the model name and the auto modules.
1160
1163
"""
1161
- # first check if there are any placeholders in the args , if not return them as is
1162
- placeholders = set (re .findall (r"{(.*?)}" , "" . join ( args [ arg ][ "description" ] for arg in args ) ))
1164
+ # first check if there are any placeholders in the docstring , if not return it as is
1165
+ placeholders = set (re .findall (r"{(.*?)}" , docstring ))
1163
1166
if not placeholders :
1164
- return args
1167
+ return docstring
1165
1168
1166
1169
# get the placeholders dictionary for the given model name
1167
1170
placeholders_dict = get_placeholders_dict (placeholders , model_name )
1171
+ # replace the placeholders in the docstring with the values from the placeholders_dict
1172
+ for placeholder , value in placeholders_dict .items ():
1173
+ docstring = docstring .replace (f"{{{ placeholder } }}" , value )
1168
1174
1169
- # replace the placeholders in the args with the values from the placeholders_dict
1170
- for arg in args :
1171
- new_arg = args [arg ]["description" ]
1172
- placeholders = re .findall (r"{(.*?)}" , new_arg )
1173
- placeholders = [placeholder for placeholder in placeholders if placeholder in placeholders_dict ]
1174
- if placeholders :
1175
- new_arg = new_arg .format (** {placeholder : placeholders_dict [placeholder ] for placeholder in placeholders })
1176
- args [arg ]["description" ] = new_arg
1177
-
1178
- return args
1175
+ return docstring
1179
1176
1180
1177
1181
1178
def get_args_doc_from_source (args_classes : Union [object , list [object ]]) -> dict :
@@ -1494,8 +1491,6 @@ def _process_kwargs_parameters(
1494
1491
kwargs_documentation = kwarg_param .annotation .__args__ [0 ].__doc__
1495
1492
if kwargs_documentation is not None :
1496
1493
documented_kwargs , _ = parse_docstring (kwargs_documentation )
1497
- if model_name_lowercase is not None :
1498
- documented_kwargs = format_args_docstring (documented_kwargs , model_name_lowercase )
1499
1494
1500
1495
# Process each kwarg parameter
1501
1496
for param_name , param_type_annotation in kwarg_param .annotation .__args__ [0 ].__annotations__ .items ():
@@ -1573,8 +1568,6 @@ def _process_parameters_section(
1573
1568
# Parse existing docstring if available
1574
1569
if func_documentation is not None :
1575
1570
documented_params , func_documentation = parse_docstring (func_documentation )
1576
- if model_name_lowercase is not None :
1577
- documented_params = format_args_docstring (documented_params , model_name_lowercase )
1578
1571
1579
1572
# Process regular parameters
1580
1573
param_docstring , missing_args = _process_regular_parameters (
@@ -1772,6 +1765,9 @@ def auto_method_docstring(
1772
1765
)
1773
1766
docstring += example_docstring
1774
1767
1768
+ # Format the docstring with the placeholders
1769
+ docstring = format_args_docstring (docstring , model_name_lowercase )
1770
+
1775
1771
# Assign the dynamically generated docstring to the wrapper function
1776
1772
func .__doc__ = docstring
1777
1773
return func
0 commit comments