Fix: dynamic model update based on api
This commit is contained in:
@@ -130,21 +130,48 @@ func makePropsTable(props map[string]float32) *tview.Table {
|
|||||||
addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) {
|
addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) {
|
||||||
setLogLevel(option)
|
setLogLevel(option)
|
||||||
})
|
})
|
||||||
|
// Helper function to get model list for a given API
|
||||||
|
getModelListForAPI := func(api string) []string {
|
||||||
|
var list []string
|
||||||
|
if strings.Contains(api, "api.deepseek.com/") {
|
||||||
|
list = []string{chatBody.Model, "deepseek-chat", "deepseek-reasoner"}
|
||||||
|
} else if strings.Contains(api, "openrouter.ai") {
|
||||||
|
list = ORFreeModels
|
||||||
|
} else {
|
||||||
|
list = LocalModels
|
||||||
|
}
|
||||||
|
// Ensure current chatBody.Model is in the list
|
||||||
|
if len(list) > 0 && !slices.Contains(list, chatBody.Model) {
|
||||||
|
list = slices.Insert(list, 0, chatBody.Model)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
var modelRowIndex int // will be set before model row is added
|
||||||
|
|
||||||
// Prepare API links dropdown - insert current API at the beginning
|
// Prepare API links dropdown - insert current API at the beginning
|
||||||
apiLinks := slices.Insert(cfg.ApiLinks, 0, cfg.CurrentAPI)
|
apiLinks := slices.Insert(cfg.ApiLinks, 0, cfg.CurrentAPI)
|
||||||
addListPopupRow("Select an api", apiLinks, cfg.CurrentAPI, func(option string) {
|
addListPopupRow("Select an api", apiLinks, cfg.CurrentAPI, func(option string) {
|
||||||
cfg.CurrentAPI = option
|
cfg.CurrentAPI = option
|
||||||
})
|
// Update model list based on new API
|
||||||
var modelList []string
|
newModelList := getModelListForAPI(cfg.CurrentAPI)
|
||||||
// INFO: modelList is chosen based on current api link
|
modelCellID := fmt.Sprintf("listpopup_%d", modelRowIndex)
|
||||||
if strings.Contains(cfg.CurrentAPI, "api.deepseek.com/") {
|
if data := cellData[modelCellID]; data != nil {
|
||||||
modelList = []string{chatBody.Model, "deepseek-chat", "deepseek-reasoner"}
|
data.Options = newModelList
|
||||||
} else if strings.Contains(cfg.CurrentAPI, "opentouter.ai") {
|
|
||||||
modelList = ORFreeModels
|
|
||||||
} else { // would match on localhost but what if llama.cpp served non localy?
|
|
||||||
modelList = LocalModels
|
|
||||||
}
|
}
|
||||||
|
// Ensure chatBody.Model is in the new list; if not, set to first available model
|
||||||
|
if len(newModelList) > 0 && !slices.Contains(newModelList, chatBody.Model) {
|
||||||
|
chatBody.Model = newModelList[0]
|
||||||
|
// Update the displayed cell text
|
||||||
|
if cell := table.GetCell(modelRowIndex, 1); cell != nil {
|
||||||
|
cell.SetText(chatBody.Model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Prepare model list dropdown
|
// Prepare model list dropdown
|
||||||
|
modelRowIndex = row
|
||||||
|
modelList := getModelListForAPI(cfg.CurrentAPI)
|
||||||
addListPopupRow("Select a model", modelList, chatBody.Model, func(option string) {
|
addListPopupRow("Select a model", modelList, chatBody.Model, func(option string) {
|
||||||
chatBody.Model = option
|
chatBody.Model = option
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user