Skip to content

Commit

Permalink
A new start
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed May 31, 2024
0 parents commit bd52c0b
Show file tree
Hide file tree
Showing 19 changed files with 1,619 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build and release
on:
workflow_dispatch:
push:
branches:
- main
- dev
paths:
- 'main.go'
- 'go.mod'
- '.github/workflows/build-and-release.yml'
tags:
- v*
pull_request:
branches:
- main

permissions:
contents: write
checks: write
pull-requests: write
packages: write

concurrency:
group: build-and-release
cancel-in-progress: true

jobs:
build-and-release:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
with:
go-version: 1.22.1

# Install dependencies
- name: Install dependencies
run: go mod download

# Build
- name: Build macOS ARM64
run: |
GOOS=darwin GOARCH=arm64 go build -o main.go -o gollama-macos-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
echo "macOS ARM64 build completed" >> "$GITHUB_STEP_SUMMARY"
- name: Build Linux
run: |
GOOS=linux GOARCH=amd64 go build -o main.go -o gollama-linux-amd64${{ github.ref == 'refs/heads/dev' && '-dev' }}
GOOS=linux GOARCH=arm64 go build -o main.go -o gollama-linux-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
echo "Linux build completed" >> "$GITHUB_STEP_SUMMARY"
- name: Upload artefacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: gollama
path: |
gollama-macos-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
gollama-linux-amd64${{ github.ref == 'refs/heads/dev' && '-dev' }}
gollama-linux-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
# Bump version
- name: Bump version and push tag
id: tag_version
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') && !contains(github.event.head_commit.message, '[skip ci]')
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: main
pre_release_branches: dev

