summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.golangci.yml50
-rw-r--r--bot.go12
-rw-r--r--extra/audio.go17
-rw-r--r--extra/stt.go11
-rw-r--r--pngmeta/metareader.go3
-rw-r--r--rag/main.go2
6 files changed, 52 insertions, 43 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 66732bf..d377c38 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,32 +1,44 @@
+version: "2"
run:
- timeout: 1m
concurrency: 2
tests: false
-
linters:
- enable-all: false
- disable-all: true
+ default: none
enable:
+ - bodyclose
- errcheck
- - gosimple
+ - fatcontext
- govet
- ineffassign
+ - noctx
+ - perfsprint
+ - prealloc
- staticcheck
- - typecheck
- unused
- - prealloc
- presets:
- - performance
-
-linters-settings:
- funlen:
- lines: 80
- statements: 50
- lll:
- line-length: 80
-
+ settings:
+ funlen:
+ lines: 80
+ statements: 50
+ lll:
+ line-length: 80
+ exclusions:
+ generated: lax
+ presets:
+ - comments
+ - common-false-positives
+ - legacy
+ - std-error-handling
+ paths:
+ - third_party$
+ - builtin$
+ - examples$
issues:
- exclude:
- # Display all issues
max-issues-per-linter: 0
max-same-issues: 0
+formatters:
+ exclusions:
+ generated: lax
+ paths:
+ - third_party$
+ - builtin$
+ - examples$
diff --git a/bot.go b/bot.go
index 6b733b2..f3ceb69 100644
--- a/bot.go
+++ b/bot.go
@@ -43,9 +43,10 @@ var (
interruptResp = false
ragger *rag.RAG
chunkParser ChunkParser
- orator extra.Orator
- asr extra.STT
- defaultLCPProps = map[string]float32{
+ //nolint:unused // TTS_ENABLED conditionally uses this
+ orator extra.Orator
+ asr extra.STT
+ defaultLCPProps = map[string]float32{
"temperature": 0.8,
"dry_multiplier": 0.0,
"min_p": 0.05,
@@ -272,6 +273,7 @@ func roleToIcon(role string) string {
return "<" + role + ">: "
}
+// FIXME: it should not be here; move to extra
func checkGame(role string, tv *tview.TextView) {
// Handle Cluedo game flow
// should go before form msg, since formmsg takes chatBody and makes ioreader out of it
@@ -283,8 +285,7 @@ func checkGame(role string, tv *tview.TextView) {
playerOrder = []string{cfg.UserRole, cfg.AssistantRole, cfg.CluedoRole2}
cluedoState = extra.CluedoPrepCards(playerOrder)
}
-
- notifyUser("got in cluedo", "yay")
+ // notifyUser("got in cluedo", "yay")
currentPlayer := playerOrder[0]
playerOrder = append(playerOrder[1:], currentPlayer) // Rotate turns
if role == cfg.UserRole {
@@ -296,7 +297,6 @@ func checkGame(role string, tv *tview.TextView) {
})
}
}
- return
}
func chatRound(userMsg, role string, tv *tview.TextView, regen, resume bool) {
diff --git a/extra/audio.go b/extra/audio.go
index 8b0d8f9..fc5e2ba 100644
--- a/extra/audio.go
+++ b/extra/audio.go
@@ -46,17 +46,12 @@ type KokoroOrator struct {
}
func stoproutine(orator Orator) {
- select {
- case <-TTSDoneChan:
- orator.GetLogger().Info("orator got done signal")
- orator.Stop()
- // close(TTSTextChan)
- // TTSTextChan = make(chan string, 10000)
- // drain the channel
- for len(TTSTextChan) > 0 {
- <-TTSTextChan
- }
- return
+ <-TTSDoneChan
+ orator.GetLogger().Info("orator got done signal")
+ orator.Stop()
+ // drain the channel
+ for len(TTSTextChan) > 0 {
+ <-TTSTextChan
}
}
diff --git a/extra/stt.go b/extra/stt.go
index 950f7a9..51fd314 100644
--- a/extra/stt.go
+++ b/extra/stt.go
@@ -32,7 +32,6 @@ type WhisperSTT struct {
ServerURL string
SampleRate int
AudioBuffer *bytes.Buffer
- streamer StreamCloser
recording bool
}
@@ -90,7 +89,7 @@ func (stt *WhisperSTT) StopRecording() (string, error) {
return "", err
}
// Send request
- resp, err := http.Post("http://localhost:8081/inference", writer.FormDataContentType(), body)
+ resp, err := http.Post(stt.ServerURL, writer.FormDataContentType(), body)
if err != nil {
stt.logger.Error("fn: StopRecording", "error", err)
return "", err
@@ -122,7 +121,9 @@ func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) {
binary.LittleEndian.PutUint16(header[34:36], 16)
copy(header[36:40], "data")
binary.LittleEndian.PutUint32(header[40:44], uint32(dataSize))
- w.Write(header)
+ if _, err := w.Write(header); err != nil {
+ stt.logger.Error("writeWavHeader", "error", err)
+ }
}
func (stt *WhisperSTT) IsRecording() bool {
@@ -136,7 +137,9 @@ func (stt *WhisperSTT) microphoneStream(sampleRate int) error {
in := make([]int16, 64)
stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(in), in)
if err != nil {
- portaudio.Terminate()
+ if paErr := portaudio.Terminate(); paErr != nil {
+ return fmt.Errorf("failed to open microphone: %w; terminate error: %w", err, paErr)
+ }
return fmt.Errorf("failed to open microphone: %w", err)
}
go func(stream *portaudio.Stream) {
diff --git a/pngmeta/metareader.go b/pngmeta/metareader.go
index 408af18..c396b4e 100644
--- a/pngmeta/metareader.go
+++ b/pngmeta/metareader.go
@@ -22,7 +22,6 @@ const (
writeHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
)
-
type PngEmbed struct {
Key string
Value string
@@ -96,7 +95,7 @@ func ReadCard(fname, uname string) (*models.CharCard, error) {
return nil, err
}
if charSpec.Name == "" {
- return nil, fmt.Errorf("failed to find role; fname %s\n", fname)
+ return nil, fmt.Errorf("failed to find role; fname %s", fname)
}
return charSpec.Simplify(uname, fname), nil
}
diff --git a/rag/main.go b/rag/main.go
index 5e53839..f3028b4 100644
--- a/rag/main.go
+++ b/rag/main.go
@@ -235,7 +235,7 @@ func (r *RAG) LineToVector(line string) ([]float32, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
- err = fmt.Errorf("non 200 resp; code: %v\n", resp.StatusCode)
+ err = fmt.Errorf("non 200 resp; code: %v", resp.StatusCode)
r.logger.Error(err.Error())
return nil, err
}