|
183 | 183 | "source": [ |
184 | 184 | "import os, sys\n", |
185 | 185 | "from typing import Optional, List, Dict\n", |
| 186 | + "import docstring_parser\n", |
186 | 187 | "sys.path.append(os.path.join(\"..\"))\n", |
187 | 188 | "from llms_wrapper.llms import LLMS, toolnames2funcs, get_func_by_name\n", |
188 | 189 | "from llms_wrapper.config import update_llm_config" |
|
514 | 515 | }, |
515 | 516 | { |
516 | 517 | "cell_type": "code", |
517 | | - "execution_count": 15, |
| 518 | + "execution_count": 18, |
518 | 519 | "id": "1818efa9", |
519 | 520 | "metadata": {}, |
520 | | - "outputs": [ |
521 | | - { |
522 | | - "ename": "NameError", |
523 | | - "evalue": "name 'docstring_parser' is not defined", |
524 | | - "output_type": "error", |
525 | | - "traceback": [ |
526 | | - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
527 | | - "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", |
528 | | - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[15]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m doc = \u001b[43mdocstring_parser\u001b[49m.parse(testfunc1.\u001b[34m__doc__\u001b[39m)\n\u001b[32m 2\u001b[39m docret = doc.returns\n", |
529 | | - "\u001b[31mNameError\u001b[39m: name 'docstring_parser' is not defined" |
530 | | - ] |
531 | | - } |
532 | | - ], |
| 521 | + "outputs": [], |
533 | 522 | "source": [ |
534 | 523 | "doc = docstring_parser.parse(testfunc1.__doc__)\n", |
535 | 524 | "docret = doc.returns" |
|
728 | 717 | }, |
729 | 718 | { |
730 | 719 | "cell_type": "code", |
731 | | - "execution_count": 150, |
| 720 | + "execution_count": 19, |
732 | 721 | "id": "c1370d83", |
733 | 722 | "metadata": {}, |
734 | 723 | "outputs": [ |
735 | 724 | { |
736 | | - "name": "stdout", |
737 | | - "output_type": "stream", |
738 | | - "text": [ |
739 | | - "Debug: argtype for parm1: str, type: <class 'str'>\n", |
740 | | - "Debug: argtype for parm1 is a python type, converted to JSON schema {'type': 'string'}\n", |
741 | | - "Debug: argtype for parm2: None, type: <class 'NoneType'>\n", |
742 | | - "Debug: argtype for parm2 is None, skipping\n", |
743 | | - "Debug: argtype for parm3: boolean, type: <class 'str'>\n", |
744 | | - "Debug: argtype for parm3 is a python type, converted to JSON schema {'type': 'string'}\n", |
745 | | - "Debug: argtype for parm4: {\"type\": \"array!\", \"items\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"city\": {\"type\": \"string\"}}}}, type: <class 'str'>\n", |
746 | | - "Debug: argtype for parm4 is a JSON schema ({\"type\": \"array!\", \"items\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"city\": {\"type\": \"string\"}}}}), using as is\n", |
747 | | - "Debug: argtypes: {'parm1': {'type': 'string'}, 'parm3': {'type': 'string'}, 'parm4': {'type': 'array!', 'items': {'type': 'object', 'properties': {'name': {'type': 'string'}, 'city': {'type': 'string'}}}}}\n", |
748 | | - "Debug: argtype for parm1 is in argtypes, using as is: {'type': 'string'}\n", |
749 | | - "Debug: argtype for parm2 is not in argtypes, using function signature parm2: parm2: Dict[str, List[int]]\n", |
750 | | - "Debug: argtype for parm3 is in argtypes, using as is: {'type': 'string'}\n", |
751 | | - "Debug: argtype for parm4 is in argtypes, using as is: {'type': 'array!', 'items': {'type': 'object', 'properties': {'name': {'type': 'string'}, 'city': {'type': 'string'}}}}\n" |
| 725 | + "ename": "NameError", |
| 726 | + "evalue": "name 'function2schema' is not defined", |
| 727 | + "output_type": "error", |
| 728 | + "traceback": [ |
| 729 | + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
| 730 | + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", |
| 731 | + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[19]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mfunction2schema\u001b[49m(testfunc1)\n", |
| 732 | + "\u001b[31mNameError\u001b[39m: name 'function2schema' is not defined" |
752 | 733 | ] |
753 | | - }, |
754 | | - { |
755 | | - "data": { |
756 | | - "text/plain": [ |
757 | | - "{'name': 'testfunc1',\n", |
758 | | - " 'description': \"Short description of the function.\\n\\nHere is a longer description of the function. It can be multiple lines long and\\ncan contain any information that is relevant to the function.\\n\\nThe function returns: A list of person information, each having a name and city and optional other fields\\n\\nThe return type is: {'type': 'array', 'items': {'type': 'object', 'additionalProperties': {'type': 'string'}}}\",\n", |
759 | | - " 'parameters': {'type': 'object',\n", |
760 | | - " 'properties': {'parm1': {'type': 'string',\n", |
761 | | - " 'description': 'the first parameter'},\n", |
762 | | - " 'parm2': {'type': 'object',\n", |
763 | | - " 'additionalProperties': {'type': 'array', 'items': {'type': 'integer'}},\n", |
764 | | - " 'description': 'the second parameter'},\n", |
765 | | - " 'parm3': {'type': 'string',\n", |
766 | | - " 'description': 'the third parameter',\n", |
767 | | - " 'default': True},\n", |
768 | | - " 'parm4': {'type': 'array!',\n", |
769 | | - " 'items': {'type': 'object',\n", |
770 | | - " 'properties': {'name': {'type': 'string'}, 'city': {'type': 'string'}}},\n", |
771 | | - " 'description': 'the fourth parameter',\n", |
772 | | - " 'default': None}},\n", |
773 | | - " 'required': ['parm1', 'parm2']}}" |
774 | | - ] |
775 | | - }, |
776 | | - "execution_count": 150, |
777 | | - "metadata": {}, |
778 | | - "output_type": "execute_result" |
779 | 734 | } |
780 | 735 | ], |
781 | 736 | "source": [ |
|
967 | 922 | }, |
968 | 923 | { |
969 | 924 | "cell_type": "code", |
970 | | - "execution_count": 151, |
| 925 | + "execution_count": 9, |
971 | 926 | "id": "91edd371", |
972 | 927 | "metadata": {}, |
973 | 928 | "outputs": [ |
974 | 929 | { |
975 | 930 | "data": { |
976 | 931 | "text/plain": [ |
977 | | - "[{'type': 'function',\n", |
978 | | - " 'function': {'name': 'testfunc1',\n", |
979 | | - " 'description': 'Short description of the function.\\n\\nHere is a longer description of the function. It can be multiple lines long and\\ncan contain any information that is relevant to the function.',\n", |
980 | | - " 'parameters': {'type': 'object',\n", |
981 | | - " 'properties': {'parm1': {'type': 'str',\n", |
982 | | - " 'description': 'the first parameter'},\n", |
983 | | - " 'parm2': {'type': None, 'description': 'the second parameter'},\n", |
984 | | - " 'parm3': {'type': 'boolean', 'description': 'the third parameter'},\n", |
985 | | - " 'parm4': {'type': '{\"type\": \"array!\", \"items\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"city\": {\"type\": \"string\"}}}}',\n", |
986 | | - " 'description': 'the fourth parameter'}},\n", |
987 | | - " 'required': ['parm1', 'parm2']}}}]" |
| 932 | + "[{'name': 'testfunc1',\n", |
| 933 | + " 'description': \"Short description of the function.\\n\\nHere is a longer description of the function. It can be multiple lines long and\\ncan contain any information that is relevant to the function.\\n\\nThe function returns: A list of person information, each having a name and city and optional other fields\\n\\nThe return type is: {'type': 'array', 'items': {'type': 'object', 'additionalProperties': {'type': 'string'}}}\",\n", |
| 934 | + " 'parameters': {'type': 'object',\n", |
| 935 | + " 'properties': {'parm1': {'type': 'string',\n", |
| 936 | + " 'description': 'the first parameter'},\n", |
| 937 | + " 'parm2': {'type': 'object',\n", |
| 938 | + " 'additionalProperties': {'type': 'array', 'items': {'type': 'integer'}},\n", |
| 939 | + " 'description': 'the second parameter'},\n", |
| 940 | + " 'parm3': {'type': 'string',\n", |
| 941 | + " 'description': 'the third parameter',\n", |
| 942 | + " 'default': True},\n", |
| 943 | + " 'parm4': {'type': 'array!',\n", |
| 944 | + " 'items': {'type': 'object',\n", |
| 945 | + " 'properties': {'name': {'type': 'string'}, 'city': {'type': 'string'}}},\n", |
| 946 | + " 'description': 'the fourth parameter',\n", |
| 947 | + " 'default': None}},\n", |
| 948 | + " 'required': ['parm1', 'parm2']}}]" |
988 | 949 | ] |
989 | 950 | }, |
990 | | - "execution_count": 151, |
| 951 | + "execution_count": 9, |
991 | 952 | "metadata": {}, |
992 | 953 | "output_type": "execute_result" |
993 | 954 | } |
|
998 | 959 | }, |
999 | 960 | { |
1000 | 961 | "cell_type": "code", |
1001 | | - "execution_count": null, |
| 962 | + "execution_count": 11, |
1002 | 963 | "id": "6b61f1e8", |
1003 | 964 | "metadata": {}, |
1004 | | - "outputs": [], |
1005 | | - "source": [] |
| 965 | + "outputs": [ |
| 966 | + { |
| 967 | + "data": { |
| 968 | + "text/plain": [ |
| 969 | + "[{'name': 'query_names',\n", |
| 970 | + " 'description': 'Query the customer database and return a list of matching names. \\n\\nThis function queries the customer database using the conditions in the where clause and returns\\na list of matching customers. The where clause may use the DB fields \"city\", \"company_name\",\\n\"country\" and \"since_date\" to limit the returned customer list. The where clause can also \\nbe followed by a limit clause to limit the number of returned names.\\n\\nThe function returns: a list of matching customer names\\n\\nThe return type is: {\\'type\\': \\'array\\', \\'items\\': {\\'type\\': \\'string\\'}}',\n", |
| 971 | + " 'parameters': {'type': 'object',\n", |
| 972 | + " 'properties': {'where_clause': {'type': 'string',\n", |
| 973 | + " 'description': 'the string containing the where and optionally limit clauses in SQL query format'}},\n", |
| 974 | + " 'required': ['where_clause']}}]" |
| 975 | + ] |
| 976 | + }, |
| 977 | + "execution_count": 11, |
| 978 | + "metadata": {}, |
| 979 | + "output_type": "execute_result" |
| 980 | + } |
| 981 | + ], |
| 982 | + "source": [ |
| 983 | + "llms.make_tooling(query_names)" |
| 984 | + ] |
1006 | 985 | }, |
1007 | 986 | { |
1008 | 987 | "cell_type": "code", |
|
0 commit comments