Spaces:
Runtime error
Runtime error
Using prompt engineering instead of fine tuning
Browse files
app.py
CHANGED
|
@@ -31,14 +31,40 @@ I Fine-Tuned the OpenAi **ada** model on Car Seats Command.
|
|
| 31 |
"""
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def get_command(command, model, id2label):
|
| 35 |
"""
|
| 36 |
This function get the classification outputs from openai API
|
| 37 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
completion = openai.Completion.create(
|
| 39 |
-
model=
|
| 40 |
)
|
| 41 |
id = int(completion["choices"][0]["text"].strip())
|
|
|
|
| 42 |
result = id2label[id] if id in id2label else "unknown"
|
| 43 |
return result
|
| 44 |
|
|
|
|
| 31 |
"""
|
| 32 |
|
| 33 |
|
| 34 |
+
# def get_command(command, model, id2label):
|
| 35 |
+
# """
|
| 36 |
+
# This function get the classification outputs from openai API
|
| 37 |
+
# """
|
| 38 |
+
# completion = openai.Completion.create(
|
| 39 |
+
# model=model, prompt=f"{command}->", max_tokens=1, temperature=0
|
| 40 |
+
# )
|
| 41 |
+
# id = int(completion["choices"][0]["text"].strip())
|
| 42 |
+
# result = id2label[id] if id in id2label else "unknown"
|
| 43 |
+
# return result
|
| 44 |
+
|
| 45 |
+
|
| 46 |
def get_command(command, model, id2label):
|
| 47 |
"""
|
| 48 |
This function get the classification outputs from openai API
|
| 49 |
"""
|
| 50 |
+
prompt = f"""
|
| 51 |
+
We want to control the seats of a car which has features to cool, heat, or massage a seat. The user said "{command}", Which feature we should use to ensure user comfort? Give just the number of the feature.
|
| 52 |
+
Mapping:
|
| 53 |
+
1: "massage_seats_on"
|
| 54 |
+
2: "massage_seats_off"
|
| 55 |
+
3: "heated_seats_on"
|
| 56 |
+
4: "heated_seats_off"
|
| 57 |
+
5: "cooled_seats_on"
|
| 58 |
+
6: "cooled_seats_off"
|
| 59 |
+
|
| 60 |
+
Command_Code:
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
completion = openai.Completion.create(
|
| 64 |
+
model="text-davinci-003", prompt=prompt, max_tokens=2, temperature=0
|
| 65 |
)
|
| 66 |
id = int(completion["choices"][0]["text"].strip())
|
| 67 |
+
|
| 68 |
result = id2label[id] if id in id2label else "unknown"
|
| 69 |
return result
|
| 70 |
|