Chore: linter

This commit is contained in:
Grail Finder
2025-05-19 10:42:10 +03:00
parent a7e7da6f99
commit 94df5b830c
6 changed files with 53 additions and 44 deletions

View File

@@ -1,32 +1,44 @@
version: "2"
run: run:
timeout: 1m
concurrency: 2 concurrency: 2
tests: false tests: false
linters: linters:
enable-all: false default: none
disable-all: true
enable: enable:
- bodyclose
- errcheck - errcheck
- gosimple - fatcontext
- govet - govet
- ineffassign - ineffassign
- staticcheck - noctx
- typecheck - perfsprint
- unused
- prealloc - prealloc
presets: - staticcheck
- performance - unused
settings:
linters-settings: funlen:
funlen: lines: 80
lines: 80 statements: 50
statements: 50 lll:
lll: line-length: 80
line-length: 80 exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues: issues:
exclude:
# Display all issues
max-issues-per-linter: 0 max-issues-per-linter: 0
max-same-issues: 0 max-same-issues: 0
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

12
bot.go
View File

@@ -43,9 +43,10 @@ var (
interruptResp = false interruptResp = false
ragger *rag.RAG ragger *rag.RAG
chunkParser ChunkParser chunkParser ChunkParser
orator extra.Orator //nolint:unused // TTS_ENABLED conditionally uses this
asr extra.STT orator extra.Orator
defaultLCPProps = map[string]float32{ asr extra.STT
defaultLCPProps = map[string]float32{
"temperature": 0.8, "temperature": 0.8,
"dry_multiplier": 0.0, "dry_multiplier": 0.0,
"min_p": 0.05, "min_p": 0.05,
@@ -272,6 +273,7 @@ func roleToIcon(role string) string {
return "<" + role + ">: " return "<" + role + ">: "
} }
// FIXME: it should not be here; move to extra
func checkGame(role string, tv *tview.TextView) { func checkGame(role string, tv *tview.TextView) {
// Handle Cluedo game flow // Handle Cluedo game flow
// should go before form msg, since formmsg takes chatBody and makes ioreader out of it // 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} playerOrder = []string{cfg.UserRole, cfg.AssistantRole, cfg.CluedoRole2}
cluedoState = extra.CluedoPrepCards(playerOrder) cluedoState = extra.CluedoPrepCards(playerOrder)
} }
// notifyUser("got in cluedo", "yay")
notifyUser("got in cluedo", "yay")
currentPlayer := playerOrder[0] currentPlayer := playerOrder[0]
playerOrder = append(playerOrder[1:], currentPlayer) // Rotate turns playerOrder = append(playerOrder[1:], currentPlayer) // Rotate turns
if role == cfg.UserRole { 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) { func chatRound(userMsg, role string, tv *tview.TextView, regen, resume bool) {

View File

@@ -46,17 +46,12 @@ type KokoroOrator struct {
} }
func stoproutine(orator Orator) { func stoproutine(orator Orator) {
select { <-TTSDoneChan
case <-TTSDoneChan: orator.GetLogger().Info("orator got done signal")
orator.GetLogger().Info("orator got done signal") orator.Stop()
orator.Stop() // drain the channel
// close(TTSTextChan) for len(TTSTextChan) > 0 {
// TTSTextChan = make(chan string, 10000) <-TTSTextChan
// drain the channel
for len(TTSTextChan) > 0 {
<-TTSTextChan
}
return
} }
} }

View File

@@ -32,7 +32,6 @@ type WhisperSTT struct {
ServerURL string ServerURL string
SampleRate int SampleRate int
AudioBuffer *bytes.Buffer AudioBuffer *bytes.Buffer
streamer StreamCloser
recording bool recording bool
} }
@@ -90,7 +89,7 @@ func (stt *WhisperSTT) StopRecording() (string, error) {
return "", err return "", err
} }
// Send request // 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 { if err != nil {
stt.logger.Error("fn: StopRecording", "error", err) stt.logger.Error("fn: StopRecording", "error", err)
return "", err return "", err
@@ -122,7 +121,9 @@ func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) {
binary.LittleEndian.PutUint16(header[34:36], 16) binary.LittleEndian.PutUint16(header[34:36], 16)
copy(header[36:40], "data") copy(header[36:40], "data")
binary.LittleEndian.PutUint32(header[40:44], uint32(dataSize)) 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 { func (stt *WhisperSTT) IsRecording() bool {
@@ -136,7 +137,9 @@ func (stt *WhisperSTT) microphoneStream(sampleRate int) error {
in := make([]int16, 64) in := make([]int16, 64)
stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(in), in) stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(in), in)
if err != nil { 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) return fmt.Errorf("failed to open microphone: %w", err)
} }
go func(stream *portaudio.Stream) { go func(stream *portaudio.Stream) {

View File

@@ -22,7 +22,6 @@ const (
writeHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" writeHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
) )
type PngEmbed struct { type PngEmbed struct {
Key string Key string
Value string Value string
@@ -96,7 +95,7 @@ func ReadCard(fname, uname string) (*models.CharCard, error) {
return nil, err return nil, err
} }
if charSpec.Name == "" { 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 return charSpec.Simplify(uname, fname), nil
} }

View File

@@ -235,7 +235,7 @@ func (r *RAG) LineToVector(line string) ([]float32, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != 200 { 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()) r.logger.Error(err.Error())
return nil, err return nil, err
} }