Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed May 30, 2024
1 parent 8f53ec2 commit e6ef724
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 1 deletion.
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 }}
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.
231 changes: 231 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# gollama - Go manage your Ollama models

gollama is a TUI application to help manage your Ollama models. It provides an interactive way to view, sort, run, and delete your models.

## Features

- List all available models with details such as name, ID, size, quantization level, and modified date.
- Sort models by name, size, or modified date.
- Select multiple models for deletion.
- Run a selected model using the Ollama CLI.
- Logging to `gollama.log` file with debug, info, and error levels.

## Installation

1. Ensure you have Go installed on your system.
2. Clone this repository:

```bash
git clone https://github.com/yourusername/gollama.git
```

3. Navigate to the project directory:

```bash
cd gollama
```

4. Build the application:

```bash
go build -o gollama main.go
```

## Usage

Run the application:

```bash
gollama
```

Use the following keyboard shortcuts to interact with the TUI:

| Key | Action |
| ----- | ----------------------- |
| Space | Select/deselect a model |
| D | Delete selected models |
| s | Sort by name |
| S | Sort by size |
| m | Sort by modified date |
| Enter | Run the selected model |
| y | Confirm deletion |
| n | Cancel deletion |

## Architecture

_Current as of 2024-05-30_

Component Diagram (PlantUML):

```plantuml
@startuml
title Gollama Application Component Diagram
component "Main Package" {
[AppModel]
[main]
}
component "Ollama API Client" {
[api.Client]
}
component "Bubbletea Library" {
interface tea.Model <<interface>>
}
component "Charmbracelet Bubbles" {
[list.Model]
[key.Binding]
}
[AppModel] --> [api.Client]: Uses for API calls
[AppModel] --> [list.Model]: Displays model data
[KeyMap] --> [list.Model]: Handles user input
[tea.Program] -down-> [AppModel]: Manages the application's state
@enduml
```

Class Diagram (PlantUML):

```plantuml
@startuml
title Gollama Application Class Diagram
class Model {
- Name: string
- ID: string
- Size: float64
- QuantizationLevel: string
- Modified: time.Time
- Selected: bool
+ Title(): string
+ Description(): string
+ FilterValue(): string
}
class KeyMap {
- Space: key.Binding
- Delete: key.Binding
- SortByName: key.Binding
- SortBySize: key.Binding
- SortByModified: key.Binding
- RunModel: key.Binding
- ConfirmYes: key.Binding
- ConfirmNo: key.Binding
}
class AppModel {
- client: *api.Client
- list: list.Model
- keys: *KeyMap
- models: []Model
- width: int
- height: int
- confirmDeletion: bool
- selectedForDeletion: []Model
+ Init(): tea.Cmd
+ Update(msg tea.Msg): (tea.Model, tea.Cmd)
+ View(): string
}
class "main" {
+ main(): void
}
AppModel --> Model: Contains
AppModel --> KeyMap: Uses
"main" --> AppModel: Creates and initializes
@enduml
```

```plantuml
@startuml
title Gollama Application Architecture
package "Main Package" {
class Model {
- Name: string
- ID: string
- Size: float64
- QuantizationLevel: string
- Modified: time.Time
- Selected: bool
+ Title(): string
+ Description(): string
+ FilterValue(): string
}
class KeyMap {
- Space: key.Binding
- Delete: key.Binding
- SortByName: key.Binding
- SortBySize: key.Binding
- SortByModified: key.Binding
- RunModel: key.Binding
- ConfirmYes: key.Binding
- ConfirmNo: key.Binding
}
class AppModel {
- client: *api.Client
- list: list.Model
- keys: *KeyMap
- models: []Model
- width: int
- height: int
- confirmDeletion: bool
- selectedForDeletion: []Model
}
class "main" {
+ main(): void
}
}
package "Ollama API Client" {
class "api.Client" {
+ List(ctx context.Context) (*ListResponse, error)
+ Delete(ctx context.Context, req *DeleteRequest) error
}
class "ListResponse" {}
class "DeleteRequest" {}
}
package "Bubbletea Library" {
interface tea.Model {
Init(): tea.Cmd
Update(msg tea.Msg): (tea.Model, tea.Cmd)
View(): string
}
}
package "Charmbracelet Bubbles" {
class "list.Model" {}
class "key.Binding" {}
}
main --> AppModel: Creates and initializes
AppModel --> api.Client: Uses for API calls
api.Client <-- AppModel: Fetches model data
AppModel --> list.Model: Displays model data
list.Model <--> Model: Contains items of type Model
AppModel --> KeyMap: Defines key bindings
KeyMap --> list.Model: Handles user input
AppModel --> "tea.Program": Runs the application
"tea.Program" -down-> AppModel: Manages the application's state
@enduml
```

## Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

## License

[MIT License](LICENSE)

Copyright © 2024 Sam McLeod
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
infoLogger.Println("Delete key pressed")
m.selectedForDeletion = getSelectedModels(m.models)
infoLogger.Printf("Selected models for deletion: %+v\n", m.selectedForDeletion)
if len(m.selectedForDeletion) == 0 {
infoLogger.Println("No models selected for deletion")
break
}
m.confirmDeletion = true
case key.Matches(msg, m.keys.ConfirmYes):
if m.confirmDeletion {
Expand Down Expand Up @@ -266,7 +270,11 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m *AppModel) View() string {
if m.confirmDeletion {
return lipgloss.NewStyle().Bold(true).Render("Are you sure you want to delete the selected models? (y/N): ")
selectedModelsList := ""
for _, model := range m.selectedForDeletion {
selectedModelsList += fmt.Sprintf("- %s\n", model.Name)
}
return fmt.Sprintf("Are you sure you want to delete the following models?\n%s(y/N): ", selectedModelsList)
}

nameWidth, sizeWidth, quantWidth, modifiedWidth, idWidth := calculateColumnWidths(m.width)
Expand Down
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>sammcj/renovate-config"
]
}

0 comments on commit e6ef724

Please sign in to comment.