@@ -43,6 +43,20 @@ def extract_params(doc_str: str) -> dict[str, str]:
43
43
return params
44
44
45
45
46
+ def extract_return_description (docstring ):
47
+ """
48
+ Extract the return description from a Python docstring.
49
+
50
+ :param docstring: The docstring to extract the return description from.
51
+ :return: The return description, or empty string if no return description is found.
52
+ """
53
+ match = re .search (r':return: (.*)' , docstring )
54
+ if match :
55
+ return " " + match .group (1 )
56
+ else :
57
+ return ""
58
+
59
+
46
60
def func_to_json (func ) -> dict [str , any ]:
47
61
"""
48
62
Convert a function to a json schema
@@ -68,6 +82,7 @@ def func_to_json(func) -> dict[str, any]:
68
82
func_doc = inspect .getdoc (_func )
69
83
# parse the docstring to get the description
70
84
func_description = '' .join ([line for line in func_doc .split ("\n " ) if not line .strip ().startswith (':' )])
85
+ func_description += extract_return_description (func_doc )
71
86
# parse the docstring to get the descriptions for each parameter in dict format
72
87
param_details = extract_params (func_doc ) if func_doc else {}
73
88
# attach parameter types to params and exclude fixed args
@@ -87,7 +102,7 @@ def func_to_json(func) -> dict[str, any]:
87
102
argspec .args [i ] not in inspect .getfullargspec (_func ).defaults and argspec .args [
88
103
i ] not in fixed_args .keys ()]
89
104
# then return everything in dict
90
- #TODO: Move this to OpenAIFunctionWrapper
105
+ # TODO: Move this to OpenAIFunctionWrapper
91
106
return {
92
107
"name" : func_name ,
93
108
"description" : func_description ,
0 commit comments