-
Notifications
You must be signed in to change notification settings - Fork 0
/
textToCode.py
24 lines (20 loc) · 979 Bytes
/
textToCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import openai
import ast
openai.api_key = os.getenv("OPENAI_API_KEY")
def transcribe(command):
response = openai.Completion.create(
model="text-davinci-003",
prompt="Return correct action. Prompt:\"%s\"\nActions are contained in this list: [\"SPOTIFY_ARTIST\", \"SPOTIFY_ALBUM\", \"SPOTIFY_SONG\", \"SPOTIFY_PLAYLIST\", \"SPOTIFY_START_PLAYBACK\", \"SPOTIFY_PAUSE_PLAYBACK\", \"SPOTIFY_NEXT\", \"SPOTIFY_PREVIOUS\", \"NETFLIX_MOVIE\", \"NETFLIX_TV\", \"BEDROOM_LIGHTS_ON\", \"BEDROOM_LIGHTS_OFF\", \"WEATHER_WIDGET\"]\nReturn a tuple in this format: \n(action, [optional_arguments,...]) \n in python code." % command,
temperature=0,
max_tokens=200,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
result = response["choices"][0]["text"]
try:
transcription = ast.literal_eval(result)
return transcription
except:
return "There was an error transcribing to code."