Skip to content

Commit 37bb094

Browse files
committed
Allow modification of OpenAI prompt, make OSKR/dev-unlocked robot setup more reliable
1 parent 27c2430 commit 37bb094

File tree

13 files changed

+72
-166
lines changed

13 files changed

+72
-166
lines changed

chipper/go.mod

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,26 @@ require (
3030
)
3131

3232
require (
33-
github.com/PerformLine/go-stockutil v1.9.3 // indirect
3433
github.com/agnivade/levenshtein v1.1.1 // indirect
3534
github.com/akavel/rsrc v0.10.2 // indirect
3635
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
3736
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
38-
github.com/alphacep/vosk-api/go v0.3.46 // indirect
39-
github.com/bregydoc/gtranslate v0.0.0-20200913051839-1bd07f6c1fc5 // indirect
4037
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
41-
github.com/davecgh/go-spew v1.1.1 // indirect
4238
github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect
43-
github.com/fatih/structs v1.1.0 // indirect
44-
github.com/fogleman/gg v1.3.0 // indirect
4539
github.com/fsnotify/fsnotify v1.4.9 // indirect
4640
github.com/go-audio/riff v1.0.0 // indirect
47-
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
4841
github.com/golang/protobuf v1.5.3 // indirect
4942
github.com/grd/ogg v0.0.0-20130623210630-0dae53159b70 // indirect
5043
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 // indirect
5144
github.com/grpc-ecosystem/grpc-gateway/v2 v2.3.0 // indirect
52-
github.com/hajimehoshi/go-mp3 v0.3.3 // indirect
53-
github.com/hajimehoshi/oto/v2 v2.2.0 // indirect
54-
github.com/hashicorp/errwrap v1.0.0 // indirect
55-
github.com/hashicorp/go-multierror v1.1.1 // indirect
5645
github.com/hashicorp/hcl v1.0.0 // indirect
57-
github.com/hegedustibor/htgo-tts v0.0.0-20220821045517-04f3cda7a12f // indirect
58-
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6 // indirect
59-
github.com/jdkato/prose v1.2.1 // indirect
6046
github.com/josephspurrier/goversioninfo v1.4.0 // indirect
61-
github.com/kercre123/vosk-api v1.0.1 // indirect
47+
github.com/kr/text v0.2.0 // indirect
6248
github.com/magiconair/properties v1.8.1 // indirect
6349
github.com/miekg/dns v1.1.41 // indirect
6450
github.com/mitchellh/mapstructure v1.4.3 // indirect
65-
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
6651
github.com/pelletier/go-toml v1.8.0 // indirect
6752
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
68-
github.com/robertkrimen/otto v0.0.0-20221127200954-e92282a6bb0d // indirect
6953
github.com/sirupsen/logrus v1.7.0 // indirect
7054
github.com/spf13/afero v1.2.2 // indirect
7155
github.com/spf13/cast v1.3.1 // indirect
@@ -83,9 +67,5 @@ require (
8367
google.golang.org/protobuf v1.31.0 // indirect
8468
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
8569
gopkg.in/hraban/opus.v2 v2.0.0-20201025103112-d779bb1cc5a2 // indirect
86-
gopkg.in/neurosnap/sentences.v1 v1.0.6 // indirect
87-
gopkg.in/sourcemap.v1 v1.0.5 // indirect
8870
gopkg.in/yaml.v2 v2.4.0 // indirect
89-
k8s.io/apimachinery v0.23.4 // indirect
90-
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
9171
)

chipper/go.sum

Lines changed: 0 additions & 121 deletions
Large diffs are not rendered by default.

chipper/pkg/mdnshandler/mdns.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mdnshandler
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -58,6 +59,10 @@ func PostmDNSNow() {
5859
}
5960

6061
func PostmDNS() {
62+
if os.Getenv("DISABLE_MDNS") == "true" {
63+
fmt.Println("mDNS is disabled")
64+
return
65+
}
6166
if PostingmDNS {
6267
return
6368
}

chipper/pkg/vars/config.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ type apiConfig struct {
2121
Unit string `json:"unit"`
2222
} `json:"weather"`
2323
Knowledge struct {
24-
Enable bool `json:"enable"`
25-
Provider string `json:"provider"`
26-
Key string `json:"key"`
27-
ID string `json:"id"`
28-
Model string `json:"model"`
29-
IntentGraph bool `json:"intentgraph"`
30-
RobotName string `json:"robotName"`
24+
Enable bool `json:"enable"`
25+
Provider string `json:"provider"`
26+
Key string `json:"key"`
27+
ID string `json:"id"`
28+
Model string `json:"model"`
29+
IntentGraph bool `json:"intentgraph"`
30+
RobotName string `json:"robotName"`
31+
OpenAIPrompt string `json:"openai_prompt"`
3132
} `json:"knowledge"`
3233
STT struct {
3334
Service string `json:"provider"`

chipper/pkg/wirepod/config-ws/webserver.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
195195
vars.APIConfig.Knowledge.Model = kgModel
196196
vars.APIConfig.Knowledge.ID = kgAPIID
197197
}
198+
if kgProvider == "openai" {
199+
if strings.TrimSpace(r.FormValue("openai_prompt")) != "" {
200+
vars.APIConfig.Knowledge.OpenAIPrompt = r.FormValue("openai_prompt")
201+
} else {
202+
vars.APIConfig.Knowledge.OpenAIPrompt = ""
203+
}
204+
}
198205
if kgProvider == "openai" && kgIntent == "true" {
199206
vars.APIConfig.Knowledge.IntentGraph = true
200207
if r.FormValue("robot_name") == "" {
@@ -217,6 +224,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
217224
kgModel := ""
218225
kgIntent := false
219226
kgRobotName := ""
227+
kgOpenAIPrompt := ""
220228
if vars.APIConfig.Knowledge.Enable {
221229
kgEnabled = true
222230
kgProvider = vars.APIConfig.Knowledge.Provider
@@ -225,6 +233,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
225233
kgAPIID = vars.APIConfig.Knowledge.ID
226234
kgIntent = vars.APIConfig.Knowledge.IntentGraph
227235
kgRobotName = vars.APIConfig.Knowledge.RobotName
236+
kgOpenAIPrompt = vars.APIConfig.Knowledge.OpenAIPrompt
228237
}
229238
fmt.Fprintf(w, "{ ")
230239
fmt.Fprintf(w, " \"kgEnabled\": %t,", kgEnabled)
@@ -233,7 +242,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
233242
fmt.Fprintf(w, " \"kgModel\": \"%s\",", kgModel)
234243
fmt.Fprintf(w, " \"kgApiID\": \"%s\",", kgAPIID)
235244
fmt.Fprintf(w, " \"kgIntentGraph\": \"%t\",", kgIntent)
236-
fmt.Fprintf(w, " \"kgRobotName\": \"%s\"", kgRobotName)
245+
fmt.Fprintf(w, " \"kgRobotName\": \"%s\",", kgRobotName)
246+
fmt.Fprintf(w, " \"kgOpenAIPrompt\": \"%s\"", kgOpenAIPrompt)
237247
fmt.Fprintf(w, "}")
238248
return
239249
case r.URL.Path == "/api/set_stt_info":

chipper/pkg/wirepod/preqs/knowledgegraph.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func houndifyKG(req sr.SpeechRequest) string {
6969
}
7070

7171
func togetherRequest(transcribedText string) string {
72-
sendString := "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. Keep the answer concise yet informative. Here is the question: " + "\\" + "\"" + transcribedText + "\\" + "\"" + " , Answer: "
72+
sendString := "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. Keep the answer concise yet informative. Here is the question: " + "\\" + "\"" + transcribedText + "\\" + "\"" + " , Answer: "
7373
url := "https://api.together.xyz/inference"
7474
model := vars.APIConfig.Knowledge.Model
7575
formData := `{
@@ -110,13 +110,25 @@ func togetherRequest(transcribedText string) string {
110110
}
111111

112112
func openaiRequest(transcribedText string) string {
113-
sendString := "You are a helpful robot called " + vars.APIConfig.Knowledge.RobotName + ". 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. Here is the question: " + "\\" + "\"" + transcribedText + "\\" + "\"" + " , Answer: "
113+
var robName string
114+
if vars.APIConfig.Knowledge.RobotName != "" {
115+
robName = vars.APIConfig.Knowledge.RobotName
116+
} else {
117+
robName = "Vector"
118+
}
119+
defaultPrompt := "You are a helpful robot called " + robName + ". 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."
120+
sendString := " Here is the question: " + "\\" + "\"" + transcribedText + "\\" + "\"" + " , Answer: "
121+
if strings.TrimSpace(vars.APIConfig.Knowledge.OpenAIPrompt) != "" {
122+
sendString = strings.TrimSpace(vars.APIConfig.Knowledge.OpenAIPrompt) + sendString
123+
} else {
124+
sendString = defaultPrompt + sendString
125+
}
114126
logger.Println("Making request to OpenAI...")
115127
url := "https://api.openai.com/v1/completions"
116128
formData := `{
117129
"model": "gpt-3.5-turbo-instruct",
118130
"prompt": "` + sendString + `",
119-
"temperature": 0.7,
131+
"temperature": 0.9,
120132
"max_tokens": 256,
121133
"top_p": 1,
122134
"frequency_penalty": 0.2,

chipper/pkg/wirepod/setup/ssh.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func runCmd(client *ssh.Client, cmd string) (string, error) {
4343
return string(output), nil
4444
}
4545

46+
func setCPURAMfreq(client *ssh.Client, cpufreq string, ramfreq string, gov string) {
47+
runCmd(client, "echo "+cpufreq+" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq && echo disabled > /sys/kernel/debug/msm_otg/bus_voting && echo 0 > /sys/kernel/debug/msm-bus-dbg/shell-client/update_request && echo 1 > /sys/kernel/debug/msm-bus-dbg/shell-client/mas && echo 512 > /sys/kernel/debug/msm-bus-dbg/shell-client/slv && echo 0 > /sys/kernel/debug/msm-bus-dbg/shell-client/ab && echo active clk2 0 1 max "+ramfreq+" > /sys/kernel/debug/rpm_send_msg/message && echo "+gov+" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor && echo 1 > /sys/kernel/debug/msm-bus-dbg/shell-client/update_request")
48+
}
49+
4650
func SetupBotViaSSH(ip string, key []byte) error {
4751
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
4852
SetupScriptPath = vars.AndroidPath + "/static/pod-bot-install.sh"
@@ -83,6 +87,9 @@ func SetupBotViaSSH(ip string, key []byte) error {
8387
return doErr(err, "initial commands")
8488
}
8589
}
90+
setCPURAMfreq(client, "1267200", "800000", "performance")
91+
SetupSSHStatus = "Waiting a few seconds for filesystem syncing"
92+
time.Sleep(time.Second * 3)
8693
SetupSSHStatus = "Transferring bot setup script and certs..."
8794
scpClient, err := scp.NewClientBySSH(client)
8895
if err != nil {
@@ -186,6 +193,7 @@ func SetupBotViaSSH(ip string, key []byte) error {
186193
if err != nil {
187194
return doErr(err, "generating new robot cert")
188195
}
196+
setCPURAMfreq(client, "733333", "500000", "interactive")
189197
client.Close()
190198
SetupSSHStatus = "done"
191199
} else {

chipper/webroot/index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ <h2 id="foldable-add" onclick="toggleSection('content-add', 'content-edit')">
4242
<input type="text" name="paramnameAdd" id="paramnameAdd"><br>
4343
<label for="paramvalueAdd">Intent parameter value (not required):</label>
4444
<input type="text" name="paramvalueAdd" id="paramvalueAdd"><br>
45-
<label for="execAdd">Path to script/program to execute after sending intent:</label>
45+
<label for="execAdd">Path to script/program to execute after sending intent (not required):</label>
4646
<input type="text" name="execAdd" id="execAdd"><br>
47-
<label for="execAdd">Arguments for program (seperated by ,)</label>
47+
<label for="execAdd">Arguments for program (seperated by ,) (not required)</label>
4848
<input type="text" name="execAddArgs" id="execAddArgs" size="50"><br>
4949
</form>
5050
<div class="center">
@@ -74,7 +74,7 @@ <h2 id="foldable-edit" onclick="toggleSection('content-edit', 'content-add')">
7474

7575

7676
<div id="section-botauth" style="display: none;">
77-
<h2>Bot Authentication</h2>
77+
<h2>Authenticate a regular robot</h2>
7878
<div class="center">
7979
<div id="disconnectButton"></div>
8080
</div>
@@ -83,10 +83,11 @@ <h2>Bot Authentication</h2>
8383
</div>
8484
<hr>
8585
<div class="center">
86-
<h3>Set up OSKR/dev bot</h3>
86+
<h3>Authenticate an OSKR/dev-unlocked robot</h3>
87+
<small>Works with firmware 1.4 and above</small>
8788
<div id="oskrSetupProgress"></div>
8889
<div id="oskrSetup">
89-
<small>If you have an OSKR/dev-unlocked bot; enter the bot's IP address and upload the bot's SSH key here, then click "Set up bot". After that, use the above instructions to continue setup. If you have a production bot, don't do this.</small></br>
90+
<small><b>If you have an OSKR/dev-unlocked bot;</b> enter the bot's IP address and upload the bot's SSH key here, then click "Set up bot". After that, head to <a href="https://keriganc.com/vector-epod-setup">https://keriganc.com/vector-epod-setup</a> and follow the instructions.</small></br>
9091
<input type="type" id="sshIp" name="sshIp" placeholder="Bot IP address">
9192
<input type="file" id="sshKeyFile" name="sshKeyFile">
9293
<div class="center">

chipper/webroot/initial.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ <h3>Knowledge Graph Setup</h3>
9393
</select><br>
9494
<span id="houndifyInput" style="display:none">
9595
<small>To use Houndify, create an account at <a href=https://www.houndify.com/signup>houndify.com</a>, create a free domain, and enter the Client ID and Key here.</small><br>
96-
<label for="houndID">Knowledge Graph Client ID:</label>
96+
<label for="houndID">Houndify Client ID:</label>
9797
<input type="text" name="houndID" id="houndID"><br>
98-
<label for="houndKey">Knowledge Graph Client Key:</label>
98+
<label for="houndKey">Houndify Client Key:</label>
9999
<input type="text" name="houndKey" id="houndKey"><br>
100100
</span>
101101
<span id="togetherInput" style="display:none">
@@ -106,8 +106,11 @@ <h3>Knowledge Graph Setup</h3>
106106
<input type="text" name="togetherKey" id="togetherKey"><br>
107107
</span>
108108
<span id="openAIInput" style="display:none">
109-
<label for="openAIKey">Knowledge Graph API Key:</label>
109+
<label for="openAIKey">OpenAI Key:</label>
110110
<input type="text" name="openAIKey" id="openAIKey"><br>
111+
<label for="openAIKey">GPT Prompt (leave blank for default):</label><br>
112+
<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>
113+
<input type="text" name="openAIPrompt" id="openAIPrompt"><br>
111114
<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>
112115
<label for="intentyes">Yes</label>
113116
<input type="radio" id="intentyes" name="intentgselect" value="yes" onclick="checkKG()"><br>

chipper/webroot/js/ble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function checkBLECapability() {
3939
m2.text = vectorEpodSetup
4040
m2.href = vectorEpodSetup
4141
m2.target = "_blank"
42-
m3.innerHTML = "Note: if you have an OSKR/dev-unlocked robot, follow the instructions in the section below this one BEFORE using the web setup."
42+
m3.innerHTML = "Note: if you have an OSKR/dev-unlocked robot, do NOT use this site. Follow the instructions in the section below this one."
4343
m1.class = "center"
4444
m2.class = "center"
4545
m3.class = "center"

0 commit comments

Comments
 (0)