diff --git a/chipper/pkg/vars/config.go b/chipper/pkg/vars/config.go index 8844f848..a283f152 100644 --- a/chipper/pkg/vars/config.go +++ b/chipper/pkg/vars/config.go @@ -21,15 +21,16 @@ type apiConfig struct { Unit string `json:"unit"` } `json:"weather"` Knowledge struct { - Enable bool `json:"enable"` - Provider string `json:"provider"` - Key string `json:"key"` - ID string `json:"id"` - Model string `json:"model"` - IntentGraph bool `json:"intentgraph"` - RobotName string `json:"robotName"` - OpenAIPrompt string `json:"openai_prompt"` - SaveChat bool `json:"save_chat"` + Enable bool `json:"enable"` + Provider string `json:"provider"` + Key string `json:"key"` + ID string `json:"id"` + Model string `json:"model"` + IntentGraph bool `json:"intentgraph"` + RobotName string `json:"robotName"` + OpenAIPrompt string `json:"openai_prompt"` + SaveChat bool `json:"save_chat"` + CommandsEnable bool `json:"commands_enable"` } `json:"knowledge"` STT struct { Service string `json:"provider"` diff --git a/chipper/pkg/wirepod/config-ws/webserver.go b/chipper/pkg/wirepod/config-ws/webserver.go index 22c4156d..9ca4f944 100755 --- a/chipper/pkg/wirepod/config-ws/webserver.go +++ b/chipper/pkg/wirepod/config-ws/webserver.go @@ -198,7 +198,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { } if kgModel == "" && kgProvider == "together" { logger.Println("Together model wasn't provided, using default meta-llama/Llama-2-70b-chat-hf") - kgModel = "meta-llama/Llama-2-70b-chat-hf" + vars.APIConfig.Knowledge.Model = "meta-llama/Llama-2-70b-chat-hf" } if kgProvider == "openai" || kgProvider == "together" { if strings.TrimSpace(r.FormValue("openai_prompt")) != "" { @@ -211,6 +211,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { } else { vars.APIConfig.Knowledge.SaveChat = false } + if r.FormValue("commands_enable") == "true" { + vars.APIConfig.Knowledge.CommandsEnable = true + } else { + vars.APIConfig.Knowledge.CommandsEnable = false + } } if (kgProvider == "openai" || kgProvider == "together") && kgIntent == "true" { vars.APIConfig.Knowledge.IntentGraph = true @@ -236,6 +241,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { kgRobotName := "" kgOpenAIPrompt := "" kgSavePrompt := false + kgCommandsEnable := false if vars.APIConfig.Knowledge.Enable { kgEnabled = true kgProvider = vars.APIConfig.Knowledge.Provider @@ -246,6 +252,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { kgRobotName = vars.APIConfig.Knowledge.RobotName kgOpenAIPrompt = vars.APIConfig.Knowledge.OpenAIPrompt kgSavePrompt = vars.APIConfig.Knowledge.SaveChat + kgCommandsEnable = vars.APIConfig.Knowledge.CommandsEnable } fmt.Fprintf(w, "{ ") fmt.Fprintf(w, " \"kgEnabled\": %t,", kgEnabled) @@ -256,7 +263,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, " \"kgIntentGraph\": \"%t\",", kgIntent) fmt.Fprintf(w, " \"kgRobotName\": \"%s\",", kgRobotName) fmt.Fprintf(w, " \"kgOpenAIPrompt\": \"%s\",", kgOpenAIPrompt) - fmt.Fprintf(w, " \"kgSaveChat\": \"%t\"", kgSavePrompt) + fmt.Fprintf(w, " \"kgSaveChat\": \"%t\",", kgSavePrompt) + fmt.Fprintf(w, " \"kgCommandsEnable\": \"%t\"", kgCommandsEnable) fmt.Fprintf(w, "}") return case r.URL.Path == "/api/set_stt_info": diff --git a/chipper/pkg/wirepod/ttr/kgsim.go b/chipper/pkg/wirepod/ttr/kgsim.go index 5da71c51..d3a760be 100644 --- a/chipper/pkg/wirepod/ttr/kgsim.go +++ b/chipper/pkg/wirepod/ttr/kgsim.go @@ -86,13 +86,7 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string ctx := context.Background() speakReady := make(chan string) - var robName string - if vars.APIConfig.Knowledge.RobotName != "" { - robName = vars.APIConfig.Knowledge.RobotName - } else { - robName = "Vector" - } - defaultPrompt := "You are a helpful, animated robot called " + robName + ". Keep the response concise yet informative." + defaultPrompt := "You are a helpful, animated robot called Vector. Keep the response concise yet informative." var nChat []openai.ChatCompletionMessage @@ -107,8 +101,6 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string smsg.Content = CreatePrompt(smsg.Content) - logger.Println("Full prompt: " + smsg.Content) - nChat = append(nChat, smsg) if vars.APIConfig.Knowledge.SaveChat { rchat := GetChat(esn) @@ -286,8 +278,8 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string // * end - modified from official vector-go-sdk }() - //var stopTTSLoop bool - //TTSLoopStopped := make(chan bool) + var stopTTSLoop bool + TTSLoopStopped := make(chan bool) for range start { time.Sleep(time.Millisecond * 300) robot.Conn.PlayAnimation( @@ -299,23 +291,25 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string Loops: 1, }, ) - // go func() { - // for { - // if stopTTSLoop { - // TTSLoopStopped <- true - // break - // } - // robot.Conn.PlayAnimation( - // ctx, - // &vectorpb.PlayAnimationRequest{ - // Animation: &vectorpb.Animation{ - // Name: "anim_tts_loop_02", - // }, - // Loops: 1, - // }, - // ) - // } - // }() + if !vars.APIConfig.Knowledge.CommandsEnable { + go func() { + for { + if stopTTSLoop { + TTSLoopStopped <- true + break + } + robot.Conn.PlayAnimation( + ctx, + &vectorpb.PlayAnimationRequest{ + Animation: &vectorpb.Animation{ + Name: "anim_tts_loop_02", + }, + Loops: 1, + }, + ) + } + }() + } numInResp := 0 for { respSlice := fullRespSlice @@ -335,8 +329,12 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string PerformActions(acts, robot) numInResp = numInResp + 1 } - //stopTTSLoop = true - // for range TTSLoopStopped { + if !vars.APIConfig.Knowledge.CommandsEnable { + stopTTSLoop = true + for range TTSLoopStopped { + break + } + } time.Sleep(time.Millisecond * 100) robot.Conn.PlayAnimation( ctx, @@ -349,7 +347,6 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string ) //time.Sleep(time.Millisecond * 3300) stop <- true - //} } return "", nil } diff --git a/chipper/pkg/wirepod/ttr/kgsim_cmds.go b/chipper/pkg/wirepod/ttr/kgsim_cmds.go index c3e7d6d6..5ee84d76 100644 --- a/chipper/pkg/wirepod/ttr/kgsim_cmds.go +++ b/chipper/pkg/wirepod/ttr/kgsim_cmds.go @@ -7,6 +7,7 @@ import ( "github.com/fforchino/vector-go-sdk/pkg/vector" "github.com/fforchino/vector-go-sdk/pkg/vectorpb" "github.com/kercre123/wire-pod/chipper/pkg/logger" + "github.com/kercre123/wire-pod/chipper/pkg/vars" ) const ( @@ -109,11 +110,13 @@ var ValidLLMCommands []LLMCommand = []LLMCommand{ } func CreatePrompt(origPrompt string) string { - prompt := origPrompt + "\n\n" + "IMPORTANT INSTRUCTIONS YOU MUST FOLLOW: The user input might not be spelt/puntuated correctly as it is coming from speech-to-text software. Do not include special characters in your answer. This includes the following characters (not including the quotes): '& ^ * # @ -'. If you want to use a hyphen, Use it like this: 'something something -- something -- something something'. DO NOT USE EMOJIS! Use the playAnimaion or playAnimationWI commands if you want to express emotion! IF YOU DO NOT ABIDE BY THESE RULES, I WILL CANCEL YOUR RESPONSE AND WILL MAKE YOU START OVER. Also, don't start your answer with 'Well, well, well', it's getting old. You are very animated and good at following instructions. Animation takes precendence over words. You are to include many animations in your response. When you are told NOT to do something, you don't do it (it's so simple)." - prompt = prompt + "\n\n" + "ALSO IMPORTANT: You are running ON an Anki Vector robot. You have a set of commands. YOU ARE TO USE THESE. DO NOT BE AFRAID TO LITTER YOUR RESPONSE WITH THEM. Your response MUST include THREE OF THESE COMMANDS OR MORE. You are going to litter your response with them. If you include just one, I will make you start over. If you include an emoji, I will make you start over. If you want to use a command but it doesn't exist or your desired parameter isn't in the list, avoid using the command. The format is {{command||parameter}}. You can embed these in sentences. Example: \"User: How are you feeling? | Response: \"{{playAnimationWI||sad}} I'm feeling sad...\"\n\nHere is every valid command:" - for _, cmd := range ValidLLMCommands { - promptAppendage := "\n\nCommand Name: " + cmd.Command + "\nDescription: " + cmd.Description + "\nParameter choices: " + cmd.ParamChoices - prompt = prompt + promptAppendage + prompt := origPrompt + "\n\n" + "The user input might not be spelt/puntuated correctly as it is coming from speech-to-text software. Do not include special characters in your answer. This includes the following characters (not including the quotes): '& ^ * # @ -'. If you want to use a hyphen, Use it like this: 'something something -- something -- something something'." + if vars.APIConfig.Knowledge.CommandsEnable { + prompt = prompt + "\n\n" + "You are running ON an Anki Vector robot. You have a set of commands. YOU ARE TO USE THESE. DO NOT BE AFRAID TO LITTER YOUR RESPONSE WITH THEM. Your response MUST include THREE OF THESE COMMANDS OR MORE. You are going to litter your response with them. If you include just one, I will make you start over. If you include an emoji, I will make you start over. If you want to use a command but it doesn't exist or your desired parameter isn't in the list, avoid using the command. The format is {{command||parameter}}. You can embed these in sentences. Example: \"User: How are you feeling? | Response: \"{{playAnimationWI||sad}} I'm feeling sad...\"\n\nDO NOT USE EMOJIS! Use the playAnimation or playAnimationWI commands if you want to express emotion! IF YOU DO NOT ABIDE BY THESE RULES, I WILL CANCEL YOUR RESPONSE AND WILL MAKE YOU START OVER. You are very animated and good at following instructions. Animation takes precendence over words. You are to include many animations in your response.\n\nHere is every valid command:" + for _, cmd := range ValidLLMCommands { + promptAppendage := "\n\nCommand Name: " + cmd.Command + "\nDescription: " + cmd.Description + "\nParameter choices: " + cmd.ParamChoices + prompt = prompt + promptAppendage + } } return prompt } diff --git a/chipper/webroot/initial.html b/chipper/webroot/initial.html index e7d0f026..4f8643b0 100644 --- a/chipper/webroot/initial.html +++ b/chipper/webroot/initial.html @@ -106,42 +106,38 @@
Would you like to enable the intent graph feature? This forwards the request to Together if the regular intent processor didn't understand what you said.
-Would you like to enable the intent graph feature? This forwards the request to Together if the regular intent processor didn't understand what you said.
-