Fix: model load if llama.cpp started after gf-lt
This commit is contained in:
22
bot.go
22
bot.go
@@ -21,6 +21,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/neurosnap/sentences/english"
|
"github.com/neurosnap/sentences/english"
|
||||||
@@ -52,6 +53,7 @@ var (
|
|||||||
//nolint:unused // TTS_ENABLED conditionally uses this
|
//nolint:unused // TTS_ENABLED conditionally uses this
|
||||||
orator extra.Orator
|
orator extra.Orator
|
||||||
asr extra.STT
|
asr extra.STT
|
||||||
|
localModelsMu sync.RWMutex
|
||||||
defaultLCPProps = map[string]float32{
|
defaultLCPProps = map[string]float32{
|
||||||
"temperature": 0.8,
|
"temperature": 0.8,
|
||||||
"dry_multiplier": 0.0,
|
"dry_multiplier": 0.0,
|
||||||
@@ -1002,12 +1004,32 @@ func updateModelLists() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if llama.cpp started after gf-lt?
|
// if llama.cpp started after gf-lt?
|
||||||
|
localModelsMu.Lock()
|
||||||
LocalModels, err = fetchLCPModels()
|
LocalModels, err = fetchLCPModels()
|
||||||
|
localModelsMu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("failed to fetch llama.cpp models", "error", err)
|
logger.Warn("failed to fetch llama.cpp models", "error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshLocalModelsIfEmpty() {
|
||||||
|
localModelsMu.RLock()
|
||||||
|
if len(LocalModels) > 0 {
|
||||||
|
localModelsMu.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localModelsMu.RUnlock()
|
||||||
|
// try to fetch
|
||||||
|
models, err := fetchLCPModels()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("failed to fetch llama.cpp models", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localModelsMu.Lock()
|
||||||
|
LocalModels = models
|
||||||
|
localModelsMu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
cfg, err = config.LoadConfig("config.toml")
|
cfg, err = config.LoadConfig("config.toml")
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ = sync.RWMutex{}
|
||||||
|
|
||||||
// Define constants for cell types
|
// Define constants for cell types
|
||||||
const (
|
const (
|
||||||
CellTypeCheckbox = "checkbox"
|
CellTypeCheckbox = "checkbox"
|
||||||
@@ -138,6 +141,10 @@ func makePropsTable(props map[string]float32) *tview.Table {
|
|||||||
} else if strings.Contains(api, "openrouter.ai") {
|
} else if strings.Contains(api, "openrouter.ai") {
|
||||||
return ORFreeModels
|
return ORFreeModels
|
||||||
}
|
}
|
||||||
|
// Assume local llama.cpp
|
||||||
|
refreshLocalModelsIfEmpty()
|
||||||
|
localModelsMu.RLock()
|
||||||
|
defer localModelsMu.RUnlock()
|
||||||
return LocalModels
|
return LocalModels
|
||||||
}
|
}
|
||||||
var modelRowIndex int // will be set before model row is added
|
var modelRowIndex int // will be set before model row is added
|
||||||
|
|||||||
5
tui.go
5
tui.go
@@ -12,11 +12,14 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ = sync.RWMutex{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
@@ -988,11 +991,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
} else {
|
} else {
|
||||||
|
localModelsMu.RLock()
|
||||||
if len(LocalModels) > 0 {
|
if len(LocalModels) > 0 {
|
||||||
currentLocalModelIndex = (currentLocalModelIndex + 1) % len(LocalModels)
|
currentLocalModelIndex = (currentLocalModelIndex + 1) % len(LocalModels)
|
||||||
chatBody.Model = LocalModels[currentLocalModelIndex]
|
chatBody.Model = LocalModels[currentLocalModelIndex]
|
||||||
cfg.CurrentModel = chatBody.Model
|
cfg.CurrentModel = chatBody.Model
|
||||||
}
|
}
|
||||||
|
localModelsMu.RUnlock()
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
// // For non-OpenRouter APIs, use the old logic
|
// // For non-OpenRouter APIs, use the old logic
|
||||||
// go func() {
|
// go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user