Skip to content

Commit b53daa6

Browse files
committed
WIP
1 parent b44314c commit b53daa6

File tree

3 files changed

+782
-74
lines changed

3 files changed

+782
-74
lines changed

llms_wrapper/llms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import warnings
66
# TODO: Remove after https://github.com/BerriAI/litellm/issues/7560 is fixed
77
warnings.filterwarnings("ignore", category=UserWarning, module="pydantic._internal._config")
8+
warnings.filterwarnings("ignore", category=UserWarning, module="pydantic")
89
import litellm
910
import json
1011
import time
@@ -215,7 +216,7 @@ def function2schema(func, include_return_type=True):
215216

216217
props[name] = schema
217218

218-
return {
219+
funcschema = {
219220
"name": func.__name__,
220221
"description": desc,
221222
"parameters": {
@@ -224,6 +225,8 @@ def function2schema(func, include_return_type=True):
224225
"required": required
225226
}
226227
}
228+
toolschema = dict(type="function", function=funcschema)
229+
return toolschema
227230

228231

229232
class LLMS:

notebooks/dev-tooling.ipynb

Lines changed: 52 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"source": [
184184
"import os, sys\n",
185185
"from typing import Optional, List, Dict\n",
186+
"import docstring_parser\n",
186187
"sys.path.append(os.path.join(\"..\"))\n",
187188
"from llms_wrapper.llms import LLMS, toolnames2funcs, get_func_by_name\n",
188189
"from llms_wrapper.config import update_llm_config"
@@ -514,22 +515,10 @@
514515
},
515516
{
516517
"cell_type": "code",
517-
"execution_count": 15,
518+
"execution_count": 18,
518519
"id": "1818efa9",
519520
"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": [],
533522
"source": [
534523
"doc = docstring_parser.parse(testfunc1.__doc__)\n",
535524
"docret = doc.returns"
@@ -728,54 +717,20 @@
728717
},
729718
{
730719
"cell_type": "code",
731-
"execution_count": 150,
720+
"execution_count": 19,
732721
"id": "c1370d83",
733722
"metadata": {},
734723
"outputs": [
735724
{
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"
752733
]
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"
779734
}
780735
],
781736
"source": [
@@ -967,27 +922,33 @@
967922
},
968923
{
969924
"cell_type": "code",
970-
"execution_count": 151,
925+
"execution_count": 9,
971926
"id": "91edd371",
972927
"metadata": {},
973928
"outputs": [
974929
{
975930
"data": {
976931
"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']}}]"
988949
]
989950
},
990-
"execution_count": 151,
951+
"execution_count": 9,
991952
"metadata": {},
992953
"output_type": "execute_result"
993954
}
@@ -998,11 +959,29 @@
998959
},
999960
{
1000961
"cell_type": "code",
1001-
"execution_count": null,
962+
"execution_count": 11,
1002963
"id": "6b61f1e8",
1003964
"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+
]
1006985
},
1007986
{
1008987
"cell_type": "code",

0 commit comments

Comments
 (0)