Skip to content

Commit

Permalink
Feature/basic chat (#9)
Browse files Browse the repository at this point in the history
* start of chat screen

* updated deps

* added precommit config

* major formatting / linting rework

* fix locating ollama executable in certain environments

* fix tab focus issue

* remember last tab used and start on that tab next launch

* changed custom ollama url env var to not conflict with existing ollama var
initial rollout of chat tab
  • Loading branch information
paulrobello authored Jul 2, 2024
1 parent 0502e0b commit efaa531
Show file tree
Hide file tree
Showing 60 changed files with 3,032 additions and 2,058 deletions.
65 changes: 65 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
default_stages: [pre-commit, pre-push]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-docstring-first
- id: check-json
- id: check-toml
- id: detect-private-key
- id: mixed-line-ending
- id: pretty-format-json
args: [--autofix, --no-sort-keys]
exclude: tests(/\w*)*/functional/|tests/input|tests(/.*)+/conftest.py|doc/data/messages|tests(/\w*)*data/

#- repo: https://github.com/asottile/pyupgrade
# rev: v3.16.0
# hooks:
# - id: pyupgrade

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
exclude: tests(/\w*)*/functional/|tests/input|tests(/.*)+/conftest.py|doc/data/messages|tests(/\w*)*data/

- repo: https://github.com/asottile/reorder-python-imports
rev: v3.13.0
hooks:
- id: reorder-python-imports
args: [--py39-plus, --add-import, 'from __future__ import annotations']
exclude: tests(/\w*)*/functional/|tests/input|tests(/.*)+/conftest.py|doc/data/messages|tests(/\w*)*data/

#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.10.1
# hooks:
# - id: mypy
# additional_dependencies: [textual, rich, pydantic, ollama, docker, types-beautifulsoup4, types-requests, types-pytz, types-simplejson, typing-extensions, asyncio, humanize, argparse, python-dotenv]
# exclude: tests(/\w*)*/functional/|tests/input|tests(/.*)+/conftest.py|doc/data/messages|tests(/\w*)*data/

- repo: local
hooks:
- id: mypy
name: mypy
entry: make
language: system
pass_filenames: false
args:
[typecheck]
exclude: tests(/\w*)*/functional/|tests/input|tests(/\w*)*data/|doc/

- repo: local
hooks:
- id: pylint
name: pylint
entry: make
language: system
pass_filenames: false
args:
[lint]
exclude: tests(/\w*)*/functional/|tests/input|tests(/\w*)*data/|doc/
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ clear_cache: # Clear application cache
dev: # Run in dev mode
$(run) textual run --dev $(lib).app:ParLlamaApp

.PHONY: wsl-dev
wsl-dev: # Run in dev mode
$(run) textual run --dev $(lib).app:ParLlamaApp -u "http://$(shell hostname).local:11434"

.PHONY: wsl-run
wsl-run: # Run in dev mode
$(python) -m $(lib) -u "http://$(shell hostname).local:11434"

.PHONY: chat_dev
chat_dev: # Run in dev mode
$(run) textual run --dev $(lib).app:ParLlamaApp -s chat

.PHONY: chat
chat: # Run in dev mode
$(python) -m $(lib) -s chat

.PHONY: debug
debug: # Run in debug mode
Expand Down Expand Up @@ -93,10 +108,10 @@ stricttypecheck: # Perform a strict static type checks with mypy
$(mypy) --scripts-are-modules --strict $(lib)

.PHONY: checkall
checkall: lint typecheck # Check all the things
checkall: typecheck lint # Check all the things

.PHONY: dobeforecommit
dobeforecommit: ugly checkall # Format then check
.PHONY: do-before-commit
do-before-commit: ugly checkall # Format then check

##############################################################################
# Package/publish.
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ textual-dev = "*"
types-requests = "*"
types-beautifulsoup4 = "*"
pydevd_pycharm = "*"
pre-commit = "*"

[requires]
python_version = "3.11"
3,738 changes: 1,972 additions & 1,766 deletions Pipfile.lock

Large diffs are not rendered by default.

63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ The application was built with [Textual](https://textual.textualize.io/) and [Ri
Supports Dark and Light mode as well as custom themes.

![Local Models Dark](https://raw.githubusercontent.com/paulrobello/parllama/main/docs/local_models_dark_1.png)

![Model View Dark](https://raw.githubusercontent.com/paulrobello/parllama/main/docs/models_view_dark_1.png)

![Site Models Dark](https://raw.githubusercontent.com/paulrobello/parllama/main/docs/site_models_dark_1.png)

![Chat Dark](https://raw.githubusercontent.com/paulrobello/parllama/main/docs/chat_dark_1.png)

![Local Models Light](https://raw.githubusercontent.com/paulrobello/parllama/main/docs/local_models_light_1.png)

## Prerequisites for running
* Install and run [Ollama](https://ollama.com/download)
* Install and run [Ollama](https://ollama.com/download)
* Install Python 3.11 or newer

## Prerequisites for dev
* Install pipenv
* Install GNU Compatible Make command

## Prerequisites for model quantization
If you want to be able to quantize custom models, download the following tool from the releases area:
If you want to be able to quantize custom models, download the following tool from the releases area:
[HuggingFaceModelDownloader](https://github.com/bodaay/HuggingFaceModelDownloader)

Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
Expand All @@ -35,6 +37,11 @@ docker pull ollama/quantize
```

## Installing from mypi using pipx
If you don't have pipx installed you can run the following:
```bash
pip install pipx
```
Once pipx is installed, run the following:
```bash
pipx install parllama
```
Expand Down Expand Up @@ -81,13 +88,15 @@ options:
--no-save Prevent saving settings for this session.
```

Unless you specify "--no-save" most flags such as -u, -t, -m, -s are sticky and will be used next time you start PAR_LLAMA.

## Environment Variables
* PARLLAMA_DATA_DIR - Used to set --data-dir
* PARLLAMA_THEME_NAME - Used to set --theme-name
* PARLLAMA_THEME_MODE - Used to set --theme-mode
* OLLAMA_HOST - Used to set --ollama-url
* OLLAMA_URL - Used to set --ollama-url

## Running Par Llama
## Running PAR_LLAMA

### with pipx installation
From anywhere:
Expand All @@ -102,6 +111,25 @@ source venv/Scripts/activate
parllama
```

## Running under Windows WSL
Ollama by default only listens to localhost for connections, so you must set the environment variable OLLAMA_HOST=0.0.0.0:11434
to make it listen on all interfaces.
**Note: this will allow connections to your Ollama server from other devices on any network you are connected to.**
If you have Ollama installed via the native Windows installer you must set OLLAMA_HOST=0.0.0.0:11434 in the "System Variable" section
of the "Environment Variables" control panel.
If you installed Ollama under WSL, setting the var with ```export OLLAMA_HOST=0.0.0.0:11434``` before starting the Ollama server will have it listen on all interfaces.
If your Ollama server is already running, stop and start it to ensure it picks up the new environment variable.
You can validate what interfaces the Ollama server is listening on by looking at the server.log file in the Ollama config folder.
You should see as one of the first few lines "OLLAMA_HOST:http://0.0.0.0:11434"

Now that the server is listening on all interfaces you must instruct PAR_LLAMA to use a custom Ollama connection url with the "-u" flag.
The command will look something like this:
```bash
parllama -u "http://$(hostname).local:11434"
```

PAR_LLAMA will remember the -u flag so subsequent runs will not require that you specify it.

### Dev mode
From repo root:
```bash
Expand Down Expand Up @@ -146,14 +174,35 @@ You must specify at least one of light or dark for the theme to be usable.

Theme can be changed via command line with the ```--theme-name``` option.

## Contributing
Start by following the instructions in the section **Installing for dev mode**.

Please ensure that all pull requests are formatted with black, pass mypy and pylint with 10/10 checks.
You can run the make target **do-before-commit** to ensure the pipeline will pass with your changes.
There is also a pre-commit config to that will assist with formatting and checks.
The easiest way to setup your environment to ensure smooth pull requests is:

If you don't have pipx installed you can run the following:
```bash
pip install pipx
```

```bash
pipx install pre-commit
pre-commit install
pre-commit run --all-files
```
After running the above all future commits will auto run pre-commit. pre-commit will fix what it can and show what
if anything remains to be fixed before the commit is allowed.


## Roadmap

**Where we are**
* Initial release - Maintain and create new models
* Initial release - Find, maintain and create new models
* Basic chat with LLM

**Where we're going**
* Basic chat with LLM
* Chat history / conversation management
* Chat with multiple models at same time to compare outputs
* LLM tool use
Binary file added docs/chat_dark_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/local_models_dark_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/local_models_light_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/models_view_dark_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/site_models_dark_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion parllama/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""PAR LLAMA TUI - A terminal user interface for Ollama."""
from __future__ import annotations

__author__ = "Paul Robello"
__copyright__ = "Copyright 2024, Paul Robello"
__credits__ = ["Paul Robello"]
__maintainer__ = "Paul Robello"
__email__ = "probello@gmail.com"
__version__ = "0.2.3"
__version__ = "0.2.4"
__licence__ = "MIT"
__application_title__ = "PAR LLAMA"
__application_binary__ = "parllama"
Expand Down
1 change: 0 additions & 1 deletion parllama/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""The main entry point for the application."""

from __future__ import annotations

import os
Expand Down
Loading

0 comments on commit efaa531

Please sign in to comment.