diff --git a/examples/Fine_tuning_for_function_calling.ipynb b/examples/Fine_tuning_for_function_calling.ipynb index 8a9236aec0..5f49599fab 100644 --- a/examples/Fine_tuning_for_function_calling.ipynb +++ b/examples/Fine_tuning_for_function_calling.ipynb @@ -118,7 +118,6 @@ "metadata": {}, "outputs": [], "source": [ - "@retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(5))\n", "def get_chat_completion(\n", " messages: list[dict[str, str]],\n", " model: str = \"gpt-4\",\n", @@ -135,7 +134,7 @@ " 'stop': stop,\n", " }\n", " if functions:\n", - " params['functions'] = functions\n", + " params['tools'] = functions\n", "\n", " completion = client.chat.completions.create(**params)\n", " return completion.choices[0].message\n" @@ -183,240 +182,279 @@ "source": [ "function_list = [\n", " {\n", - " \"name\": \"takeoff_drone\",\n", - " \"description\": \"Initiate the drone's takeoff sequence.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"altitude\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Specifies the altitude in meters to which the drone should ascend.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"takeoff_drone\",\n", + " \"description\": \"Initiate the drone's takeoff sequence.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"altitude\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Specifies the altitude in meters to which the drone should ascend.\",\n", + " }\n", + " },\n", + " \"required\": [\"altitude\"],\n", " },\n", - " \"required\": [\"altitude\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"land_drone\",\n", - " \"description\": \"Land the drone at its current location or a specified landing point.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"location\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"current\", \"home_base\", \"custom\"],\n", - " \"description\": \"Specifies the landing location for the drone.\"\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"land_drone\",\n", + " \"description\": \"Land the drone at its current location or a specified landing point.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"location\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"current\", \"home_base\", \"custom\"],\n", + " \"description\": \"Specifies the landing location for the drone.\",\n", + " },\n", + " \"coordinates\": {\n", + " \"type\": \"object\",\n", + " \"description\": \"GPS coordinates for custom landing location. Required if location is 'custom'.\",\n", + " },\n", " },\n", - " \"coordinates\": {\n", - " \"type\": \"object\",\n", - " \"description\": \"GPS coordinates for custom landing location. Required if location is 'custom'.\"\n", - " }\n", + " \"required\": [\"location\"],\n", " },\n", - " \"required\": [\"location\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"control_drone_movement\",\n", - " \"description\": \"Direct the drone's movement in a specific direction.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"direction\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"forward\", \"backward\", \"left\", \"right\", \"up\", \"down\"],\n", - " \"description\": \"Direction in which the drone should move.\"\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"control_drone_movement\",\n", + " \"description\": \"Direct the drone's movement in a specific direction.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"direction\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"forward\", \"backward\", \"left\", \"right\", \"up\", \"down\"],\n", + " \"description\": \"Direction in which the drone should move.\",\n", + " },\n", + " \"distance\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Distance in meters the drone should travel in the specified direction.\",\n", + " },\n", " },\n", - " \"distance\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Distance in meters the drone should travel in the specified direction.\"\n", - " }\n", + " \"required\": [\"direction\", \"distance\"],\n", " },\n", - " \"required\": [\"direction\", \"distance\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_drone_speed\",\n", - " \"description\": \"Adjust the speed of the drone.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"speed\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Specifies the speed in km/h.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_drone_speed\",\n", + " \"description\": \"Adjust the speed of the drone.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"speed\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Specifies the speed in km/h.\",\n", + " }\n", + " },\n", + " \"required\": [\"speed\"],\n", " },\n", - " \"required\": [\"speed\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"control_camera\",\n", - " \"description\": \"Control the drone's camera to capture images or videos.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"mode\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"photo\", \"video\", \"panorama\"],\n", - " \"description\": \"Camera mode to capture content.\"\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"control_camera\",\n", + " \"description\": \"Control the drone's camera to capture images or videos.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"mode\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"photo\", \"video\", \"panorama\"],\n", + " \"description\": \"Camera mode to capture content.\",\n", + " },\n", + " \"duration\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Duration in seconds for video capture. Required if mode is 'video'.\",\n", + " },\n", " },\n", - " \"duration\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Duration in seconds for video capture. Required if mode is 'video'.\"\n", - " }\n", + " \"required\": [\"mode\"],\n", " },\n", - " \"required\": [\"mode\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"control_gimbal\",\n", - " \"description\": \"Adjust the drone's gimbal for camera stabilization and direction.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"tilt\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Tilt angle for the gimbal in degrees.\"\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"control_gimbal\",\n", + " \"description\": \"Adjust the drone's gimbal for camera stabilization and direction.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"tilt\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Tilt angle for the gimbal in degrees.\",\n", + " },\n", + " \"pan\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Pan angle for the gimbal in degrees.\",\n", + " },\n", " },\n", - " \"pan\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Pan angle for the gimbal in degrees.\"\n", - " }\n", + " \"required\": [\"tilt\", \"pan\"],\n", " },\n", - " \"required\": [\"tilt\", \"pan\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_drone_lighting\",\n", - " \"description\": \"Control the drone's lighting for visibility and signaling.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"mode\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"on\", \"off\", \"blink\", \"sos\"],\n", - " \"description\": \"Lighting mode for the drone.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_drone_lighting\",\n", + " \"description\": \"Control the drone's lighting for visibility and signaling.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"mode\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"on\", \"off\", \"blink\", \"sos\"],\n", + " \"description\": \"Lighting mode for the drone.\",\n", + " }\n", + " },\n", + " \"required\": [\"mode\"],\n", " },\n", - " \"required\": [\"mode\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"return_to_home\",\n", - " \"description\": \"Command the drone to return to its home or launch location.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {}\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"return_to_home\",\n", + " \"description\": \"Command the drone to return to its home or launch location.\",\n", + " \"parameters\": {\"type\": \"object\", \"properties\": {}},\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_battery_saver_mode\",\n", - " \"description\": \"Toggle battery saver mode.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"status\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"on\", \"off\"],\n", - " \"description\": \"Toggle battery saver mode.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_battery_saver_mode\",\n", + " \"description\": \"Toggle battery saver mode.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"status\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"on\", \"off\"],\n", + " \"description\": \"Toggle battery saver mode.\",\n", + " }\n", + " },\n", + " \"required\": [\"status\"],\n", " },\n", - " \"required\": [\"status\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_obstacle_avoidance\",\n", - " \"description\": \"Configure obstacle avoidance settings.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"mode\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"on\", \"off\"],\n", - " \"description\": \"Toggle obstacle avoidance.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_obstacle_avoidance\",\n", + " \"description\": \"Configure obstacle avoidance settings.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"mode\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"on\", \"off\"],\n", + " \"description\": \"Toggle obstacle avoidance.\",\n", + " }\n", + " },\n", + " \"required\": [\"mode\"],\n", " },\n", - " \"required\": [\"mode\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_follow_me_mode\",\n", - " \"description\": \"Enable or disable 'follow me' mode.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"status\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"on\", \"off\"],\n", - " \"description\": \"Toggle 'follow me' mode.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_follow_me_mode\",\n", + " \"description\": \"Enable or disable 'follow me' mode.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"status\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"on\", \"off\"],\n", + " \"description\": \"Toggle 'follow me' mode.\",\n", + " }\n", + " },\n", + " \"required\": [\"status\"],\n", " },\n", - " \"required\": [\"status\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"calibrate_sensors\",\n", - " \"description\": \"Initiate calibration sequence for drone's sensors.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {}\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"calibrate_sensors\",\n", + " \"description\": \"Initiate calibration sequence for drone's sensors.\",\n", + " \"parameters\": {\"type\": \"object\", \"properties\": {}},\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_autopilot\",\n", - " \"description\": \"Enable or disable autopilot mode.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"status\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"on\", \"off\"],\n", - " \"description\": \"Toggle autopilot mode.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_autopilot\",\n", + " \"description\": \"Enable or disable autopilot mode.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"status\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"on\", \"off\"],\n", + " \"description\": \"Toggle autopilot mode.\",\n", + " }\n", + " },\n", + " \"required\": [\"status\"],\n", " },\n", - " \"required\": [\"status\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"configure_led_display\",\n", - " \"description\": \"Configure the drone's LED display pattern and colors.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"pattern\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"solid\", \"blink\", \"pulse\", \"rainbow\"],\n", - " \"description\": \"Pattern for the LED display.\"\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"configure_led_display\",\n", + " \"description\": \"Configure the drone's LED display pattern and colors.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"pattern\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"solid\", \"blink\", \"pulse\", \"rainbow\"],\n", + " \"description\": \"Pattern for the LED display.\",\n", + " },\n", + " \"color\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"red\", \"blue\", \"green\", \"yellow\", \"white\"],\n", + " \"description\": \"Color for the LED display. Not required if pattern is 'rainbow'.\",\n", + " },\n", " },\n", - " \"color\": {\n", - " \"type\": \"string\",\n", - " \"enum\": [\"red\", \"blue\", \"green\", \"yellow\", \"white\"],\n", - " \"description\": \"Color for the LED display. Not required if pattern is 'rainbow'.\"\n", - " }\n", + " \"required\": [\"pattern\"],\n", " },\n", - " \"required\": [\"pattern\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"set_home_location\",\n", - " \"description\": \"Set or change the home location for the drone.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"coordinates\": {\n", - " \"type\": \"object\",\n", - " \"description\": \"GPS coordinates for the home location.\"\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"set_home_location\",\n", + " \"description\": \"Set or change the home location for the drone.\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"coordinates\": {\n", + " \"type\": \"object\",\n", + " \"description\": \"GPS coordinates for the home location.\",\n", + " }\n", + " },\n", + " \"required\": [\"coordinates\"],\n", " },\n", - " \"required\": [\"coordinates\"]\n", - " }\n", + " },\n", " },\n", " {\n", - " \"name\": \"reject_request\",\n", - " \"description\": \"Use this function if the request is not possible.\",\n", - " \"parameters\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {}\n", - " }\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"reject_request\",\n", + " \"description\": \"Use this function if the request is not possible.\",\n", + " \"parameters\": {\"type\": \"object\", \"properties\": {}},\n", + " },\n", " },\n", "]\n" ] @@ -450,16 +488,16 @@ "output_type": "stream", "text": [ "Land the drone at the home base\n", - "FunctionCall(arguments='{\\n \"location\": \"home_base\"\\n}', name='land_drone') \n", + "Function(arguments='{\\n \"location\": \"home_base\"\\n}', name='land_drone') \n", "\n", "Take off the drone to 50 meters\n", - "FunctionCall(arguments='{\\n \"altitude\": 50\\n}', name='takeoff_drone') \n", + "Function(arguments='{\\n \"altitude\": 50\\n}', name='takeoff_drone') \n", "\n", "change speed to 15 kilometers per hour\n", - "FunctionCall(arguments='{\\n \"speed\": 15\\n}', name='set_drone_speed') \n", + "Function(arguments='{\\n \"speed\": 15\\n}', name='set_drone_speed') \n", "\n", "turn into an elephant!\n", - "FunctionCall(arguments='{}', name='reject_request') \n", + "Function(arguments='{}', name='reject_request') \n", "\n" ] } @@ -471,7 +509,7 @@ " messages.append({\"role\": \"user\", \"content\": prompt})\n", " completion = get_chat_completion(model=\"gpt-3.5-turbo\",messages=messages,functions=function_list)\n", " print(prompt)\n", - " print(completion.function_call,'\\n')\n" + " print(completion.tool_calls[0].function,'\\n')\n" ] }, { @@ -498,29 +536,54 @@ "cell_type": "code", "execution_count": 9, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "ChatCompletionMessage(content=None, role='assistant', function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_6rwNKuIgO7l8Izw5qoFcuSuk', function=Function(arguments='{}', name='reject_request'), type='function')])" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "completion\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Play pre-recorded audio message\n", - "FunctionCall(arguments='{}', name='reject_request')\n", + "Function(arguments='{}', name='reject_request') \n", + "\n", "\n", "\n", "Initiate live-streaming on social media\n", - "FunctionCall(arguments='{\\n\"mode\": \"video\",\\n\"duration\": 0\\n}', name='control_camera')\n", + "Function(arguments='{\\n\"mode\": \"video\"\\n}', name='control_camera') \n", + "\n", "\n", "\n", "Scan environment for heat signatures\n", - "None\n", + "Function(arguments='{\\n \"mode\": \"photo\"\\n}', name='control_camera') \n", + "\n", "\n", "\n", "Enable stealth mode\n", - "FunctionCall(arguments='{\\n \"mode\": \"off\"\\n}', name='set_drone_lighting')\n", + "Function(arguments='{\\n \"pattern\": \"solid\",\\n \"color\": \"black\"\\n}', name='configure_led_display') \n", + "\n", "\n", "\n", "Change drone's paint job color\n", - "FunctionCall(arguments='{\\n \"pattern\": \"solid\",\\n \"color\": \"blue\"\\n}', name='configure_led_display')\n", + "Function(arguments='{\\n \"pattern\": \"solid\",\\n \"color\": \"blue\"\\n}', name='configure_led_display') \n", + "\n", "\n", "\n" ] @@ -534,10 +597,10 @@ " completion = get_chat_completion(model=\"gpt-3.5-turbo\",messages=messages,functions=function_list)\n", " print(prompt)\n", " try:\n", - " print(completion.function_call)\n", + " print(completion.tool_calls[0].function,'\\n')\n", " print('\\n')\n", " except:\n", - " print(completion.content)\n", + " print(completion.tool_calls[0].content,'\\n')\n", " print('\\n')\n" ] }, @@ -583,7 +646,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -603,7 +666,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -710,7 +773,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -780,7 +843,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -788,8 +851,8 @@ "all_but_reject = [f for f in function_list if f.get('name') != 'reject_request']\n", "\n", "for function in all_but_reject:\n", - " func_name = function[\"name\"]\n", - " params = function[\"parameters\"]\n", + " func_name = function['function']['name']\n", + " params = function['function']['parameters']\n", " for arguments in generate_permutations(params):\n", " if any(val in arguments.values() for val in ['fill_in_int', 'fill_in_str']):\n", " input_object = {\n", @@ -816,7 +879,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -841,9 +904,130 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[34m0.0% complete\u001b[0m\n", + "{'name': 'takeoff_drone', 'arguments': {'altitude': 100}}\n", + "\u001b[34m1.8% complete\u001b[0m\n", + "{'name': 'land_drone', 'arguments': {'location': 'current'}}\n", + "\u001b[34m3.5% complete\u001b[0m\n", + "{'name': 'land_drone', 'arguments': {'location': 'home_base'}}\n", + "\u001b[34m5.3% complete\u001b[0m\n", + "{'name': 'land_drone', 'arguments': {'location': 'custom'}}\n", + "\u001b[34m7.0% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'forward', 'distance': 50}}\n", + "\u001b[34m8.8% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'backward', 'distance': 10}}\n", + "\u001b[34m10.5% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'left', 'distance': 10}}\n", + "\u001b[34m12.3% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'right', 'distance': 10}}\n", + "\u001b[34m14.0% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'up', 'distance': 10}}\n", + "\u001b[34m15.8% complete\u001b[0m\n", + "{'name': 'control_drone_movement', 'arguments': {'direction': 'down', 'distance': 10}}\n", + "\u001b[34m17.5% complete\u001b[0m\n", + "{'name': 'set_drone_speed', 'arguments': {'speed': 20}}\n", + "\u001b[34m19.3% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'photo'}}\n", + "\u001b[34m21.1% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'photo', 'duration': 0}}\n", + "\u001b[34m22.8% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'video'}}\n", + "\u001b[34m24.6% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'video', 'duration': 60}}\n", + "\u001b[34m26.3% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'panorama'}}\n", + "\u001b[34m28.1% complete\u001b[0m\n", + "{'name': 'control_camera', 'arguments': {'mode': 'panorama', 'duration': 0}}\n", + "\u001b[34m29.8% complete\u001b[0m\n", + "{'name': 'control_gimbal', 'arguments': {'tilt': 45, 'pan': 90}}\n", + "\u001b[34m31.6% complete\u001b[0m\n", + "{'name': 'set_drone_lighting', 'arguments': {'mode': 'on'}}\n", + "\u001b[34m33.3% complete\u001b[0m\n", + "{'name': 'set_drone_lighting', 'arguments': {'mode': 'off'}}\n", + "\u001b[34m35.1% complete\u001b[0m\n", + "{'name': 'set_drone_lighting', 'arguments': {'mode': 'blink'}}\n", + "\u001b[34m36.8% complete\u001b[0m\n", + "{'name': 'set_drone_lighting', 'arguments': {'mode': 'sos'}}\n", + "\u001b[34m38.6% complete\u001b[0m\n", + "{'name': 'return_to_home', 'arguments': {}}\n", + "\u001b[34m40.4% complete\u001b[0m\n", + "{'name': 'set_battery_saver_mode', 'arguments': {'status': 'on'}}\n", + "\u001b[34m42.1% complete\u001b[0m\n", + "{'name': 'set_battery_saver_mode', 'arguments': {'status': 'off'}}\n", + "\u001b[34m43.9% complete\u001b[0m\n", + "{'name': 'set_obstacle_avoidance', 'arguments': {'mode': 'on'}}\n", + "\u001b[34m45.6% complete\u001b[0m\n", + "{'name': 'set_obstacle_avoidance', 'arguments': {'mode': 'off'}}\n", + "\u001b[34m47.4% complete\u001b[0m\n", + "{'name': 'set_follow_me_mode', 'arguments': {'status': 'on'}}\n", + "\u001b[34m49.1% complete\u001b[0m\n", + "{'name': 'set_follow_me_mode', 'arguments': {'status': 'off'}}\n", + "\u001b[34m50.9% complete\u001b[0m\n", + "{'name': 'calibrate_sensors', 'arguments': {}}\n", + "\u001b[34m52.6% complete\u001b[0m\n", + "{'name': 'set_autopilot', 'arguments': {'status': 'on'}}\n", + "\u001b[34m54.4% complete\u001b[0m\n", + "{'name': 'set_autopilot', 'arguments': {'status': 'off'}}\n", + "\u001b[34m56.1% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid'}}\n", + "\u001b[34m57.9% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid', 'color': 'red'}}\n", + "\u001b[34m59.6% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid', 'color': 'blue'}}\n", + "\u001b[34m61.4% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid', 'color': 'green'}}\n", + "\u001b[34m63.2% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid', 'color': 'yellow'}}\n", + "\u001b[34m64.9% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'solid', 'color': 'white'}}\n", + "\u001b[34m66.7% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink'}}\n", + "\u001b[34m68.4% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink', 'color': 'red'}}\n", + "\u001b[34m70.2% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink', 'color': 'blue'}}\n", + "\u001b[34m71.9% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink', 'color': 'green'}}\n", + "\u001b[34m73.7% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink', 'color': 'yellow'}}\n", + "\u001b[34m75.4% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'blink', 'color': 'white'}}\n", + "\u001b[34m77.2% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse'}}\n", + "\u001b[34m78.9% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse', 'color': 'red'}}\n", + "\u001b[34m80.7% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse', 'color': 'blue'}}\n", + "\u001b[34m82.5% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse', 'color': 'green'}}\n", + "\u001b[34m84.2% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse', 'color': 'yellow'}}\n", + "\u001b[34m86.0% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'pulse', 'color': 'white'}}\n", + "\u001b[34m87.7% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow'}}\n", + "\u001b[34m89.5% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow', 'color': 'red'}}\n", + "\u001b[34m91.2% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow', 'color': 'blue'}}\n", + "\u001b[34m93.0% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow', 'color': 'green'}}\n", + "\u001b[34m94.7% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow', 'color': 'yellow'}}\n", + "\u001b[34m96.5% complete\u001b[0m\n", + "{'name': 'configure_led_display', 'arguments': {'pattern': 'rainbow', 'color': 'white'}}\n", + "\u001b[34m98.2% complete\u001b[0m\n", + "{'name': 'reject_request', 'arguments': {}}\n" + ] + } + ], "source": [ "training_examples_unformatted = create_commands(input_objects)\n" ] @@ -857,7 +1041,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -873,7 +1057,7 @@ " training_examples.append({\"messages\": [{\"role\":\"system\",\"content\":DRONE_SYSTEM_PROMPT\n", " },{\"role\":\"user\",\"content\": p},\n", " {\"role\":\"assistant\",\"function_call\": prompt['Input']}],\n", - " \"functions\":function_list})\n" + " \"functions\":[func['function'] for func in function_list]})\n" ] }, { @@ -885,7 +1069,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -908,7 +1092,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -919,7 +1103,7 @@ " reject_training_list.append({\"messages\": [{\"role\":\"system\",\"content\":DRONE_SYSTEM_PROMPT\n", " },{\"role\":\"user\",\"content\": prompt},\n", " {\"role\":\"assistant\",\"function_call\": {\"name\": \"reject_request\",\"arguments\": \"{}\"}}],\n", - " \"functions\":function_list})\n" + " \"functions\":[func['function'] for func in function_list]})\n" ] }, { @@ -931,7 +1115,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -940,7 +1124,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -967,9 +1151,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "file-CGMggG5iZYKTocwgCp7kV7C6\n" + ] + } + ], "source": [ "if __name__ == \"__main__\":\n", " file = client.files.create(\n", @@ -1002,9 +1194,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Play pre-recorded audio message\n", + "reject_request \n", + "\n", + "Initiate live-streaming on social media\n", + "reject_request \n", + "\n", + "Scan environment for heat signatures\n", + "reject_request \n", + "\n", + "Enable stealth mode\n", + "reject_request \n", + "\n", + "Change drone's paint job color\n", + "reject_request \n", + "\n" + ] + } + ], "source": [ "for eval_question in challenging_prompts:\n", " messages = []\n", @@ -1012,7 +1226,7 @@ " messages.append({\"role\": \"user\", \"content\": eval_question})\n", " completion = get_chat_completion(model=\"ft:gpt-3.5-turbo-0613:openai-internal::8DloQKS2\",messages=messages,functions=function_list)\n", " print(eval_question)\n", - " print(completion.function_call,'\\n')\n" + " print(completion.tool_calls[0].function.name,'\\n')\n" ] }, {