Skip to content

Commit

Permalink
Little webroot enhancements, it now trims space around API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kercre123 committed Apr 7, 2024
1 parent ce39281 commit bfde3e3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion chipper/intent-data/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
},
{
"name": "intent_greeting_hello",
"keyphrases" : ["hello", "our you", "high", "below", "little", "follow", "for you", "far you", "how about you", "how are you", "the low", "the loo" ]
"keyphrases" : ["hello", "our you", "high", "below", "little", "follow", "for you", "far you", "how about you", "how are you", "the low", "the loo", "our are you" ]
},
{
"name": "intent_imperative_come",
Expand Down
10 changes: 5 additions & 5 deletions chipper/pkg/wirepod/config-ws/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
vars.APIConfig.Weather.Enable = false
} else {
vars.APIConfig.Weather.Enable = true
vars.APIConfig.Weather.Key = weatherAPIKey
vars.APIConfig.Weather.Key = strings.TrimSpace(weatherAPIKey)
vars.APIConfig.Weather.Provider = weatherProvider
}
vars.WriteConfigToDisk()
Expand Down Expand Up @@ -192,9 +192,9 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
} else {
vars.APIConfig.Knowledge.Enable = true
vars.APIConfig.Knowledge.Provider = kgProvider
vars.APIConfig.Knowledge.Key = kgAPIKey
vars.APIConfig.Knowledge.Model = kgModel
vars.APIConfig.Knowledge.ID = kgAPIID
vars.APIConfig.Knowledge.Key = strings.TrimSpace(kgAPIKey)
vars.APIConfig.Knowledge.Model = strings.TrimSpace(kgModel)
vars.APIConfig.Knowledge.ID = strings.TrimSpace(kgAPIID)
}
if kgModel == "" && kgProvider == "together" {
logger.Println("Together model wasn't provided, using default meta-llama/Llama-2-70b-chat-hf")
Expand All @@ -217,7 +217,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
if r.FormValue("robot_name") == "" {
vars.APIConfig.Knowledge.RobotName = "Vector"
} else {
vars.APIConfig.Knowledge.RobotName = r.FormValue("robot_name")
vars.APIConfig.Knowledge.RobotName = strings.TrimSpace(r.FormValue("robot_name"))
}
} else if (kgProvider == "openai" || kgProvider == "together") && kgIntent == "false" {
vars.APIConfig.Knowledge.IntentGraph = false
Expand Down
3 changes: 3 additions & 0 deletions chipper/pkg/wirepod/preqs/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (s *Server) ProcessIntent(req *vtt.IntentRequest) (*vtt.IntentResponse, err
_, err := ttr.StreamingKGSim(req, req.Device, transcribedText)
if err != nil {
logger.Println("LLM error: " + err.Error())
logger.LogUI("LLM error: " + err.Error())
ttr.IntentPass(req, "intent_system_unmatched", transcribedText, map[string]string{"": ""}, false)
ttr.KGSim(req.Device, "There was an error getting a response from the L L M. Check the logs in the web interface.")
}
logger.Println("Bot " + speechReq.Device + " request served.")
return nil, nil
Expand Down
3 changes: 3 additions & 0 deletions chipper/pkg/wirepod/preqs/intent_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (s *Server) ProcessIntentGraph(req *vtt.IntentGraphRequest) (*vtt.IntentGra
_, err := ttr.StreamingKGSim(req, req.Device, transcribedText)
if err != nil {
logger.Println("LLM error: " + err.Error())
logger.LogUI("LLM error: " + err.Error())
ttr.IntentPass(req, "intent_system_unmatched", transcribedText, map[string]string{"": ""}, false)
ttr.KGSim(req.Device, "There was an error getting a response from the L L M. Check the logs in the web interface.")
}
logger.Println("Bot " + speechReq.Device + " request served.")
return nil, nil
Expand Down
6 changes: 6 additions & 0 deletions chipper/pkg/wirepod/ttr/kgsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
var isDone bool
var c *openai.Client
if vars.APIConfig.Knowledge.Provider == "together" {
if vars.APIConfig.Knowledge.Model == "" {
vars.APIConfig.Knowledge.Model = "meta-llama/Llama-2-70b-chat-hf"
vars.WriteConfigToDisk()
}
conf := openai.DefaultConfig(vars.APIConfig.Knowledge.Key)
conf.BaseURL = "https://api.together.xyz/v1"
c = openai.NewClientWithConfig(conf)
Expand Down Expand Up @@ -128,8 +132,10 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
if err != nil {
if strings.Contains(err.Error(), "does not exist") && vars.APIConfig.Knowledge.Provider == "openai" {
logger.Println("GPT-4 model cannot be accessed with this API key. You likely need to add more than $5 dollars of funds to your OpenAI account.")
logger.LogUI("GPT-4 model cannot be accessed with this API key. You likely need to add more than $5 dollars of funds to your OpenAI account.")
aireq.Model = openai.GPT3Dot5Turbo
logger.Println("Falling back to " + aireq.Model)
logger.LogUI("Falling back to " + aireq.Model)
stream, err = c.CreateChatCompletionStream(ctx, aireq)
if err != nil {
logger.Println("OpenAI still not returning a response even after falling back. Erroring.")
Expand Down
6 changes: 5 additions & 1 deletion chipper/webroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ <h3>Authenticate an OSKR/dev-unlocked robot</h3>

<div id="section-log" style="display: none;">
<h2>Log</h2>
<textarea id="botTranscriptedTextArea" rows="4" cols="50">
<label for="logdebug">Show all logs</label>
<input id="logdebug" name="logdebug" type="checkbox"><br>
<label for="logscrollbottom">Scroll to bottom</label>
<input id="logscrollbottom" name="logscrollbottom" type="checkbox">
<textarea id="botTranscriptedTextArea" rows="7" cols="50">
loading log...
</textarea>
<hr>
Expand Down
2 changes: 1 addition & 1 deletion chipper/webroot/initial.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h3>Knowledge Graph Setup</h3>
<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 robot called Vector. You will be given a question asked by a user and you must provide the best answer you can. It may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.)</label></small>
<small><label for="openAIKey">(default: "You are a helpful robot called Vector. The prompt may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer 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>
<label for="intentyes">Yes</label>
Expand Down
16 changes: 13 additions & 3 deletions chipper/webroot/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,19 @@ function showLog() {

GetLog = true
logDivArea = document.getElementById("botTranscriptedTextArea")
document.getElementById("logscrollbottom").checked = true
logP = document.createElement("p")
interval = setInterval(function() {
if (GetLog == false) {
clearInterval(interval)
return
}
let xhr = new XMLHttpRequest();
xhr.open("GET", "/api/get_logs");
if (document.getElementById("logdebug").checked) {
xhr.open("GET", "/api/get_debug_logs");
} else {
xhr.open("GET", "/api/get_logs");
}
xhr.send();
xhr.onload = function() {
logDivArea.innerHTML = ""
Expand All @@ -438,9 +443,14 @@ function showLog() {
} else {
logP.innerHTML = xhr.response
}
logDivArea.value = logP.innerHTML;
if (document.getElementById("logscrollbottom").checked) {
logDivArea.value = logP.innerHTML;
logDivArea.scrollTop = logDivArea.scrollHeight;
} else {
logDivArea.value = logP.innerHTML;
}
}
}, 1000)
}, 500)
}

function showLanguage() {
Expand Down
2 changes: 1 addition & 1 deletion chipper/webroot/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <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 robot called Vector. You will be given a question asked by a user and you must provide the best answer you can. It may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.)</label></small>
<small><label for="togetherAIPrompt">(default: "You are a helpful robot called Vector. The prompt may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer 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>
<label for="togetherintentyes">Yes</label>
Expand Down

0 comments on commit bfde3e3

Please sign in to comment.