fix hyperlink (#1052)

This commit is contained in:
James Hills 2024-02-27 09:17:56 -08:00 committed by GitHub
parent 28f7e88382
commit 88051d4185
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 279 additions and 403 deletions

View File

@ -114,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -125,6 +125,7 @@
" temperature=1.0,\n",
" stop=None,\n",
" tools=None,\n",
" functions=None\n",
") -> str:\n",
" params = {\n",
" 'model': model,\n",
@ -134,6 +135,8 @@
" 'stop': stop,\n",
" 'tools': tools,\n",
" }\n",
" if functions:\n",
" params['functions'] = functions\n",
"\n",
" completion = client.chat.completions.create(**params)\n",
" return completion.choices[0].message\n"
@ -181,279 +184,240 @@
"source": [
"function_list = [\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",
" \"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",
" },\n",
" \"required\": [\"altitude\"]\n",
" }\n",
" },\n",
" {\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",
" \"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",
" \"required\": [\"location\"],\n",
" \"coordinates\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"GPS coordinates for custom landing location. Required if location is 'custom'.\"\n",
" }\n",
" },\n",
" },\n",
" \"required\": [\"location\"]\n",
" }\n",
" },\n",
" {\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",
" \"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",
" \"required\": [\"direction\", \"distance\"],\n",
" \"distance\": {\n",
" \"type\": \"integer\",\n",
" \"description\": \"Distance in meters the drone should travel in the specified direction.\"\n",
" }\n",
" },\n",
" },\n",
" \"required\": [\"direction\", \"distance\"]\n",
" }\n",
" },\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",
" \"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",
" },\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",
" },\n",
" \"required\": [\"speed\"],\n",
" \"duration\": {\n",
" \"type\": \"integer\",\n",
" \"description\": \"Duration in seconds for video capture. Required if mode is 'video'.\"\n",
" }\n",
" },\n",
" },\n",
" \"required\": [\"mode\"]\n",
" }\n",
" },\n",
" {\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",
" \"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",
" \"required\": [\"mode\"],\n",
" \"pan\": {\n",
" \"type\": \"integer\",\n",
" \"description\": \"Pan angle for the gimbal in degrees.\"\n",
" }\n",
" },\n",
" },\n",
" \"required\": [\"tilt\", \"pan\"]\n",
" }\n",
" },\n",
" {\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",
" \"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",
" },\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",
" },\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",
" },\n",
" \"required\": [\"status\"]\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",
" },\n",
" \"required\": [\"mode\"]\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",
" },\n",
" \"required\": [\"status\"]\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",
" },\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",
" },\n",
" \"required\": [\"status\"]\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",
" },\n",
" \"required\": [\"tilt\", \"pan\"],\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",
" },\n",
" \"required\": [\"pattern\"]\n",
" }\n",
" },\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",
" \"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",
" },\n",
" \"required\": [\"coordinates\"]\n",
" }\n",
" },\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",
" \"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",
" },\n",
" },\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",
" },\n",
" },\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",
" },\n",
" },\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",
" \"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",
" },\n",
" },\n",
" {\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",
" \"required\": [\"pattern\"],\n",
" },\n",
" },\n",
" },\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",
" },\n",
" },\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",
" \"name\": \"reject_request\",\n",
" \"description\": \"Use this function if the request is not possible.\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {}\n",
" }\n",
" },\n",
"]\n"
]
@ -487,16 +451,16 @@
"output_type": "stream",
"text": [
"Land the drone at the home base\n",
"Function(arguments='{\\n \"location\": \"home_base\"\\n}', name='land_drone') \n",
"FunctionCall(arguments='{\\n \"location\": \"home_base\"\\n}', name='land_drone') \n",
"\n",
"Take off the drone to 50 meters\n",
"Function(arguments='{\\n \"altitude\": 50\\n}', name='takeoff_drone') \n",
"FunctionCall(arguments='{\\n \"altitude\": 50\\n}', name='takeoff_drone') \n",
"\n",
"change speed to 15 kilometers per hour\n",
"Function(arguments='{\\n \"speed\": 15\\n}', name='set_drone_speed') \n",
"FunctionCall(arguments='{ \"speed\": 15 }', name='set_drone_speed') \n",
"\n",
"turn into an elephant!\n",
"Function(arguments='{}', name='reject_request') \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n"
]
}
@ -508,7 +472,7 @@
" messages.append({\"role\": \"user\", \"content\": prompt})\n",
" completion = get_chat_completion(model=\"gpt-3.5-turbo\",messages=messages,tools=function_list)\n",
" print(prompt)\n",
" print(completion.tool_calls[0].function,'\\n')\n"
" print(completion.function_call,'\\n')\n"
]
},
{
@ -533,7 +497,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -541,28 +505,23 @@
"output_type": "stream",
"text": [
"Play pre-recorded audio message\n",
"Function(arguments='{}', name='reject_request') \n",
"\n",
"FunctionCall(arguments='{}', name='reject_request')\n",
"\n",
"\n",
"Initiate live-streaming on social media\n",
"Function(arguments='{\\n\"mode\": \"video\",\\n\"duration\": 0\\n}', name='control_camera') \n",
"\n",
"FunctionCall(arguments='{\\n \"mode\": \"video\",\\n \"duration\": 0\\n}', name='control_camera')\n",
"\n",
"\n",
"Scan environment for heat signatures\n",
"Function(arguments='{ \"mode\": \"photo\" }', name='control_camera') \n",
"\n",
"FunctionCall(arguments='{\\n \"mode\": \"photo\"\\n}', name='control_camera')\n",
"\n",
"\n",
"Enable stealth mode\n",
"Function(arguments='{\\n \"mode\": \"off\"\\n}', name='set_drone_lighting') \n",
"\n",
"FunctionCall(arguments='{\\n \"mode\": \"off\"\\n}', name='set_drone_lighting')\n",
"\n",
"\n",
"Change drone's paint job color\n",
"Function(arguments='{\\n \"pattern\": \"solid\",\\n \"color\": \"blue\"\\n}', name='configure_led_display') \n",
"\n",
"FunctionCall(arguments='{\\n \"pattern\": \"solid\",\\n \"color\": \"blue\"\\n}', name='configure_led_display')\n",
"\n",
"\n"
]
@ -576,10 +535,10 @@
" completion = get_chat_completion(model=\"gpt-3.5-turbo\",messages=messages,tools=function_list)\n",
" print(prompt)\n",
" try:\n",
" print(completion.tool_calls[0].function,'\\n')\n",
" print(completion.function_call)\n",
" print('\\n')\n",
" except:\n",
" print(completion.tool_calls[0].content,'\\n')\n",
" print(completion.content)\n",
" print('\\n')\n"
]
},
@ -625,7 +584,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@ -645,7 +604,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@ -752,7 +711,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@ -822,7 +781,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@ -830,8 +789,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['function']['name']\n",
" params = function['function']['parameters']\n",
" func_name = function[\"name\"]\n",
" params = 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",
@ -858,21 +817,22 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def create_commands(invocation_list):\n",
" example_list = []\n",
" for i, invocation in enumerate(invocation_list):\n",
" print(f'\\033[34m{np.round(100*i/len(invocation_list),1)}% complete\\033[0m')\n",
" print(invocation)\n",
" if i<10:\n",
" print(f'\\033[34m{np.round(100*i/len(invocation_list),1)}% complete\\033[0m')\n",
" print(invocation)\n",
"\n",
" # Format the prompt with the invocation string\n",
" request_prompt = COMMAND_GENERATION_PROMPT.format(invocation=invocation)\n",
"\n",
" messages = [{\"role\": \"user\", \"content\": f\"{request_prompt}\"}]\n",
" completion = get_chat_completion(messages,temperature=0.8).content\n",
" completion = get_chat_completion(messages,temperature=0.8)\n",
" command_dict = {\n",
" \"Input\": invocation,\n",
" \"Prompt\": completion\n",
@ -883,7 +843,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@ -894,121 +854,28 @@
"{'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",
"\u001b[34m3.6% complete\u001b[0m\n",
"{'name': 'land_drone', 'arguments': {'location': 'home_base'}}\n",
"\u001b[34m5.3% complete\u001b[0m\n",
"\u001b[34m5.4% complete\u001b[0m\n",
"{'name': 'land_drone', 'arguments': {'location': 'custom'}}\n",
"\u001b[34m7.0% complete\u001b[0m\n",
"\u001b[34m7.1% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'forward', 'distance': 50}}\n",
"\u001b[34m8.8% complete\u001b[0m\n",
"\u001b[34m8.9% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'backward', 'distance': 10}}\n",
"\u001b[34m10.5% complete\u001b[0m\n",
"\u001b[34m10.7% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'left', 'distance': 10}}\n",
"\u001b[34m12.3% complete\u001b[0m\n",
"\u001b[34m12.5% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'right', 'distance': 10}}\n",
"\u001b[34m14.0% complete\u001b[0m\n",
"\u001b[34m14.3% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'up', 'distance': 20}}\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': 30}}\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"
"\u001b[34m16.1% complete\u001b[0m\n",
"{'name': 'control_drone_movement', 'arguments': {'direction': 'down', 'distance': 10}}\n"
]
}
],
"source": [
"training_examples_unformatted = create_commands(input_objects)"
"#Only printing the first 10 rows\n",
"training_examples_unformatted = create_commands(input_objects)\n"
]
},
{
@ -1020,23 +887,25 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"training_examples = []\n",
"\n",
"for prompt in training_examples_unformatted:\n",
" #adjust formatting for training data specs\n",
" try:\n",
" prompt[\"Input\"] = ast.literal_eval(prompt[\"Input\"])\n",
" except:\n",
" continue\n",
"\n",
" #if its not a dict, convert to dict\n",
" if type(prompt['Input'])!=dict:\n",
" prompt['Input'] = ast.literal_eval(prompt['Input'])\n",
" prompt['Input']['arguments']=json.dumps(prompt['Input']['arguments'])\n",
" for p in prompt['Prompt']:\n",
" for p in ast.literal_eval(prompt['Prompt'].content):\n",
" training_examples.append({\"messages\": [{\"role\":\"system\",\"content\":DRONE_SYSTEM_PROMPT\n",
" },{\"role\":\"user\",\"content\": p},\n",
" {\"role\":\"assistant\",\"function_call\": prompt['Input']}],\n",
" \"functions\":[func['function'] for func in function_list]})\n"
" \"functions\":function_list})\n",
"\n"
]
},
{
@ -1048,7 +917,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
@ -1071,7 +940,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@ -1082,7 +951,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\":[func['function'] for func in function_list]})\n"
" \"functions\":function_list})\n"
]
},
{
@ -1094,7 +963,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
@ -1103,7 +972,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
@ -1130,14 +999,14 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"file-CGMggG5iZYKTocwgCp7kV7C6\n"
"file-xrLV8EbNZk31QPT1TB5KIx7E\n"
]
}
],
@ -1172,7 +1041,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 22,
"metadata": {},
"outputs": [
{
@ -1180,19 +1049,19 @@
"output_type": "stream",
"text": [
"Play pre-recorded audio message\n",
"reject_request \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n",
"Initiate live-streaming on social media\n",
"reject_request \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n",
"Scan environment for heat signatures\n",
"reject_request \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n",
"Enable stealth mode\n",
"reject_request \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n",
"Change drone's paint job color\n",
"reject_request \n",
"FunctionCall(arguments='{}', name='reject_request') \n",
"\n"
]
}
@ -1204,7 +1073,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,tools=function_list)\n",
" print(eval_question)\n",
" print(completion.tool_calls[0].function.name,'\\n')\n"
" print(completion.function_call,'\\n')\n"
]
},
{

View File

@ -431,9 +431,16 @@
"source": [
"For the first two questions, our model asserts with (near) 100% confidence that the article has sufficient context to answer the posed questions.<br><br>\n",
"On the other hand, for the more tricky questions which are less clearly answered in the article, the model is less confident that it has sufficient context. This is a great guardrail to help ensure our retrieved content is sufficient.<br><br>\n",
"This self-evaluation can help reduce hallucinations, as you can restrict answers or re-prompt the user when your `sufficient_context_for_answer` log probability is below a certain threshold. Methods like this have been shown to significantly reduce RAG for Q&A hallucinations and errors ([Example]((https://jfan001.medium.com/how-we-cut-the-rate-of-gpt-hallucinations-from-20-to-less-than-2-f3bfcc10e4ec)))"
"This self-evaluation can help reduce hallucinations, as you can restrict answers or re-prompt the user when your `sufficient_context_for_answer` log probability is below a certain threshold. Methods like this have been shown to significantly reduce RAG for Q&A hallucinations and errors ([Example](https://jfan001.medium.com/how-we-cut-the-rate-of-gpt-hallucinations-from-20-to-less-than-2-f3bfcc10e4ec)) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},