Skip to content

Commit

Permalink
Disable LLM commands by default, can be enabled in web interface. Cle…
Browse files Browse the repository at this point in the history
…an up knowledgegraph settings interface a bit
  • Loading branch information
kercre123 committed Apr 13, 2024
1 parent 5e41488 commit 91c8a30
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 109 deletions.
19 changes: 10 additions & 9 deletions chipper/pkg/vars/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
12 changes: 10 additions & 2 deletions chipper/pkg/wirepod/config-ws/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")) != "" {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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":
Expand Down
59 changes: 28 additions & 31 deletions chipper/pkg/wirepod/ttr/kgsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -349,7 +347,6 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
)
//time.Sleep(time.Millisecond * 3300)
stop <- true
//}
}
return "", nil
}
Expand Down
13 changes: 8 additions & 5 deletions chipper/pkg/wirepod/ttr/kgsim_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
32 changes: 14 additions & 18 deletions chipper/webroot/initial.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,38 @@ <h3>Knowledge Graph Setup</h3>
<label for="togetherKey">Together Key:</label>
<input type="text" name="togetherKey" id="togetherKey"><br>
<label for="togetherAIPrompt">GPT Prompt (leave blank for default):</label><br>
<small><label for="togetherAIPrompt">(default: "You are a helpful, animated robot called " + robName + ". Keep the response concise yet informative.")</label></small>
<small><label for="togetherAIPrompt">(default: "You are a helpful, animated robot called Vector. Keep the response concise yet informative.")</label></small>
<input type="text" name="togetherAIPrompt" id="togetherAIPrompt"><br>
<small>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.</small><br>
<p>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.</p>
<label for="togetherintentyes">Yes</label>
<input type="radio" id="togetherintentyes" name="togetherintentgselect" value="yes" onclick="checkKG()"><br>
<input type="radio" id="togetherintentyes" name="togetherintentgselect" value="yes" onclick="checkKG()">
<label for="intentno">No</label>
<input type="radio" id="togetherintentno" name="togetherintentgselect" value="no" onclick="checkKG()">
<span id="togetherAIRobotNameInput" style="display:none">
<br>
<label for="togetherAIRobotName">Robot name:</label>
<input type="text" name="togetherAIRobotName" id="togetherAIRobotName" placeholder="Anki Vector">
</span>

</span>
<span id="openAIInput" style="display:none">
<br>
<label for="openAIKey">OpenAI Key:</label>
<input type="text" name="openAIKey" id="openAIKey"><br>
<label for="openAIKey">GPT Prompt (leave blank for default):</label><br>
<small><label for="openAIKey">(default: "You are a helpful, animated robot called " + robName + ". Keep the response concise yet informative.")</label></small>
<small><label for="openAIKey">(default: "You are a helpful, animated robot called Vector. Keep the response concise yet informative.")</label></small>
<input type="text" name="openAIPrompt" id="openAIPrompt"><br>
<small>Would you like to enable the intent graph feature? This forwards the request to OpenAI if the regular intent processor didn't understand what you said.</small><br>
<p>Would you like to enable the intent graph feature? This forwards the request to OpenAI if the regular intent processor didn't understand what you said.</p>
<label for="intentyes">Yes</label>
<input type="radio" id="intentyes" name="intentgselect" value="yes" onclick="checkKG()"><br>
<input type="radio" id="intentyes" name="intentgselect" value="yes" onclick="checkKG()">
<label for="intentno">No</label>
<input type="radio" id="intentno" name="intentgselect" value="no" onclick="checkKG()">
<span id="openAIRobotNameInput" style="display:none">
<br>
<label for="openAIRobotName">Robot name:</label>
<input type="text" name="openAIRobotName" id="openAIRobotName" placeholder="Anki Vector">
</span>
<p>Enable LLM commands (allows the LLM to run commands on the robot)? (BETA)</p>
<label for="commandYes">Yes</label>
<input type="radio" id="commandYes" name="commandDoselect" value="yes">
<label for="commandNo">No</label>
<input type="radio" id="commandNo" name="commandDoselect" value="no">
</span>

<span id="saveChatInput" style="display:none">
<small>Would you like chats to be saved and used in the context of future responses?</small><br>
<p>Would you like chats to be saved and used in the context of future responses?</p>
<label for="saveChatYes">Yes</label>
<input type="radio" id="saveChatYes" name="saveChatselect" value="yes"><br>
<input type="radio" id="saveChatYes" name="saveChatselect" value="yes">
<label for="saveChatNo">No</label>
<input type="radio" id="saveChatNo" name="saveChatselect" value="no">
</span>
Expand Down
10 changes: 7 additions & 3 deletions chipper/webroot/js/initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ function initKGAPIKey() {
var robotName = ""
var model = ""
var saveChat = ""
var doCommands = ""

if (provider == "openai") {
key = document.getElementById("openAIKey").value
openAIPrompt = document.getElementById("openAIPrompt").value
if (document.getElementById("commandYes").checked == true) {
doCommands = "true"
} else {
doCommands = "false"
}
if (document.getElementById("intentyes").checked == true) {
intentgraph = "true"
robotName = document.getElementById("openAIRobotName").value
} else {
intentgraph = "false"
}
Expand All @@ -117,7 +122,6 @@ function initKGAPIKey() {
model = document.getElementById("togetherModel").value
if (document.getElementById("togetherintentyes").checked == true) {
intentgraph = "true"
robotName = document.getElementById("togetherAIRobotName").value
} else {
intentgraph = "false"
}
Expand All @@ -136,7 +140,7 @@ function initKGAPIKey() {
intentgraph = "false"
}

var data = "provider=" + provider + "&api_key=" + key + "&api_id=" + id + "&model=" + model + "&intent_graph=" + intentgraph + "&robot_name=" + robotName + "&openai_prompt=" + openAIPrompt + "&save_chat=" + saveChat
var data = "provider=" + provider + "&api_key=" + key + "&api_id=" + id + "&model=" + model + "&intent_graph=" + intentgraph + "&robot_name=" + robotName + "&openai_prompt=" + openAIPrompt + "&save_chat=" + saveChat + "&commands_enable=" + doCommands
fetch("/api/set_kg_api?" + data)
.then(response => response.text())
.then((response) => {
Expand Down
Loading

0 comments on commit 91c8a30

Please sign in to comment.