Skip to content

Commit 1ccbc73

Browse files
committed
fixes #61
1 parent 9b34b6b commit 1ccbc73

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

01_funccall.ipynb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,11 @@
736736
{
737737
"cell_type": "code",
738738
"execution_count": null,
739-
"id": "23f54386",
739+
"id": "748da965",
740740
"metadata": {},
741741
"outputs": [],
742742
"source": [
743-
"#| exports\n",
743+
"#| export\n",
744744
"def get_schema(\n",
745745
" f:Union[callable,dict], # Function to get schema for\n",
746746
" pname='input_schema', # Key name for parameters\n",
@@ -754,7 +754,12 @@
754754
" assert desc, \"Docstring missing!\"\n",
755755
" d = docments(f, full=True)\n",
756756
" ret = d.pop('return')\n",
757-
" if (ret.anno is not empty) and (ret.anno is not None): desc += f'\\n\\nReturns:\\n- type: {_types(ret.anno)[0]}'\n",
757+
" has_type = (ret.anno is not empty) and (ret.anno is not None)\n",
758+
" has_doc = ret.docment\n",
759+
" if has_type or has_doc:\n",
760+
" type_str = f'type: {_types(ret.anno)[0]}'\n",
761+
" ret_str = f'{ret.docment} ({type_str})' if has_type and has_doc else (type_str if has_type else ret.docment)\n",
762+
" desc += f'\\n\\nReturns:\\n- {ret_str}'\n",
758763
" return {\"name\": f.__name__, \"description\": desc, pname: schema}"
759764
]
760765
},
@@ -768,7 +773,7 @@
768773
"data": {
769774
"text/plain": [
770775
"{'name': 'get_schema',\n",
771-
" 'description': 'Generate JSON schema for a class, function, or method\\n\\nReturns:\\n- type: object',\n",
776+
" 'description': \"Generate JSON schema for a class, function, or method\\n\\nReturns:\\n- {'name':..., 'description':..., pname:...} (type: object)\",\n",
772777
" 'input_schema': {'type': 'object',\n",
773778
" 'properties': {'f': {'type': 'object',\n",
774779
" 'description': 'Function to get schema for',\n",
@@ -823,7 +828,7 @@
823828
"Adds a + b.\n",
824829
"\n",
825830
"Returns:\n",
826-
"- type: integer\n"
831+
"- The sum of the inputs (type: integer)\n"
827832
]
828833
},
829834
{
@@ -872,7 +877,7 @@
872877
"data": {
873878
"text/plain": [
874879
"{'name': 'silly_test',\n",
875-
" 'description': 'Mandatory docstring',\n",
880+
" 'description': 'Mandatory docstring\\n\\nReturns:\\n- type: integer',\n",
876881
" 'input_schema': {'type': 'object',\n",
877882
" 'properties': {'a': {'type': 'integer', 'description': 'quoted type hint'}},\n",
878883
" 'required': ['a']}}"
@@ -886,7 +891,7 @@
886891
"source": [
887892
"def silly_test(\n",
888893
" a: 'int', # quoted type hint\n",
889-
"):\n",
894+
")->int:\n",
890895
" \"Mandatory docstring\"\n",
891896
" return a\n",
892897
"\n",
@@ -911,7 +916,7 @@
911916
"data": {
912917
"text/plain": [
913918
"{'name': 'sums',\n",
914-
" 'description': 'Adds a + b.\\n\\nReturns:\\n- type: integer',\n",
919+
" 'description': 'Adds a + b.',\n",
915920
" 'input_schema': {'type': 'object',\n",
916921
" 'properties': {'a': {'type': 'integer', 'description': 'First thing to sum'},\n",
917922
" 'b': {'type': 'integer',\n",
@@ -931,7 +936,7 @@
931936
" self,\n",
932937
" a:int, # First thing to sum\n",
933938
" b:int=1 # Second thing to sum\n",
934-
" ) -> int: # The sum of the inputs\n",
939+
" ): # The sum of the inputs\n",
935940
" \"Adds a + b.\"\n",
936941
" print(f\"Finding the sum of {a} and {b}\")\n",
937942
" return a + b\n",

toolslm/funccall.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ def get_schema(
141141
assert desc, "Docstring missing!"
142142
d = docments(f, full=True)
143143
ret = d.pop('return')
144-
if (ret.anno is not empty) and (ret.anno is not None): desc += f'\n\nReturns:\n- type: {_types(ret.anno)[0]}'
144+
has_type = (ret.anno is not empty) and (ret.anno is not None)
145+
has_doc = ret.docment
146+
if has_type or has_doc:
147+
type_str = f'type: {_types(ret.anno)[0]}'
148+
ret_str = f'{ret.docment} ({type_str})' if has_type and has_doc else (type_str if has_type else ret.docment)
149+
desc += f'\n\nReturns:\n- {ret_str}'
145150
return {"name": f.__name__, "description": desc, pname: schema}
146151

147152
# %% ../01_funccall.ipynb

0 commit comments

Comments
 (0)