Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- .idea/workspace.xml +4 -4
- __pycache__/prompts.cpython-311.pyc +0 -0
- app.py +30 -39
- commands.txt +1 -1
- prompts.py +1 -1
- server/uav_api.py +0 -1
- test/test_multiplecommands.py +61 -0
- test/test_singlecommands.py +119 -0
- test/test_unviablecommands.py +71 -0
.idea/workspace.xml
CHANGED
|
@@ -6,8 +6,7 @@
|
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="fa28c5e7-7701-41dc-9f17-0b006dec0c27" name="Changes" comment="">
|
| 8 |
<change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
|
| 9 |
-
<change beforePath="$PROJECT_DIR$/
|
| 10 |
-
<change beforePath="$PROJECT_DIR$/uav_api.py" beforeDir="false" />
|
| 11 |
</list>
|
| 12 |
<option name="SHOW_DIALOG" value="false" />
|
| 13 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -189,7 +188,8 @@
|
|
| 189 |
<workItem from="1690062126029" duration="3577000" />
|
| 190 |
<workItem from="1690068665233" duration="59000" />
|
| 191 |
<workItem from="1691001889072" duration="1298000" />
|
| 192 |
-
<workItem from="1691003416341" duration="
|
|
|
|
| 193 |
</task>
|
| 194 |
<servers />
|
| 195 |
</component>
|
|
@@ -228,7 +228,7 @@
|
|
| 228 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_invalid_command2.coverage" NAME="pytest for test_fewshot.test_invalid_command2 Coverage Results" MODIFIED="1689919761343" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 229 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$gradio_theme.coverage" NAME="gradio_theme Coverage Results" MODIFIED="1690008184752" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 230 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_location_no_action4.coverage" NAME="pytest for test_fewshot.test_location_no_action4 Coverage Results" MODIFIED="1689926082281" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 231 |
-
<SUITE FILE_PATH="coverage/conversational_uav_explorer$app.coverage" NAME="app Coverage Results" MODIFIED="
|
| 232 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$testing.coverage" NAME="testing Coverage Results" MODIFIED="1689806315429" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 233 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_no_location1.coverage" NAME="pytest for test_fewshot.test_no_location1 Coverage Results" MODIFIED="1689810960745" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 234 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_parking_garage.coverage" NAME="pytest for test_fewshot.test_parking_garage Coverage Results" MODIFIED="1689923732887" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
|
|
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="fa28c5e7-7701-41dc-9f17-0b006dec0c27" name="Changes" comment="">
|
| 8 |
<change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
|
| 9 |
+
<change beforePath="$PROJECT_DIR$/prompts.py" beforeDir="false" afterPath="$PROJECT_DIR$/prompts.py" afterDir="false" />
|
|
|
|
| 10 |
</list>
|
| 11 |
<option name="SHOW_DIALOG" value="false" />
|
| 12 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
|
|
| 188 |
<workItem from="1690062126029" duration="3577000" />
|
| 189 |
<workItem from="1690068665233" duration="59000" />
|
| 190 |
<workItem from="1691001889072" duration="1298000" />
|
| 191 |
+
<workItem from="1691003416341" duration="16951000" />
|
| 192 |
+
<workItem from="1691213146639" duration="1326000" />
|
| 193 |
</task>
|
| 194 |
<servers />
|
| 195 |
</component>
|
|
|
|
| 228 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_invalid_command2.coverage" NAME="pytest for test_fewshot.test_invalid_command2 Coverage Results" MODIFIED="1689919761343" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 229 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$gradio_theme.coverage" NAME="gradio_theme Coverage Results" MODIFIED="1690008184752" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 230 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_location_no_action4.coverage" NAME="pytest for test_fewshot.test_location_no_action4 Coverage Results" MODIFIED="1689926082281" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 231 |
+
<SUITE FILE_PATH="coverage/conversational_uav_explorer$app.coverage" NAME="app Coverage Results" MODIFIED="1691214438868" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 232 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$testing.coverage" NAME="testing Coverage Results" MODIFIED="1689806315429" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 233 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_no_location1.coverage" NAME="pytest for test_fewshot.test_no_location1 Coverage Results" MODIFIED="1689810960745" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
| 234 |
<SUITE FILE_PATH="coverage/conversational_uav_explorer$pytest_for_test_fewshot_test_parking_garage.coverage" NAME="pytest for test_fewshot.test_parking_garage Coverage Results" MODIFIED="1689923732887" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
__pycache__/prompts.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/prompts.cpython-311.pyc and b/__pycache__/prompts.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -5,23 +5,6 @@ from fewshot import FewShot4UAVs
|
|
| 5 |
|
| 6 |
fewshot = FewShot4UAVs()
|
| 7 |
|
| 8 |
-
"""def send_command(command, location=None):
|
| 9 |
-
url = f"http://url/{command}"
|
| 10 |
-
data = {}
|
| 11 |
-
if location:
|
| 12 |
-
data["location"] = location
|
| 13 |
-
response = requests.post(url, json=data)
|
| 14 |
-
return response.content
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def parse_command(text):
|
| 18 |
-
tokens = re.split(' \t|\n|: ', text.lower())
|
| 19 |
-
print(tokens)
|
| 20 |
-
if len(tokens) >= 2:
|
| 21 |
-
return tokens[1]
|
| 22 |
-
else:
|
| 23 |
-
return 'none'"""
|
| 24 |
-
|
| 25 |
|
| 26 |
def transcribe(audio):
|
| 27 |
messages = [
|
|
@@ -29,33 +12,41 @@ def transcribe(audio):
|
|
| 29 |
"content": prompt_chat_response}
|
| 30 |
]
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
messages=messages
|
| 48 |
-
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
return chat_transcript
|
| 59 |
|
| 60 |
|
| 61 |
with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
|
@@ -63,7 +54,7 @@ with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
|
| 63 |
# Conversational UAV Explorer
|
| 64 |
Press record and speak into the microphone to give a command. Make sure to stop recording before pressing "Give Command."\n\n
|
| 65 |
Commands: Take picture, Go to, Land, Take off""")
|
| 66 |
-
with gr.Row()
|
| 67 |
audio_input = gr.Audio(source="microphone", type="filepath")
|
| 68 |
output = gr.Textbox(label="Transcript")
|
| 69 |
with gr.Row():
|
|
|
|
| 5 |
|
| 6 |
fewshot = FewShot4UAVs()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def transcribe(audio):
|
| 10 |
messages = [
|
|
|
|
| 12 |
"content": prompt_chat_response}
|
| 13 |
]
|
| 14 |
|
| 15 |
+
try:
|
| 16 |
+
audio_file = open(audio, "rb")
|
| 17 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
| 18 |
|
| 19 |
+
original_transcript = transcript["text"]
|
| 20 |
+
messages.append({"role": "user", "content": original_transcript, "name": "Operator"})
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"An error occurred during transcribing: {e}")
|
| 23 |
+
return str(e) # Return the error message to Gradio UI
|
| 24 |
|
| 25 |
+
try:
|
| 26 |
+
formatted_command_text = fewshot.get_command(original_transcript)
|
| 27 |
+
messages.append({"role": "function", "content": formatted_command_text, "name": "UAV"})
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"An error occurred during formatting the command: {e}")
|
| 30 |
+
return str(e)
|
| 31 |
|
| 32 |
+
try:
|
| 33 |
+
response = openai.ChatCompletion.create(
|
| 34 |
+
model="gpt-3.5-turbo",
|
| 35 |
+
messages=messages
|
| 36 |
+
)
|
| 37 |
|
| 38 |
+
uav_response = response["choices"][0]["message"]["content"]
|
| 39 |
+
messages.append({"role": "assistant", "content": uav_response, "name": "Assistant"})
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
chat_transcript = ""
|
| 42 |
+
for message in messages:
|
| 43 |
+
if message['role'] != 'system':
|
| 44 |
+
chat_transcript += f"{message['name']}: {message['content']} \n\n"
|
| 45 |
|
| 46 |
+
return chat_transcript
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"An error occurred during building chat transcript: {e}")
|
| 49 |
+
return str(e)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
|
|
|
| 54 |
# Conversational UAV Explorer
|
| 55 |
Press record and speak into the microphone to give a command. Make sure to stop recording before pressing "Give Command."\n\n
|
| 56 |
Commands: Take picture, Go to, Land, Take off""")
|
| 57 |
+
with gr.Row():
|
| 58 |
audio_input = gr.Audio(source="microphone", type="filepath")
|
| 59 |
output = gr.Textbox(label="Transcript")
|
| 60 |
with gr.Row():
|
commands.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
|
| 2 |
-
|
|
|
|
| 1 |
|
| 2 |
+
TAKEPICTURE greenhouse
|
prompts.py
CHANGED
|
@@ -103,7 +103,7 @@ examples_few_shot = [
|
|
| 103 |
"command": "TAKEOFF"
|
| 104 |
},
|
| 105 |
{
|
| 106 |
-
"sentence": "Land
|
| 107 |
"command": "LAND"
|
| 108 |
},
|
| 109 |
{
|
|
|
|
| 103 |
"command": "TAKEOFF"
|
| 104 |
},
|
| 105 |
{
|
| 106 |
+
"sentence": "Land.",
|
| 107 |
"command": "LAND"
|
| 108 |
},
|
| 109 |
{
|
server/uav_api.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
from flask import Flask
|
| 2 |
-
from app import send_command
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
|
|
|
| 1 |
from flask import Flask
|
|
|
|
| 2 |
|
| 3 |
app = Flask(__name__)
|
| 4 |
|
test/test_multiplecommands.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import re
|
| 3 |
+
from fewshot import FewShot4UAVs
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.fixture
|
| 7 |
+
def fewshot():
|
| 8 |
+
return FewShot4UAVs()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# format: <command> \t<goal>
|
| 12 |
+
def parse_multiple_commands(text):
|
| 13 |
+
text = text.lstrip('\n')
|
| 14 |
+
lines = text.split("\n")
|
| 15 |
+
first_action = lines[0].split()[0].lower()
|
| 16 |
+
second_action = lines[1].split()[0].lower()
|
| 17 |
+
return first_action, second_action
|
| 18 |
+
|
| 19 |
+
def test_multiple_actions(fewshot):
|
| 20 |
+
text = "Take a photo and then take off."
|
| 21 |
+
output = fewshot.get_command(text)
|
| 22 |
+
command = parse_multiple_commands(output)
|
| 23 |
+
assert command == ('takephoto', 'takeoff')
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_two_go_to(fewshot):
|
| 27 |
+
text = "Go to the Kroger on Lombardy St and then go to Roots on W Grace St."
|
| 28 |
+
output = fewshot.get_command(text)
|
| 29 |
+
command = parse_multiple_commands(output)
|
| 30 |
+
assert command == ('goto', 'goto')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test_multiple_actions_and_locations(fewshot):
|
| 34 |
+
text = "Fly to the park and take a picture of the red house."
|
| 35 |
+
output = fewshot.get_command(text)
|
| 36 |
+
command = parse_multiple_commands(output)
|
| 37 |
+
assert command == ('goto', 'takephoto')
|
| 38 |
+
|
| 39 |
+
def test_action_and_location(fewshot):
|
| 40 |
+
text = "Fly to the park and take a picture."
|
| 41 |
+
output = fewshot.get_command(text)
|
| 42 |
+
command = parse_multiple_commands(output)
|
| 43 |
+
assert command == ('goto', 'takephoto')
|
| 44 |
+
|
| 45 |
+
def test_action_and_location_synonyms(fewshot):
|
| 46 |
+
text = "Hover and head to the closest park."
|
| 47 |
+
output = fewshot.get_command(text)
|
| 48 |
+
command = parse_multiple_commands(output)
|
| 49 |
+
assert command == ('takeoff', 'goto')
|
| 50 |
+
|
| 51 |
+
def test_action_synonyms(fewshot):
|
| 52 |
+
text = "Ascend and then take a photo."
|
| 53 |
+
output = fewshot.get_command(text)
|
| 54 |
+
command = parse_multiple_commands(output)
|
| 55 |
+
assert command == ('takeoff', 'takephoto')
|
| 56 |
+
|
| 57 |
+
def test_action_synonyms2(fewshot):
|
| 58 |
+
text = "Descend and then take a photo."
|
| 59 |
+
output = fewshot.get_command(text)
|
| 60 |
+
command = parse_multiple_commands(output)
|
| 61 |
+
assert command == ('land', 'takephoto')
|
test/test_singlecommands.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import re
|
| 3 |
+
from fewshot import FewShot4UAVs
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.fixture
|
| 7 |
+
def fewshot():
|
| 8 |
+
return FewShot4UAVs()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# format: <command> \t<goal>
|
| 12 |
+
def parse_command(text):
|
| 13 |
+
tokens = re.split(' \t|\n|: ', text.lower())
|
| 14 |
+
print(tokens)
|
| 15 |
+
if len(tokens) >= 2:
|
| 16 |
+
return tokens[1]
|
| 17 |
+
else:
|
| 18 |
+
return 'none'
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_red_house(fewshot):
|
| 22 |
+
text = "Go to the red house on W Broad St."
|
| 23 |
+
output = fewshot.get_command(text)
|
| 24 |
+
command = parse_command(output)
|
| 25 |
+
assert command == "goto"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_take_off(fewshot):
|
| 29 |
+
text = "Take off from where you are."
|
| 30 |
+
output = fewshot.get_command(text)
|
| 31 |
+
command = parse_command(output)
|
| 32 |
+
assert command == "takeoff"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_take_off_synonym(fewshot):
|
| 36 |
+
text = "Lift off."
|
| 37 |
+
output = fewshot.get_command(text)
|
| 38 |
+
command = parse_command(output)
|
| 39 |
+
assert command == "takeoff"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_land(fewshot):
|
| 43 |
+
text = "Land now."
|
| 44 |
+
output = fewshot.get_command(text)
|
| 45 |
+
command = parse_command(output)
|
| 46 |
+
assert command == "land"
|
| 47 |
+
|
| 48 |
+
def test_purple_house(fewshot):
|
| 49 |
+
text = "Travel to the purple house on the left side."
|
| 50 |
+
output = fewshot.get_command(text)
|
| 51 |
+
command = parse_command(output)
|
| 52 |
+
assert command == "goto"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def test_parking_garage(fewshot):
|
| 56 |
+
text = "Fly to the parking garage across the street."
|
| 57 |
+
output = fewshot.get_command(text)
|
| 58 |
+
command = parse_command(output)
|
| 59 |
+
assert command == "goto"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_gym(fewshot):
|
| 63 |
+
text = "Check out the Cary St Gym."
|
| 64 |
+
output = fewshot.get_command(text)
|
| 65 |
+
command = parse_command(output)
|
| 66 |
+
assert command == "goto"
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def test_cease_flight(fewshot):
|
| 70 |
+
text = "Cease flight."
|
| 71 |
+
output = fewshot.get_command(text)
|
| 72 |
+
command = parse_command(output)
|
| 73 |
+
assert command == "land"
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_stop_flight(fewshot):
|
| 77 |
+
text = "Stop the flight."
|
| 78 |
+
output = fewshot.get_command(text)
|
| 79 |
+
command = parse_command(output)
|
| 80 |
+
assert command == "land"
|
| 81 |
+
|
| 82 |
+
def test_location_no_action(fewshot):
|
| 83 |
+
text = "Willow Lawn."
|
| 84 |
+
output = fewshot.get_command(text)
|
| 85 |
+
command = parse_command(output)
|
| 86 |
+
assert command == "goto"
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def test_location_no_action2(fewshot):
|
| 90 |
+
text = "Whole Foods on W Broad St."
|
| 91 |
+
output = fewshot.get_command(text)
|
| 92 |
+
command = parse_command(output)
|
| 93 |
+
assert command == "goto"
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def test_location_no_action3(fewshot):
|
| 97 |
+
text = "Starbucks at N Robinson St."
|
| 98 |
+
output = fewshot.get_command(text)
|
| 99 |
+
command = parse_command(output)
|
| 100 |
+
assert command == "goto"
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_with_extra_words(fewshot):
|
| 104 |
+
text = "Please go to the Whole Foods on W Broad St."
|
| 105 |
+
output = fewshot.get_command(text)
|
| 106 |
+
command = parse_command(output)
|
| 107 |
+
assert command == "goto"
|
| 108 |
+
|
| 109 |
+
def test_with_extra_words2(fewshot):
|
| 110 |
+
text = "Go to the Whole Foods on W Broad St please."
|
| 111 |
+
output = fewshot.get_command(text)
|
| 112 |
+
command = parse_command(output)
|
| 113 |
+
assert command == "goto"
|
| 114 |
+
|
| 115 |
+
def test_action_synonyms3(fewshot):
|
| 116 |
+
text = "Descend"
|
| 117 |
+
output = fewshot.get_command(text)
|
| 118 |
+
command = parse_command(output)
|
| 119 |
+
assert command == 'land'
|
test/test_unviablecommands.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import re
|
| 3 |
+
from fewshot import FewShot4UAVs
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.fixture
|
| 7 |
+
def fewshot():
|
| 8 |
+
return FewShot4UAVs()
|
| 9 |
+
|
| 10 |
+
# format: <command> \t<goal>
|
| 11 |
+
def parse_command(text):
|
| 12 |
+
tokens = re.split(' \t|\n|: ', text.lower())
|
| 13 |
+
print(tokens)
|
| 14 |
+
if len(tokens) >= 2:
|
| 15 |
+
return tokens[1]
|
| 16 |
+
else:
|
| 17 |
+
return 'none'
|
| 18 |
+
|
| 19 |
+
def test_picture(fewshot):
|
| 20 |
+
text = "Take a picture."
|
| 21 |
+
output = fewshot.get_command(text)
|
| 22 |
+
command = parse_command(output)
|
| 23 |
+
assert command == "none"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_snap_pic(fewshot):
|
| 27 |
+
text = "Snap a photo."
|
| 28 |
+
output = fewshot.get_command(text)
|
| 29 |
+
command = parse_command(output)
|
| 30 |
+
assert command == "none"
|
| 31 |
+
|
| 32 |
+
def test_no_location1(fewshot):
|
| 33 |
+
text = "Check out."
|
| 34 |
+
output = fewshot.get_command(text)
|
| 35 |
+
command = parse_command(output)
|
| 36 |
+
assert command == "none"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_no_location2(fewshot):
|
| 40 |
+
text = "Go to."
|
| 41 |
+
output = fewshot.get_command(text)
|
| 42 |
+
command = parse_command(output)
|
| 43 |
+
assert command == "none"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_no_location3(fewshot):
|
| 47 |
+
text = "Travel to."
|
| 48 |
+
output = fewshot.get_command(text)
|
| 49 |
+
command = parse_command(output)
|
| 50 |
+
assert command == "none"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_no_location4(fewshot):
|
| 54 |
+
text = "Head to."
|
| 55 |
+
output = fewshot.get_command(text)
|
| 56 |
+
command = parse_command(output)
|
| 57 |
+
assert command == "none"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_empty_input(fewshot):
|
| 61 |
+
text = ""
|
| 62 |
+
output = fewshot.get_command(text)
|
| 63 |
+
command = parse_command(output)
|
| 64 |
+
assert command == "none"
|
| 65 |
+
|
| 66 |
+
def test_invalid_command(fewshot):
|
| 67 |
+
text = "Do something."
|
| 68 |
+
output = fewshot.get_command(text)
|
| 69 |
+
command = parse_command(output)
|
| 70 |
+
assert command == "none"
|
| 71 |
+
|