-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e9ddccc
Showing
19 changed files
with
1,626 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
gollama | ||
**/.swp | ||
**/.tmp | ||
**/.trash | ||
**/*.log | ||
dist/ | ||
.selected* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
# Gollama | ||
|
||
Gollama is a Go-based client for Ollama for managing models. It provides a TUI for listing, 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) | ||
- [Makefile](#makefile) | ||
- [Logging](#logging) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Architecture](#architecture) | ||
- [Component Diagram](#component-diagram) | ||
- [Class Diagram](#class-diagram) | ||
|
||
## Features | ||
|
||
- List available models from Ollama. | ||
- Select and delete models. | ||
- Link models to LM-Studio. | ||
- Configurable via JSON. | ||
- Interactive TUI with sorting and filtering capabilities. | ||
|
||
![](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. | ||
|
||
## Makefile | ||
|
||
The Makefile includes an interactive menu for common tasks such as building, running, testing, and linting the project. | ||
|
||
To use the interactive menu: | ||
|
||
```shell | ||
make menu | ||
``` | ||
|
||
## Logging | ||
|
||
Gollama uses a custom logging package that supports different log levels and outputs to a specified log 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 | ||
``` |
Oops, something went wrong.