Skip to content
Snippets Groups Projects
02-dynamic-routes.ipynb 39.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • James Briggs's avatar
    James Briggs committed
          "text/plain": [
           "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}], similarity_score=None)"
    
    James Briggs's avatar
    James Briggs committed
         },
    
         "execution_count": 30,
    
    James Briggs's avatar
    James Briggs committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "response = rl2(\"What is the time difference between Los Angeles and Istanbul?\")\n",
        "response"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 31,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "2jxAIi6rg9hv",
        "outputId": "8abff974-602f-4c0d-8d21-3a275b0eee62"
       },
       "outputs": [
    
    James Briggs's avatar
    James Briggs committed
         "name": "stdout",
         "output_type": "stream",
         "text": [
    
          "The time difference between America/Los_Angeles and Europe/Istanbul is 11.0 hours.\n"
         ]
        },
        {
         "name": "stderr",
         "output_type": "stream",
         "text": [
          "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_13320\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n",
          "  now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n"
    
    James Briggs's avatar
    James Briggs committed
         ]
        }
       ],
       "source": [
        "parse_response(response)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {
        "id": "14qz-ApLg9hv"
       },
       "source": [
        "### Testing the `multi_function_route` - The `convert_time` Function"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 32,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "PzM1HH7Rg9hv",
        "outputId": "e123c86f-9754-453a-d895-bfcce26110d4"
       },
       "outputs": [
    
    James Briggs's avatar
    James Briggs committed
         "name": "stderr",
         "output_type": "stream",
         "text": [
    
          "2025-01-06 12:10:55 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n",
          "2025-01-06 12:10:59 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
    
    James Briggs's avatar
    James Briggs committed
         ]
    
    James Briggs's avatar
    James Briggs committed
         "data": {
          "text/plain": [
           "RouteChoice(name='timezone_management', function_call=[{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}], similarity_score=None)"
    
    James Briggs's avatar
    James Briggs committed
         },
    
         "execution_count": 32,
    
    James Briggs's avatar
    James Briggs committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "response = rl2(\"What is 23:02 Dubai time in Tokyo time? Please and thank you.\")\n",
        "response"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 33,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "QFKZ757Pg9hv",
        "outputId": "af5c1328-f6dd-4dc7-c104-e920198885fc"
       },
       "outputs": [
    
    James Briggs's avatar
    James Briggs committed
         "name": "stdout",
         "output_type": "stream",
         "text": [
          "04:02\n"
         ]
        }
       ],
       "source": [
        "parse_response(response)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {
        "id": "TSRfC6JJg9hv"
       },
       "source": [
        "### The Cool Bit - Testing `multi_function_route` - Multiple Functions at Once"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 34,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "Vnj6A3AVg9hv",
        "outputId": "c8a61c3f-a504-430b-82fb-c211c0523dcb"
       },
       "outputs": [
    
    James Briggs's avatar
    James Briggs committed
         "name": "stderr",
         "output_type": "stream",
         "text": [
    
          "2025-01-06 12:11:03 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n",
          "2025-01-06 12:11:05 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
    
    James Briggs's avatar
    James Briggs committed
         ]
        }
       ],
       "source": [
        "response = rl2(\n",
        "    \"\"\"\n",
        "    What is the time in Prague?\n",
        "    What is the time difference between Frankfurt and Beijing?\n",
        "    What is 5:53 Lisbon time in Bangkok time?\n",
        "\"\"\"\n",
        ")"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 35,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "L9jq_Yoag9hv",
        "outputId": "50fae028-4af4-46f5-f6e9-4262b8874caa"
       },
       "outputs": [
    
    James Briggs's avatar
    James Briggs committed
         "data": {
          "text/plain": [
           "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}], similarity_score=None)"
    
    James Briggs's avatar
    James Briggs committed
         },
    
         "execution_count": 35,
    
    James Briggs's avatar
    James Briggs committed
         "metadata": {},
         "output_type": "execute_result"
    
    James Briggs's avatar
    James Briggs committed
       ],
       "source": [
        "response"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 36,
    
    James Briggs's avatar
    James Briggs committed
       "metadata": {
        "id": "Hw3raSVBg9hv",
        "outputId": "d30b9cba-979d-4bdf-86e0-37c550c4187d"
       },
       "outputs": [
        {
         "name": "stdout",
         "output_type": "stream",
         "text": [
    
          "13:11\n",
          "The time difference between Europe/Berlin and Asia/Shanghai is 7.0 hours.\n",
          "12:53\n"
         ]
        },
        {
         "name": "stderr",
         "output_type": "stream",
         "text": [
          "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_13320\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n",
          "  now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n"
    
    James Briggs's avatar
    James Briggs committed
         ]
    
    James Briggs's avatar
    James Briggs committed
        }
    
    James Briggs's avatar
    James Briggs committed
       ],
       "source": [
        "parse_response(response)"
       ]
      }
     ],
     "metadata": {
      "colab": {
       "provenance": []
      },
      "kernelspec": {
       "display_name": "decision-layer",
       "language": "python",
       "name": "python3"
    
    James Briggs's avatar
    James Briggs committed
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
       "version": "3.12.7"
    
    James Briggs's avatar
    James Briggs committed
      }
     },
     "nbformat": 4,
     "nbformat_minor": 0