Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed May 31, 2024
1 parent ffc365c commit 550c4d7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.models[i].Family < m.models[j].Family
})
m.refreshList()
m.keys.SortOrder = "family" // Update sort order
case key.Matches(msg, m.keys.RunModel):
if item, ok := m.list.SelectedItem().(Model); ok {
runModel(item.Name)
Expand Down Expand Up @@ -115,7 +116,6 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.height = msg.Height
m.list.SetSize(m.width, m.height-5)
}

var cmd tea.Cmd
m.list, cmd = m.list.Update(msg)
return m, cmd
Expand Down
14 changes: 13 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type Config struct {
LMStudioFilePaths string `json:"lm_studio_file_paths"`
LogLevel string `json:"log_level"`
LogFilePath string `json:"log_file_path"`
SortOrder string `json:"sort_order"`
SortOrder string `json:"sort_order"` // Current sort order
LastSortSelection string `json:"-"` // Temporary field to hold the last sort selection
}

var defaultConfig = Config{
Expand All @@ -27,6 +28,11 @@ var defaultConfig = Config{
SortOrder: "modified", // Default sort order
}

type ConfigOption struct {
Key string
Value string
}

func LoadConfig() (Config, error) {
configPath := getConfigPath()
fmt.Println("Loading config from:", configPath) // Debug print
Expand Down Expand Up @@ -56,17 +62,23 @@ func LoadConfig() (Config, error) {
if err := json.NewDecoder(file).Decode(&config); err != nil {
return Config{}, fmt.Errorf("failed to decode config file: %w", err)
}

// Set the last sort selection to the current sort order
config.LastSortSelection = config.SortOrder

return config, nil
}

func SaveConfig(config Config) error {
configPath := getConfigPath()
fmt.Println("Saving config to:", configPath) // Debug print

// if the config file doesn't exist, create it
file, err := os.Create(configPath)
if err != nil {
return fmt.Errorf("failed to create config file: %w", err)
}

defer file.Close()

if err := json.NewEncoder(file).Encode(config); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package main
import (
"gollama/logging"

"github.com/charmbracelet/lipgloss"
"github.com/ollama/ollama/api"
)

func parseAPIResponse(resp *api.ListResponse) []Model {
models := make([]Model, len(resp.Models))
for i, modelResp := range resp.Models {
models[i] = Model{
Name: modelResp.Name,
Name: lipgloss.NewStyle().Foreground(lipgloss.Color("white")).Render(modelResp.Name),
ID: truncate(modelResp.Digest, 7), // Truncate the ID
Size: float64(modelResp.Size) / (1024 * 1024 * 1024), // Convert bytes to GB
QuantizationLevel: modelResp.Details.QuantizationLevel,
Expand Down
10 changes: 0 additions & 10 deletions item_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, item list.Ite
quantColor := colors.QuantColor(model.QuantizationLevel)
sizeColor := colors.SizeColor(model.Size)

// highlight some key words in model names (e.g. "instruct" or "code")
if model.Name == "instruct" || model.Name == "code" {
nameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Bold(true).BorderLeft(true).BorderStyle(lipgloss.OuterHalfBlockBorder()).BorderLeftBackground(lipgloss.Color("200"))
sizeStyle = lipgloss.NewStyle().Foreground(sizeColor).Bold(true).BorderLeft(true).BorderLeftBackground(lipgloss.Color("200"))
quantStyle = lipgloss.NewStyle().Foreground(quantColor).Bold(true).BorderLeft(true).BorderLeftBackground(lipgloss.Color("200"))
familyStyle = lipgloss.NewStyle().Foreground(familyColor).Bold(true).BorderLeft(true).BorderLeftBackground(lipgloss.Color("200"))
modifiedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("115")).BorderLeft(true)
idStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("225")).BorderLeft(true)
}

if index == m.Index() {
// Highlight the selected item
nameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Bold(true).BorderLeft(true).BorderStyle(lipgloss.OuterHalfBlockBorder()).BorderLeftBackground(lipgloss.Color("200"))
Expand Down
5 changes: 5 additions & 0 deletions keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ func NewKeyMap() *KeyMap {
LinkAllModels: key.NewBinding(key.WithKeys("L"), key.WithHelp("L", "link all models to LM Studio")),
}
}

// a function to get the state of the sort order
func (k *KeyMap) GetSortOrder() string {
return k.SortOrder
}
17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func main() {
sort.Slice(groupedModels, func(i, j int) bool {
return groupedModels[i].Modified.After(groupedModels[j].Modified)
})
case "family":
sort.Slice(groupedModels, func(i, j int) bool {
return groupedModels[i].Family < groupedModels[j].Family
})
}

items := make([]list.Item, len(groupedModels))
Expand Down Expand Up @@ -155,14 +159,17 @@ func main() {
}

app.list = l
if _, err := tea.NewProgram(&app, tea.WithAltScreen()).Run(); err != nil {

p := tea.NewProgram(&app, tea.WithAltScreen(), tea.WithMouseCellMotion())
if _, err := p.Run(); err != nil {
logging.ErrorLogger.Printf("Error: %v", err)
l.ResetSelected()
} else {
// Clear the terminal screen again to refresh the application view
fmt.Print("\033[H\033[2J")
}

// Save the config with any values (e.g. sorted column) that may have changed
cfg.SortOrder = app.keys.SortOrder // Save the current sort order to config
// Save the updated configuration
if err := config.SaveConfig(cfg); err != nil {
logging.ErrorLogger.Println("Error saving config:", err)
panic(err)
}
}
3 changes: 2 additions & 1 deletion operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func linkModel(modelName, lmStudioModelsDir string, noCleanup bool) error {
lmStudioModelName := strings.ReplaceAll(strings.ReplaceAll(modelName, ":", "-"), "_", "-")
lmStudioModelDir := filepath.Join(lmStudioModelsDir, author, lmStudioModelName+"-GGUF")

fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("cyan")).Render(fmt.Sprintf("Model: %s\nPath: %s", modelName, modelPath)))
fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("cyan")).Render(fmt.Sprintf("Model: %s", modelName)))
fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("green")).Render(fmt.Sprintf("Path: %s", modelPath)))
fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("green")).Render(fmt.Sprintf("LM Studio model directory: %s", lmStudioModelDir)))

// Check if the model path is a valid file
Expand Down

0 comments on commit 550c4d7

Please sign in to comment.