charla 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- charla-1.0.0/.github/FUNDING.yml +4 -0
- charla-1.0.0/.github/workflows/test.yml +42 -0
- charla-1.0.0/.gitignore +165 -0
- charla-1.0.0/LICENSE.txt +9 -0
- charla-1.0.0/PKG-INFO +75 -0
- charla-1.0.0/README.md +51 -0
- charla-1.0.0/charla/__about__.py +5 -0
- charla-1.0.0/charla/__init__.py +3 -0
- charla-1.0.0/charla/chat.py +74 -0
- charla-1.0.0/charla/cli.py +59 -0
- charla-1.0.0/charla/config.py +17 -0
- charla-1.0.0/pyproject.toml +74 -0
- charla-1.0.0/tests/__init__.py +3 -0
- charla-1.0.0/tests/test_chat.py +12 -0
- charla-1.0.0/todo.md +4 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: test-${{ github.head_ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
env:
|
|
14
|
+
PYTHONUNBUFFERED: "1"
|
|
15
|
+
FORCE_COLOR: "1"
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
run:
|
|
19
|
+
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
|
|
20
|
+
runs-on: ${{ matrix.os }}
|
|
21
|
+
strategy:
|
|
22
|
+
fail-fast: false
|
|
23
|
+
matrix:
|
|
24
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
25
|
+
python-version: ['3.10', '3.11', '3.12']
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
|
|
30
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
31
|
+
uses: actions/setup-python@v4
|
|
32
|
+
with:
|
|
33
|
+
python-version: ${{ matrix.python-version }}
|
|
34
|
+
|
|
35
|
+
- name: Install Hatch
|
|
36
|
+
run: pip install --upgrade hatch
|
|
37
|
+
|
|
38
|
+
- name: Run static analysis
|
|
39
|
+
run: hatch fmt --check
|
|
40
|
+
|
|
41
|
+
- name: Run tests
|
|
42
|
+
run: hatch test --python ${{ matrix.python-version }} --cover --randomize --parallel --retries 2 --retry-delay 1
|
charla-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
chat-history/
|
|
2
|
+
experimental/
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# poetry
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
105
|
+
#poetry.lock
|
|
106
|
+
|
|
107
|
+
# pdm
|
|
108
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
109
|
+
#pdm.lock
|
|
110
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
111
|
+
# in version control.
|
|
112
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
113
|
+
.pdm.toml
|
|
114
|
+
.pdm-python
|
|
115
|
+
.pdm-build/
|
|
116
|
+
|
|
117
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
118
|
+
__pypackages__/
|
|
119
|
+
|
|
120
|
+
# Celery stuff
|
|
121
|
+
celerybeat-schedule
|
|
122
|
+
celerybeat.pid
|
|
123
|
+
|
|
124
|
+
# SageMath parsed files
|
|
125
|
+
*.sage.py
|
|
126
|
+
|
|
127
|
+
# Environments
|
|
128
|
+
.env
|
|
129
|
+
.venv
|
|
130
|
+
env/
|
|
131
|
+
venv/
|
|
132
|
+
ENV/
|
|
133
|
+
env.bak/
|
|
134
|
+
venv.bak/
|
|
135
|
+
|
|
136
|
+
# Spyder project settings
|
|
137
|
+
.spyderproject
|
|
138
|
+
.spyproject
|
|
139
|
+
|
|
140
|
+
# Rope project settings
|
|
141
|
+
.ropeproject
|
|
142
|
+
|
|
143
|
+
# mkdocs documentation
|
|
144
|
+
/site
|
|
145
|
+
|
|
146
|
+
# mypy
|
|
147
|
+
.mypy_cache/
|
|
148
|
+
.dmypy.json
|
|
149
|
+
dmypy.json
|
|
150
|
+
|
|
151
|
+
# Pyre type checker
|
|
152
|
+
.pyre/
|
|
153
|
+
|
|
154
|
+
# pytype static type analyzer
|
|
155
|
+
.pytype/
|
|
156
|
+
|
|
157
|
+
# Cython debug symbols
|
|
158
|
+
cython_debug/
|
|
159
|
+
|
|
160
|
+
# PyCharm
|
|
161
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
162
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
163
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
164
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
165
|
+
#.idea/
|
charla-1.0.0/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Ramiro Gómez <code@ramiro.org>
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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.
|
charla-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: charla
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A terminal based chat application that works with local language models.
|
|
5
|
+
Project-URL: Documentation, https://github.com/yaph/charla#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/yaph/charla/issues
|
|
7
|
+
Project-URL: Source, https://github.com/yaph/charla
|
|
8
|
+
Author-email: Ramiro Gómez <code@ramiro.org>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Keywords: chat-client,chatbot,cli,llm,ollama,terminal
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: ollama
|
|
21
|
+
Requires-Dist: platformdirs
|
|
22
|
+
Requires-Dist: prompt-toolkit
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Charla: Terminal-Based Chat Application with Ollama Backend Integration
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/charla)
|
|
28
|
+
[](https://pypi.org/project/charla)
|
|
29
|
+
|
|
30
|
+
**Charla** is a terminal based chat application that integrates with [Ollama](https://ollama.com/), a backend designed to serve language models. To use Charla, ensure that the `ollama` server is running and at least one language model is installed.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install Charla using `pipx`:
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
pipx install charla
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Launch the chat console by typing `charla` in your terminal, or view all available command line options with `charla -h`.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
* Terminal-based chat system that supports context aware conversations using local language models.
|
|
47
|
+
* Chat sessions are saved as markdown files in the user's documents directory when ending a chat.
|
|
48
|
+
* Prompt history is saved and previously entered prompts are auto-suggested.
|
|
49
|
+
* Mode switching between single-line and multi-line input without interruption to your chat session.
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
Run the command-line interface directly from the project source without installing the package:
|
|
54
|
+
|
|
55
|
+
```console
|
|
56
|
+
python -m charla.cli
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### ollama API
|
|
60
|
+
|
|
61
|
+
Installed models:
|
|
62
|
+
|
|
63
|
+
```console
|
|
64
|
+
curl http://localhost:11434/api/tags
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Model info:
|
|
68
|
+
|
|
69
|
+
```console
|
|
70
|
+
curl http://localhost:11434/api/show -d '{"name": "phi3"}'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
Charla is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
charla-1.0.0/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Charla: Terminal-Based Chat Application with Ollama Backend Integration
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/charla)
|
|
4
|
+
[](https://pypi.org/project/charla)
|
|
5
|
+
|
|
6
|
+
**Charla** is a terminal based chat application that integrates with [Ollama](https://ollama.com/), a backend designed to serve language models. To use Charla, ensure that the `ollama` server is running and at least one language model is installed.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Install Charla using `pipx`:
|
|
11
|
+
|
|
12
|
+
```console
|
|
13
|
+
pipx install charla
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Launch the chat console by typing `charla` in your terminal, or view all available command line options with `charla -h`.
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
* Terminal-based chat system that supports context aware conversations using local language models.
|
|
23
|
+
* Chat sessions are saved as markdown files in the user's documents directory when ending a chat.
|
|
24
|
+
* Prompt history is saved and previously entered prompts are auto-suggested.
|
|
25
|
+
* Mode switching between single-line and multi-line input without interruption to your chat session.
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
Run the command-line interface directly from the project source without installing the package:
|
|
30
|
+
|
|
31
|
+
```console
|
|
32
|
+
python -m charla.cli
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### ollama API
|
|
36
|
+
|
|
37
|
+
Installed models:
|
|
38
|
+
|
|
39
|
+
```console
|
|
40
|
+
curl http://localhost:11434/api/tags
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Model info:
|
|
44
|
+
|
|
45
|
+
```console
|
|
46
|
+
curl http://localhost:11434/api/show -d '{"name": "phi3"}'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
Charla is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from operator import itemgetter
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from prompt_toolkit import PromptSession
|
|
7
|
+
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|
8
|
+
from prompt_toolkit.history import FileHistory
|
|
9
|
+
from prompt_toolkit.key_binding import KeyBindings
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
import ollama
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# UI text
|
|
17
|
+
t_prompt = 'PROMPT: '
|
|
18
|
+
t_prompt_ml = 'PROMPT \N{LATIN SUBSCRIPT SMALL LETTER M}\N{LATIN SUBSCRIPT SMALL LETTER L}: '
|
|
19
|
+
t_response = 'RESPONSE:'
|
|
20
|
+
t_help = '''
|
|
21
|
+
Press CTRL-C or CTRL-D to exit chat.
|
|
22
|
+
Press ALT+M to switch between single and multi line mode.
|
|
23
|
+
Press ALT+RETURN to send prompt in multi line mode.
|
|
24
|
+
Press ↑ and ↓ to navigate previously entered prompts.
|
|
25
|
+
Press → to complete an auto suggested prompt.
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
def available_models() -> None | list[str]:
|
|
29
|
+
"""Return available models sorted by size."""
|
|
30
|
+
|
|
31
|
+
if model_list := ollama.list()['models']:
|
|
32
|
+
return [m for m in sorted(model_list, key=itemgetter('size'))]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def generate(model: str, prompt: str, context: list, output: list) -> str | Any:
|
|
36
|
+
stream = ollama.generate(model=model, prompt=prompt, context=context, stream=True)
|
|
37
|
+
|
|
38
|
+
text = ''
|
|
39
|
+
for chunk in stream:
|
|
40
|
+
if not chunk['done']:
|
|
41
|
+
text += chunk['response']
|
|
42
|
+
print(chunk['response'], end='', flush=True)
|
|
43
|
+
|
|
44
|
+
output.append(f'{t_response}\n\n{text}\n')
|
|
45
|
+
return chunk['context']
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def prompt_session(history: Path) -> PromptSession:
|
|
49
|
+
session = PromptSession(message=t_prompt,
|
|
50
|
+
history=FileHistory(history),
|
|
51
|
+
auto_suggest=AutoSuggestFromHistory())
|
|
52
|
+
|
|
53
|
+
print(t_help)
|
|
54
|
+
|
|
55
|
+
bindings = KeyBindings()
|
|
56
|
+
|
|
57
|
+
@bindings.add('escape', 'm')
|
|
58
|
+
def switch_multiline(event):
|
|
59
|
+
session.multiline = not session.multiline
|
|
60
|
+
session.message = t_prompt if session.multiline is False else t_prompt_ml
|
|
61
|
+
|
|
62
|
+
session.key_bindings = bindings
|
|
63
|
+
|
|
64
|
+
return session
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def save(chats_path: Path, output: list[str], model_name: str) -> None:
|
|
68
|
+
if len(output) > 1:
|
|
69
|
+
now = datetime.strftime(datetime.now(), '%Y-%m-%d-%H-%M-%S')
|
|
70
|
+
slug = re.sub(r'\W', '-', model_name)
|
|
71
|
+
file = chats_path / f'{now}-{slug}.md'
|
|
72
|
+
|
|
73
|
+
print(f'Saving chat in: {file}')
|
|
74
|
+
file.write_text('\n'.join(output))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import argparse
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from prompt_toolkit import HTML, print_formatted_text as print_fmt
|
|
8
|
+
|
|
9
|
+
from charla import chat, config
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
if (models := chat.available_models()) is None:
|
|
14
|
+
sys.exit('No language models available.')
|
|
15
|
+
model_names = [m['name'] for m in models]
|
|
16
|
+
|
|
17
|
+
parser = argparse.ArgumentParser(description='Chat with local language models.')
|
|
18
|
+
parser.add_argument('--model', '-m',
|
|
19
|
+
choices=model_names,
|
|
20
|
+
help='Language model to chat with.')
|
|
21
|
+
argv = parser.parse_args()
|
|
22
|
+
|
|
23
|
+
# Determine model
|
|
24
|
+
if (model := config.setting('model', argv.model)) == '':
|
|
25
|
+
model = model_names[0]
|
|
26
|
+
|
|
27
|
+
context = [] # Store conversation history to make the model context aware
|
|
28
|
+
output = [f'# Chat with: {model}\n'] # List to store output text
|
|
29
|
+
|
|
30
|
+
history = Path(config.setting('prompt_history'))
|
|
31
|
+
history.parent.mkdir(exist_ok=True, parents=True)
|
|
32
|
+
session = chat.prompt_session(history)
|
|
33
|
+
|
|
34
|
+
print_fmt('Chat with:', HTML(f'<ansigreen>{model}</ansigreen>'), '\n')
|
|
35
|
+
|
|
36
|
+
while True:
|
|
37
|
+
try:
|
|
38
|
+
user_input = session.prompt()
|
|
39
|
+
if not user_input:
|
|
40
|
+
continue
|
|
41
|
+
|
|
42
|
+
output.append(f'{chat.t_prompt}{user_input}\n')
|
|
43
|
+
print(f'\n{chat.t_response}\n')
|
|
44
|
+
context = chat.generate(model, user_input, context, output)
|
|
45
|
+
print('\n')
|
|
46
|
+
# Exit program on CTRL-C and CTRL-D
|
|
47
|
+
except (KeyboardInterrupt, EOFError):
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
chats_path = Path(config.setting('chats_path'))
|
|
51
|
+
chats_path.mkdir(exist_ok=True, parents=True)
|
|
52
|
+
chat.save(chats_path, output, model)
|
|
53
|
+
|
|
54
|
+
print_fmt(HTML('<b>Exiting program.</b>'))
|
|
55
|
+
sys.exit()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == '__main__':
|
|
59
|
+
main()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from platformdirs import user_cache_dir, user_documents_dir
|
|
2
|
+
|
|
3
|
+
from charla import __about__
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
name = __about__.__name__
|
|
7
|
+
|
|
8
|
+
default_settings = {
|
|
9
|
+
'model': '',
|
|
10
|
+
'chats_path': user_documents_dir() + f'/{name}/chats',
|
|
11
|
+
'prompt_history': user_cache_dir(appname=name) + '/prompt-history.txt'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def setting(key: str, value: str = None) -> str:
|
|
16
|
+
return value if value else default_settings.get(key)
|
|
17
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "charla"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = 'A terminal based chat application that works with local language models.'
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = ["chat-client", "cli", "llm", "chatbot", "ollama", "terminal"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Ramiro Gómez", email = "code@ramiro.org" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"ollama",
|
|
27
|
+
"platformdirs",
|
|
28
|
+
"prompt_toolkit"
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
charla = "charla.cli:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Documentation = "https://github.com/yaph/charla#readme"
|
|
36
|
+
Issues = "https://github.com/yaph/charla/issues"
|
|
37
|
+
Source = "https://github.com/yaph/charla"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.version]
|
|
40
|
+
path = "charla/__about__.py"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.envs.dev]
|
|
43
|
+
extra-dependencies = ["flake8", "ipdb", "mypy>=1.0.0"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.envs.dev.scripts]
|
|
46
|
+
type_check = "mypy --install-types --non-interactive {args:charla tests}"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.envs.pub.scripts]
|
|
49
|
+
release = [
|
|
50
|
+
"hatch test",
|
|
51
|
+
"hatch build --clean",
|
|
52
|
+
"hatch publish -u __token__",
|
|
53
|
+
"git tag -a $(hatch version) -m \"Create version $(hatch version)\"",
|
|
54
|
+
"git push --tags"
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.coverage.run]
|
|
58
|
+
source_pkgs = ["charla", "tests"]
|
|
59
|
+
branch = true
|
|
60
|
+
parallel = true
|
|
61
|
+
omit = [
|
|
62
|
+
"charla/__about__.py",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[tool.coverage.paths]
|
|
66
|
+
charla = ["charla", "*/charla/charla"]
|
|
67
|
+
tests = ["tests", "*/charla/tests"]
|
|
68
|
+
|
|
69
|
+
[tool.coverage.report]
|
|
70
|
+
exclude_lines = [
|
|
71
|
+
"no cov",
|
|
72
|
+
"if __name__ == .__main__.:",
|
|
73
|
+
"if TYPE_CHECKING:",
|
|
74
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from charla import chat
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_available_models():
|
|
5
|
+
models = chat.available_models()
|
|
6
|
+
assert len(models)
|
|
7
|
+
assert 'name' in models[0]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_prompt_session():
|
|
11
|
+
session = chat.prompt_session('cache/prompt-history.txt')
|
|
12
|
+
assert session.message == chat.t_prompt
|
charla-1.0.0/todo.md
ADDED