From 7a2abb311db8cc2c373eb606947b8ac8ebfa39df Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 9 Sep 2023 20:24:58 +0300 Subject: [PATCH] grammars : add assistant + update comments --- examples/command/command.cpp | 4 +-- grammars/assistant.gbnf | 57 ++++++++++++++++++++++++++++++++++++ grammars/chess.gbnf | 4 --- grammars/colors.gbnf | 4 --- 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 grammars/assistant.gbnf diff --git a/examples/command/command.cpp b/examples/command/command.cpp index dfffbda7..ef5b09be 100644 --- a/examples/command/command.cpp +++ b/examples/command/command.cpp @@ -137,6 +137,7 @@ std::string transcribe( t_ms = 0; whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY); + //whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_BEAM_SEARCH); wparams.print_progress = false; wparams.print_special = params.print_special; @@ -149,9 +150,6 @@ std::string transcribe( wparams.language = params.language.c_str(); wparams.n_threads = params.n_threads; - // disable fallback - seems not useful for command recognition - wparams.temperature_inc = 0.00f; - wparams.audio_ctx = params.audio_ctx; wparams.speed_up = params.speed_up; diff --git a/grammars/assistant.gbnf b/grammars/assistant.gbnf new file mode 100644 index 00000000..c7432672 --- /dev/null +++ b/grammars/assistant.gbnf @@ -0,0 +1,57 @@ +# - "turn on lights." +# - "set thermostat to 22." +# - "increase TV by 10." +# - "decrease oven by 50." +# - "play music." +# - "stop podcast." +# - "schedule cleaning at 3pm." +# - "cancel cleaning." +# - "remind me to buy milk at 5pm." +# - "show me security system." +# - "hide washing machine." +# - "what is the lights status?" +# - "what is the current thermostat value?" +# - "what is the security system status?" +# - "what is the door lock status?" +# - "what is the camera battery level?" +# - "what is the weather like today?" +# - "what is the forecast for tomorrow?" +# - "what is the time?" +# - "what is my schedule for today?" +# - "what tasks do I have?" +# - "what reminders do I have?" +# +# example: +# +# ./command -m ./models/ggml-base.en.bin -t 8 --grammar ./grammars/chess.gbnf --prompt "Ok Whisper, start listening for commands" +# + +root ::= init " " (command | question) "." +prompt ::= init "." + +# leading space is very important! +init ::= " Ok Whisper, start listening for commands" + +command ::= "Turn " ("on" | "off") " " device | "Set " device " to " value | + "Increase " device " by " value | "Decrease " device " by " value | + "Play " media | "Stop " media | "Schedule " task " at " time | "Cancel " task | + "Remind me to " task " at " time | "Show me " device | "Hide " device + +question ::= "What is the " device " status?" | "What is the current " device " value?" | + "What is the " device " temperature?" | "What is the " device " humidity?" | + "What is the " device " power consumption?" | "What is the " device " battery level?" | + "What is the weather like today?" | "What is the forecast for tomorrow?" | + "What is the time?" | "What is my schedule for today?" | "What tasks do I have?" | + "What reminders do I have?" + +device ::= "lights" | "thermostat" | "security system" | "door lock" | "camera" | "speaker" | "TV" | + "music player" | "coffee machine" | "oven" | "refrigerator" | "washing machine" | + "vacuum cleaner" + +value ::= [0-9]+ + +media ::= "music" | "radio" | "podcast" | "audiobook" | "TV show" | "movie" + +task ::= [a-zA-Z]+ (" " [a-zA-Z]+)? + +time ::= [0-9] [0-9]? ":" [0-9] [0-9] ("am" | "pm")? diff --git a/grammars/chess.gbnf b/grammars/chess.gbnf index 122ce123..9a3ca1d5 100644 --- a/grammars/chess.gbnf +++ b/grammars/chess.gbnf @@ -5,10 +5,6 @@ # - c3 queen to d4 king b1 # - pawn to a1 bishop to b2 knight to c3 # -# initial prompt: -# -# "pawn to a1, bishop to b2, knight to c3, rook to d4, queen to e5, king to f6," -# # example: # # ./command -m ./models/ggml-base.en.bin -t 8 --grammar ./grammars/chess.gbnf --prompt "pawn knight king a1 f5 h6" diff --git a/grammars/colors.gbnf b/grammars/colors.gbnf index f4a4930c..039c83d9 100644 --- a/grammars/colors.gbnf +++ b/grammars/colors.gbnf @@ -6,10 +6,6 @@ # - green red # - green blue green # -# initial prompt: -# -# "red green blue" -# # example: # # ./command -m ./models/ggml-base.en.bin -t 8 --grammar ./grammars/colors.gbnf --prompt "red green blue"