# Publish
- name: Create a GitHub release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') && !contains(github.event.head_commit.message, '[skip ci]')
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
generateReleaseNotes: true
allowUpdates: true
prerelease: ${{ startsWith(github.ref, 'refs/heads/dev') }}
artifacts: |
gollama-macos-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
gollama-linux-amd64${{ github.ref == 'refs/heads/dev' && '-dev' }}
gollama-linux-arm64${{ github.ref == 'refs/heads/dev' && '-dev' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gollama
**/.swp
**/.tmp
**/.trash
**/*.log
dist/
.selected*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sam McLeod

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#### Dynamically Generated Interactive Menu ####

# Error Handling
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c

# Name of this Makefile
MAKEFILE_NAME := $(lastword $(MAKEFILE_LIST))

# Special targets that should not be listed
EXCLUDE_LIST := menu all .PHONY

# Function to extract targets from the Makefile
define extract_targets
$(shell awk -F: '/^[a-zA-Z0-9_-]+:/ {print $$1}' $(MAKEFILE_NAME) | grep -v -E '^($(EXCLUDE_LIST))$$')
endef

TARGETS := $(call extract_targets)

.PHONY: $(TARGETS) menu all

menu: ## Makefile Interactive Menu
@# Check if fzf is installed
@if command -v fzf >/dev/null 2>&1; then \
echo "Using fzf for selection..."; \
echo "$(TARGETS)" | tr ' ' '\n' | fzf > .selected_target; \
target_choice=$$(cat .selected_target); \
else \
echo "fzf not found, using numbered menu:"; \
echo "$(TARGETS)" | tr ' ' '\n' > .targets; \
awk '{print NR " - " $$0}' .targets; \
read -p "Enter choice: " choice; \
target_choice=$$(awk 'NR == '$$choice' {print}' .targets); \
fi; \
if [ -n "$$target_choice" ]; then \
$(MAKE) $$target_choice; \
else \
echo "Invalid choice"; \
fi

# Default target
all: menu

help: ## This help function
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# Targets (example targets listed below)
lint: ## Run lint
gofmt -w .

test: ## Run test
go test -v ./...

build: ## Run build
go build .

run: ## Run
go run *.go
197 changes: 197 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Gollama

Gollama is a Go-based client for Ollama for managing models.
It provides a TUI for listing, sorting, selecting and deleting models and can link Ollama models to LM-Studio.

## Table of Contents

- [Gollama](#gollama)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Logging](#logging)
- [Contributing](#contributing)
- [License](#license)
- [Architecture](#architecture)
- [Component Diagram](#component-diagram)
- [Class Diagram](#class-diagram)

## Features

- Interactive TUI with sorting and filtering capabilities.
- List available models and display basic metadata such as size, quantization level, model family, and modified date.
- Run models.
- Select and delete models.
- Link models to LM-Studio.

![](screenshots/gollama-v1.0.0.jpg)

## Installation

1. Clone the repository:

```shell
git clone https://github.com/sammcj/gollama.git
cd gollama
```

2. Build the project:

```shell
make build
```

## Usage

1. Run the application:

```shell
./gollama
```

2. Use the interactive TUI to list, select, delete, and link models.

## Configuration

Gollama uses a JSON configuration file located at `~/.config/gollama/config.json`. The configuration file includes options for sorting, columns, API keys, log levels etc...

Example configuration:

```json
{
"default_sort": "Size",
"columns": ["Name", "Size", "Quant", "Family", "Modified", "ID"],
"ollama_api_key": "your-api-key",
"lm_studio_file_paths": "/path/to/lm-studio/models",
"log_level": "debug",
"log_file_path": "gollama.log",
"sort_order": "modified",
"strip_string": "my-private-registry.internal/"
}
```

The strip string option can be used to remove a prefix from model names as they are displayed in the TUI.
This can be useful if you have a common prefix such as a private registry that you want to remove for display purposes.

## Logging

Logs can be found in the `gollama.log` which is stored in `$HOME/.config/gollama/gollama.log` by default.
The log level can be set in the configuration file.

## Contributing

Contributions are welcome!
Please fork the repository and create a pull request with your changes.

## License

Copyright © 2024 Sam McLeod

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Architecture

### Component Diagram

```mermaid
graph TD
A[Main Application] --> B[API Client]
A --> C[Configuration]
A --> D[Logging]
A --> E[User Interface]
E --> F[Model List]
E --> G[Key Bindings]
E --> H[Item Delegate]
```

### Class Diagram

```mermaid
classDiagram
class AppModel {
+client : *api.Client
+list : list.Model
+keys : *KeyMap
+models : []Model
+width : int
+height : int
+confirmDeletion : bool
+selectedForDeletion : []Model
+ollamaModelsDir : string
+lmStudioModelsDir : string
+noCleanup : bool
+cfg : *config.Config
+message : string
+Init() tea.Cmd
+Update(msg tea.Msg) (tea.Model, tea.Cmd)
+View() string
+refreshList()
+clearScreen() tea.Model
}
class Model {
+Name : string
+ID : string
+Size : float64
+QuantizationLevel : string
+Modified : time.Time
+Selected : bool
+Family : string
+IDStr() string
+SizeStr() string
+FamilyStr() string
+ModifiedStr() string
+QuantStr() string
+SelectedStr() string
+NameStr() string
+Title() string
+Description() string
+FilterValue() string
}
class Config {
+DefaultSort : string
+Columns : []string
+OllamaAPIKey : string
+LMStudioFilePaths : string
+LogLevel : string
+LogFilePath : string
+SortOrder : string
+LastSortSelection : string
+StripString : string
+LoadConfig() (Config, error)
+SaveConfig(config Config) error
+getConfigPath() string
}
class KeyMap {
+Space : key.Binding
+Delete : key.Binding
+SortByName : key.Binding
+SortBySize : key.Binding
+SortByModified : key.Binding
+SortByQuant : key.Binding
+SortByFamily : key.Binding
+RunModel : key.Binding
+ConfirmYes : key.Binding
+ConfirmNo : key.Binding
+LinkModel : key.Binding
+LinkAllModels : key.Binding
+ClearScreen : key.Binding
+GetSortOrder() string
}
class Logging {
+DebugLogger : *log.Logger
+InfoLogger : *log.Logger
+ErrorLogger : *log.Logger
+Init(logLevel, logFilePath string) error
}
AppModel --> Model
AppModel --> KeyMap
AppModel --> Config
AppModel --> Logging
```
Loading

0 comments on commit bd52c0b

Please sign in to comment.