Skip to content

Commit

Permalink
Fix version related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
synacktraa committed Sep 22, 2024
1 parent da42cbe commit df0f87c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 313 deletions.
312 changes: 9 additions & 303 deletions cookbooks/gorillaLLM-integration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@
"id": "-Eo0djkPhFFb",
"outputId": "6596b3bc-c04c-4a4a-e38e-f13119bf6194"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m41.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m10.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m137.5/137.5 MB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
],
"outputs": [],
"source": [
"#@title Install and import necessary libraries\n",
"%pip install -qU tool-parse[pydantic] duckduckgo_search\n",
Expand Down Expand Up @@ -137,31 +126,7 @@
"id": "SP9V5lGFkeD6",
"outputId": "c750b19a-c285-4fe6-f5d8-f3201456c5d2"
},
"outputs": [
{
"data": {
"text/plain": [
"{'type': 'function',\n",
" 'function': {'name': 'search_text',\n",
" 'description': 'Search for text in the web.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'text': {'type': 'string',\n",
" 'description': 'Text to search for.'},\n",
" 'safe_search': {'type': 'boolean',\n",
" 'description': 'If True, enable safe search.'},\n",
" 'backend': {'enum': ['api', 'html', 'lite'],\n",
" 'type': 'string',\n",
" 'description': 'Backend to use for retrieving results.'},\n",
" 'max_results': {'type': 'integer',\n",
" 'description': 'Max results to return.'}},\n",
" 'required': ['text']}}}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"\"\"\"\n",
"Lets take a look at each tool schema, we can get a particular tool schema from the registry like we're accessing a dictionary object with a key\n",
Expand All @@ -179,34 +144,7 @@
"id": "HfYA9KjxonV9",
"outputId": "89ffd1d1-3daf-4a13-beb9-87abc656cbdc"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
},
{
"data": {
"text/plain": [
"{'type': 'function',\n",
" 'function': {'name': 'product_information',\n",
" 'description': 'Information about the product.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'name': {'type': 'string',\n",
" 'description': 'Name of the product.'},\n",
" 'price': {'type': 'number', 'description': 'Price of the product.'},\n",
" 'in_stock': {'type': 'boolean',\n",
" 'description': 'If the product is in stock.'}},\n",
" 'required': ['name', 'price', 'in_stock']}}}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"print('ProductInfo' in tr) # Original name is ProductInfo but we gave it a custom name so it will return False\n",
"tr['product_information']"
Expand All @@ -222,27 +160,7 @@
"id": "Goo0IAp-o98B",
"outputId": "9b880952-4f10-4520-f3f9-18beecb00983"
},
"outputs": [
{
"data": {
"text/plain": [
"{'type': 'function',\n",
" 'function': {'name': 'get_translation',\n",
" 'description': 'Translate the given text.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'text': {'type': 'string',\n",
" 'description': 'Text to translate.'},\n",
" 'to': {'enum': ['en', 'ja', 'hi', 'es', 'fr', 'de', 'zh'],\n",
" 'type': 'string',\n",
" 'description': 'what language to translate.'}},\n",
" 'required': ['text']}}}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"tr['get_translation']"
]
Expand Down Expand Up @@ -379,148 +297,7 @@
"id": "3M2f1MgphNjv",
"outputId": "c1a29423-799c-492d-a636-89dba8326be6"
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "483f65df966b48d8b62abc8094e3f9c8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"tokenizer_config.json: 0%| | 0.00/4.24k [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72547d880c39424993bc752ba97052d0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"tokenizer.json: 0%| | 0.00/4.61M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "aeb7131aa1cb4f3b820f5063fbc9a557",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"special_tokens_map.json: 0%| | 0.00/462 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "21ad73d3a8c2472994817d3996dee28e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"config.json: 0%| | 0.00/669 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "26a90b7cb9b643378bb7dbc3a8c5aadb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"pytorch_model.bin.index.json: 0%| | 0.00/22.5k [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "39803456cda546ae8bb12a2c8c519b76",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading shards: 0%| | 0/2 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1d2e6a0c0c2d4cef9bf6d3cf5e059ffd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"pytorch_model-00001-of-00002.bin: 0%| | 0.00/9.97G [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "182c12f2b5d74fe091298276324afbfb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"pytorch_model-00002-of-00002.bin: 0%| | 0.00/3.85G [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0a5b954c58e14b6b8bbbf01a51e71789",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "089005c09ed84c55b0ddae0151158979",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"generation_config.json: 0%| | 0.00/121 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32\n",
"\n",
Expand Down Expand Up @@ -572,51 +349,7 @@
"id": "KgMj4vdmhK4v",
"outputId": "83b37b9d-a7fe-4677-b4cc-b9d34d415ecf"
},
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'function',\n",
" 'function': {'name': 'search_text',\n",
" 'description': 'Search for text in the web.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'text': {'type': 'string',\n",
" 'description': 'Text to search for.'},\n",
" 'safe_search': {'type': 'boolean',\n",
" 'description': 'If True, enable safe search.'},\n",
" 'backend': {'enum': ['api', 'html', 'lite'],\n",
" 'type': 'string',\n",
" 'description': 'Backend to use for retrieving results.'},\n",
" 'max_results': {'type': 'integer',\n",
" 'description': 'Max results to return.'}},\n",
" 'required': ['text']}}},\n",
" {'type': 'function',\n",
" 'function': {'name': 'product_information',\n",
" 'description': 'Information about the product.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'name': {'type': 'string',\n",
" 'description': 'Name of the product.'},\n",
" 'price': {'type': 'number', 'description': 'Price of the product.'},\n",
" 'in_stock': {'type': 'boolean',\n",
" 'description': 'If the product is in stock.'}},\n",
" 'required': ['name', 'price', 'in_stock']}}},\n",
" {'type': 'function',\n",
" 'function': {'name': 'get_translation',\n",
" 'description': 'Translate the given text.',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'text': {'type': 'string',\n",
" 'description': 'Text to translate.'},\n",
" 'to': {'enum': ['en', 'ja', 'hi', 'es', 'fr', 'de', 'zh'],\n",
" 'type': 'string',\n",
" 'description': 'what language to translate.'}},\n",
" 'required': ['text']}}}]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Getting schema of registered tools\n",
"\n",
Expand All @@ -634,16 +367,7 @@
"id": "VQpRHlLXpaPG",
"outputId": "922107a8-3fd5-49d0-deaa-6f7c66ddb9c4"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"expression=\"search_text(text='gorilla')\"\n",
"output=[{'title': 'Gorilla - Wikipedia', 'href': 'https://en.wikipedia.org/wiki/Gorilla', 'body': 'The word gorilla comes from the history of Hanno the Navigator (c. 500 BC), a Carthaginian explorer on an expedition to the west African coast to the area that later became Sierra Leone. [1] [2] Members of the expedition encountered \"savage people, the greater part of whom were women, whose bodies were hairy, and whom our interpreters called Gorillae\".[3] [4] It is unknown whether what the ...'}]\n"
]
}
],
"outputs": [],
"source": [
"# Search text\n",
"expression = get_gorilla_expression(\n",
Expand All @@ -666,16 +390,7 @@
"id": "1M7Nt9yoqAL_",
"outputId": "b7609cea-228d-4f77-bdb3-0e98e2ea79ad"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"expression=\"product_information(name='RTX 4900', price=3500, in_stock=True)\"\n",
"output=ProductInfo(name='RTX 4900', price=3500.0, in_stock=True)\n"
]
}
],
"outputs": [],
"source": [
"# Extracting product information\n",
"expression = get_gorilla_expression(\n",
Expand All @@ -698,16 +413,7 @@
"id": "8KcCJ7X3q3Sn",
"outputId": "afedf3b0-52a9-41cc-8e68-721998a1e51b"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"expression=\"get_translation(text='Tool calling is one of the best features of LLM', to='hi')\"\n",
"output=[{'detected_language': 'en', 'translated': 'टूल कॉलिंग एलएलएम की सबसे अच्छी विशेषताओं में से एक है', 'original': 'Tool calling is one of the best features of LLM'}]\n"
]
}
],
"outputs": [],
"source": [
"# Translation\n",
"expression = get_gorilla_expression(\n",
Expand Down
Loading

0 comments on commit df0f87c

Please sign in to comment.