lupaxa-basic-cli-chatbot 0.1.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.
- lupaxa_basic_cli_chatbot-0.1.0/.gitignore +24 -0
- lupaxa_basic_cli_chatbot-0.1.0/LICENCE +21 -0
- lupaxa_basic_cli_chatbot-0.1.0/PKG-INFO +168 -0
- lupaxa_basic_cli_chatbot-0.1.0/README.md +106 -0
- lupaxa_basic_cli_chatbot-0.1.0/docs/README.md +23 -0
- lupaxa_basic_cli_chatbot-0.1.0/pyproject.toml +100 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/__init__.py +10 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/__main__.py +8 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/chat.py +71 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/cli.py +624 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/config.py +210 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/__init__.py +34 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/base.py +35 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/catalog.py +41 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/errors.py +21 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/gemini.py +131 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/grok.py +140 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/ollama.py +108 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/providers/openai.py +129 -0
- lupaxa_basic_cli_chatbot-0.1.0/src/lupaxa/basic_cli_chatbot/version.py +10 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# OS
|
|
2
|
+
.DS_Store
|
|
3
|
+
|
|
4
|
+
# Cursor
|
|
5
|
+
.cursor/
|
|
6
|
+
.superpowers/
|
|
7
|
+
.worktrees/
|
|
8
|
+
cursor-docs
|
|
9
|
+
|
|
10
|
+
# Make
|
|
11
|
+
.makefiles/
|
|
12
|
+
|
|
13
|
+
# MkDocs
|
|
14
|
+
site/
|
|
15
|
+
|
|
16
|
+
# Python
|
|
17
|
+
.venv/
|
|
18
|
+
__pycache__/
|
|
19
|
+
.mypy_cache/
|
|
20
|
+
.ruff_cache/
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
dist/
|
|
23
|
+
build/
|
|
24
|
+
*.egg-info/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) The Lupaxa Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lupaxa-basic-cli-chatbot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple command-line AI chatbot with conversation context.
|
|
5
|
+
Project-URL: Homepage, https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot
|
|
6
|
+
Project-URL: Documentation, https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot
|
|
7
|
+
Project-URL: Repository, https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot
|
|
8
|
+
Project-URL: Issues, https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot/issues
|
|
9
|
+
Author: The Lupaxa Project
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) The Lupaxa Project
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENCE
|
|
32
|
+
Keywords: chatbot,cli,openai
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
43
|
+
Classifier: Topic :: Utilities
|
|
44
|
+
Requires-Python: >=3.10
|
|
45
|
+
Requires-Dist: google-genai
|
|
46
|
+
Requires-Dist: httpx
|
|
47
|
+
Requires-Dist: ollama
|
|
48
|
+
Requires-Dist: openai>=2
|
|
49
|
+
Requires-Dist: pyyaml
|
|
50
|
+
Requires-Dist: xai-sdk
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: bump-my-version>=1.2.0; extra == 'dev'
|
|
53
|
+
Requires-Dist: hatch>=1.12.0; extra == 'dev'
|
|
54
|
+
Requires-Dist: mypy>=1.12.0; extra == 'dev'
|
|
55
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
56
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
57
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
58
|
+
Provides-Extra: test
|
|
59
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'test'
|
|
60
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
61
|
+
Description-Content-Type: text/markdown
|
|
62
|
+
|
|
63
|
+
<p align="center">
|
|
64
|
+
<a href="https://github.com/lupaxa-ai-toolbox">
|
|
65
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/ai-toolbox/readme-logo.png" alt="AI Toolbox" />
|
|
66
|
+
</a>
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
<h1 align="center">Basic CLI Chatbot</h1>
|
|
70
|
+
|
|
71
|
+
A command-line chatbot that talks to OpenAI, Gemini, Grok, or a local Ollama
|
|
72
|
+
server. A chat requires a provider and a model.
|
|
73
|
+
|
|
74
|
+
The PyPI name is `lupaxa-basic-cli-chatbot`. The console script is
|
|
75
|
+
`basic-cli-chatbot`.
|
|
76
|
+
|
|
77
|
+
## Install
|
|
78
|
+
|
|
79
|
+
Python 3.10 or newer. Set `OPENAI_API_KEY` for `--provider openai`,
|
|
80
|
+
`GEMINI_API_KEY` for `--provider gemini`, and `XAI_API_KEY` for
|
|
81
|
+
`--provider grok`. Ollama uses a local server and does not need those keys.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install lupaxa-basic-cli-chatbot
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Homebrew
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
brew tap the-lupaxa-project/tap
|
|
91
|
+
brew trust the-lupaxa-project/tap
|
|
92
|
+
brew install basic-cli-chatbot
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
A command with no question opens a prompt. A question after the flags asks
|
|
98
|
+
once and exits.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
basic-cli-chatbot --provider openai --model gpt-5.6-luna
|
|
102
|
+
basic-cli-chatbot --provider openai --model gpt-5.6-luna "What is 2+2?"
|
|
103
|
+
basic-cli-chatbot --provider ollama --model llama3.2
|
|
104
|
+
basic-cli-chatbot --provider grok --model grok-4.6
|
|
105
|
+
basic-cli-chatbot --list-models --provider ollama
|
|
106
|
+
basic-cli-chatbot --show-config --provider gemini
|
|
107
|
+
basic-cli-chatbot --version
|
|
108
|
+
basic-cli-chatbot --help
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`--provider` overrides `BASIC_CLI_CHATBOT_PROVIDER`. `--model` overrides
|
|
112
|
+
`BASIC_CLI_CHATBOT_MODEL`.
|
|
113
|
+
|
|
114
|
+
Ollama talks to a server at `http://localhost:11434`. That server has to be
|
|
115
|
+
running, and the model has to be installed already (`ollama pull llama3.2`).
|
|
116
|
+
|
|
117
|
+
A YAML profile file can supply the provider, the model, and the optional
|
|
118
|
+
chat settings. The default path is `$XDG_CONFIG_HOME/basic-cli-chatbot/config.yaml`,
|
|
119
|
+
or `~/.config/basic-cli-chatbot/config.yaml` when `XDG_CONFIG_HOME` is unset.
|
|
120
|
+
`--config` points at another file.
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
default:
|
|
124
|
+
provider: openai
|
|
125
|
+
model: gpt-5.6-luna
|
|
126
|
+
code-review:
|
|
127
|
+
provider: ollama
|
|
128
|
+
model: llama3.2
|
|
129
|
+
ollama-host: http://127.0.0.1:11434
|
|
130
|
+
timeout: 120
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`--profile code-review` uses that profile and cannot be combined with
|
|
134
|
+
`--provider` or `--model`. With neither of those flags and no `--profile`,
|
|
135
|
+
a `default` profile is used. `--ollama-host`, `--max-context-messages`,
|
|
136
|
+
`--timeout`, `--stream`, and `--no-stream` replace the profile value when
|
|
137
|
+
you pass them. `--validate` checks the file and exits. API keys stay in
|
|
138
|
+
the environment.
|
|
139
|
+
|
|
140
|
+
`--ollama-host` overrides `http://localhost:11434`.
|
|
141
|
+
|
|
142
|
+
`--max-context-messages` defaults to `0`, which keeps the whole
|
|
143
|
+
conversation.
|
|
144
|
+
|
|
145
|
+
Replies print as they arrive. `--no-stream` prints the reply in one piece.
|
|
146
|
+
|
|
147
|
+
The reply wait is 60 seconds for OpenAI, Gemini, and Grok, and 300 seconds
|
|
148
|
+
for Ollama. `--timeout` overrides that. `BASIC_CLI_CHATBOT_TIMEOUT` is used
|
|
149
|
+
only when `--timeout` is unset and the profile has no `timeout`.
|
|
150
|
+
|
|
151
|
+
`exit` and `quit` stop the prompt. `clear` drops the conversation.
|
|
152
|
+
`/context` prints how many messages are kept. `/provider` and `/model`
|
|
153
|
+
print the current names.
|
|
154
|
+
|
|
155
|
+
`--show-config` reports a key as `configured` or `not configured` and
|
|
156
|
+
does not print the secret.
|
|
157
|
+
|
|
158
|
+
## Development
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
make init
|
|
162
|
+
make python-install-dev
|
|
163
|
+
make python-check
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
<a href="https://github.com/the-lupaxa-project">
|
|
167
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
|
|
168
|
+
</a>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/lupaxa-ai-toolbox">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/ai-toolbox/readme-logo.png" alt="AI Toolbox" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">Basic CLI Chatbot</h1>
|
|
8
|
+
|
|
9
|
+
A command-line chatbot that talks to OpenAI, Gemini, Grok, or a local Ollama
|
|
10
|
+
server. A chat requires a provider and a model.
|
|
11
|
+
|
|
12
|
+
The PyPI name is `lupaxa-basic-cli-chatbot`. The console script is
|
|
13
|
+
`basic-cli-chatbot`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Python 3.10 or newer. Set `OPENAI_API_KEY` for `--provider openai`,
|
|
18
|
+
`GEMINI_API_KEY` for `--provider gemini`, and `XAI_API_KEY` for
|
|
19
|
+
`--provider grok`. Ollama uses a local server and does not need those keys.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install lupaxa-basic-cli-chatbot
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Homebrew
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
brew tap the-lupaxa-project/tap
|
|
29
|
+
brew trust the-lupaxa-project/tap
|
|
30
|
+
brew install basic-cli-chatbot
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
A command with no question opens a prompt. A question after the flags asks
|
|
36
|
+
once and exits.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
basic-cli-chatbot --provider openai --model gpt-5.6-luna
|
|
40
|
+
basic-cli-chatbot --provider openai --model gpt-5.6-luna "What is 2+2?"
|
|
41
|
+
basic-cli-chatbot --provider ollama --model llama3.2
|
|
42
|
+
basic-cli-chatbot --provider grok --model grok-4.6
|
|
43
|
+
basic-cli-chatbot --list-models --provider ollama
|
|
44
|
+
basic-cli-chatbot --show-config --provider gemini
|
|
45
|
+
basic-cli-chatbot --version
|
|
46
|
+
basic-cli-chatbot --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`--provider` overrides `BASIC_CLI_CHATBOT_PROVIDER`. `--model` overrides
|
|
50
|
+
`BASIC_CLI_CHATBOT_MODEL`.
|
|
51
|
+
|
|
52
|
+
Ollama talks to a server at `http://localhost:11434`. That server has to be
|
|
53
|
+
running, and the model has to be installed already (`ollama pull llama3.2`).
|
|
54
|
+
|
|
55
|
+
A YAML profile file can supply the provider, the model, and the optional
|
|
56
|
+
chat settings. The default path is `$XDG_CONFIG_HOME/basic-cli-chatbot/config.yaml`,
|
|
57
|
+
or `~/.config/basic-cli-chatbot/config.yaml` when `XDG_CONFIG_HOME` is unset.
|
|
58
|
+
`--config` points at another file.
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
default:
|
|
62
|
+
provider: openai
|
|
63
|
+
model: gpt-5.6-luna
|
|
64
|
+
code-review:
|
|
65
|
+
provider: ollama
|
|
66
|
+
model: llama3.2
|
|
67
|
+
ollama-host: http://127.0.0.1:11434
|
|
68
|
+
timeout: 120
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`--profile code-review` uses that profile and cannot be combined with
|
|
72
|
+
`--provider` or `--model`. With neither of those flags and no `--profile`,
|
|
73
|
+
a `default` profile is used. `--ollama-host`, `--max-context-messages`,
|
|
74
|
+
`--timeout`, `--stream`, and `--no-stream` replace the profile value when
|
|
75
|
+
you pass them. `--validate` checks the file and exits. API keys stay in
|
|
76
|
+
the environment.
|
|
77
|
+
|
|
78
|
+
`--ollama-host` overrides `http://localhost:11434`.
|
|
79
|
+
|
|
80
|
+
`--max-context-messages` defaults to `0`, which keeps the whole
|
|
81
|
+
conversation.
|
|
82
|
+
|
|
83
|
+
Replies print as they arrive. `--no-stream` prints the reply in one piece.
|
|
84
|
+
|
|
85
|
+
The reply wait is 60 seconds for OpenAI, Gemini, and Grok, and 300 seconds
|
|
86
|
+
for Ollama. `--timeout` overrides that. `BASIC_CLI_CHATBOT_TIMEOUT` is used
|
|
87
|
+
only when `--timeout` is unset and the profile has no `timeout`.
|
|
88
|
+
|
|
89
|
+
`exit` and `quit` stop the prompt. `clear` drops the conversation.
|
|
90
|
+
`/context` prints how many messages are kept. `/provider` and `/model`
|
|
91
|
+
print the current names.
|
|
92
|
+
|
|
93
|
+
`--show-config` reports a key as `configured` or `not configured` and
|
|
94
|
+
does not print the secret.
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
make init
|
|
100
|
+
make python-install-dev
|
|
101
|
+
make python-check
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
<a href="https://github.com/the-lupaxa-project">
|
|
105
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
|
|
106
|
+
</a>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/lupaxa-ai-toolbox">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/ai-toolbox/readme-logo.png" alt="Organisation Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">Core Documentation</h1>
|
|
8
|
+
|
|
9
|
+
The following documents define the standards that apply across **The Lupaxa Project**:
|
|
10
|
+
|
|
11
|
+
| Document | Purpose |
|
|
12
|
+
| :------------------------------------ | :---------------------------------------------------------------- |
|
|
13
|
+
| [Code of Conduct](CODE_OF_CONDUCT.md) | Expected behaviour and reporting procedures. |
|
|
14
|
+
| [How to Contribute](CONTRIBUTING.md) | Development workflow, coding standards, and contribution process. |
|
|
15
|
+
| [Governance](GOVERNANCE.md) | Project governance, roles, and decision-making. |
|
|
16
|
+
| [Maintainers](MAINTAINERS.md) | Maintainer responsibilities and expectations. |
|
|
17
|
+
| [Projects Overview](PROJECTS.md) | Overview of organisations, repositories, and project structure. |
|
|
18
|
+
| [Security Policy](SECURITY.md) | Responsible disclosure and secure development practices. |
|
|
19
|
+
| [Support Guide](SUPPORT.md) | How to obtain help and support. |
|
|
20
|
+
|
|
21
|
+
<a href="https://github.com/the-lupaxa-project">
|
|
22
|
+
<img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
|
|
23
|
+
</a>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.18"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lupaxa-basic-cli-chatbot"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A simple command-line AI chatbot with conversation context."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENCE" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "The Lupaxa Project" }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
keywords = ["chatbot", "cli", "openai"]
|
|
18
|
+
|
|
19
|
+
dependencies = [
|
|
20
|
+
"google-genai",
|
|
21
|
+
"httpx",
|
|
22
|
+
"ollama",
|
|
23
|
+
"openai>=2",
|
|
24
|
+
"PyYAML",
|
|
25
|
+
"xai-sdk",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Environment :: Console",
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"License :: OSI Approved :: MIT License",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
"Programming Language :: Python :: 3",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Topic :: Utilities",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot"
|
|
44
|
+
Documentation = "https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot"
|
|
45
|
+
Repository = "https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot"
|
|
46
|
+
Issues = "https://github.com/lupaxa-ai-toolbox/basic-cli-chatbot/issues"
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
basic-cli-chatbot = "lupaxa.basic_cli_chatbot.cli:main"
|
|
50
|
+
|
|
51
|
+
[project.optional-dependencies]
|
|
52
|
+
dev = [
|
|
53
|
+
"pytest>=8.0",
|
|
54
|
+
"pytest-cov>=5.0",
|
|
55
|
+
"ruff>=0.6.0",
|
|
56
|
+
"mypy>=1.12.0",
|
|
57
|
+
"hatch>=1.12.0",
|
|
58
|
+
"bump-my-version>=1.2.0",
|
|
59
|
+
]
|
|
60
|
+
test = [
|
|
61
|
+
"pytest>=8.0",
|
|
62
|
+
"pytest-cov>=5.0",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[tool.hatch.version]
|
|
66
|
+
path = "src/lupaxa/basic_cli_chatbot/version.py"
|
|
67
|
+
|
|
68
|
+
[tool.hatch.build.targets.sdist]
|
|
69
|
+
include = [
|
|
70
|
+
"src/**",
|
|
71
|
+
"README.md",
|
|
72
|
+
"LICENCE",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[tool.hatch.build.targets.wheel]
|
|
76
|
+
packages = ["src/lupaxa"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff]
|
|
79
|
+
line-length = 100
|
|
80
|
+
target-version = "py310"
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint]
|
|
83
|
+
select = ["E", "F", "I", "B", "UP", "SIM"]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.format]
|
|
86
|
+
quote-style = "double"
|
|
87
|
+
|
|
88
|
+
[tool.mypy]
|
|
89
|
+
python_version = "3.10"
|
|
90
|
+
files = ["src", "tests"]
|
|
91
|
+
mypy_path = "src"
|
|
92
|
+
explicit_package_bases = true
|
|
93
|
+
namespace_packages = true
|
|
94
|
+
warn_unused_configs = true
|
|
95
|
+
ignore_missing_imports = true
|
|
96
|
+
|
|
97
|
+
[tool.pytest.ini_options]
|
|
98
|
+
addopts = "-ra -q --disable-warnings"
|
|
99
|
+
testpaths = ["tests"]
|
|
100
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Conversation history helper. Not part of the public package API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .providers.base import Provider
|
|
6
|
+
|
|
7
|
+
SYSTEM_PROMPT = (
|
|
8
|
+
"You are a helpful general-purpose assistant. Answer questions clearly and concisely."
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def trim(conversation: list[dict[str, str]], max_context_messages: int) -> None:
|
|
13
|
+
"""Drop oldest complete user/assistant pairs until the list fits.
|
|
14
|
+
|
|
15
|
+
``0`` means unlimited. An odd cap uses the next lower even number.
|
|
16
|
+
A trailing user row with no assistant reply is kept.
|
|
17
|
+
"""
|
|
18
|
+
if max_context_messages == 0:
|
|
19
|
+
return
|
|
20
|
+
limit = max_context_messages - (max_context_messages % 2)
|
|
21
|
+
while len(conversation) > limit:
|
|
22
|
+
complete_pair = (
|
|
23
|
+
len(conversation) >= 2
|
|
24
|
+
and conversation[0].get("role") == "user"
|
|
25
|
+
and conversation[1].get("role") == "assistant"
|
|
26
|
+
)
|
|
27
|
+
if not complete_pair:
|
|
28
|
+
break
|
|
29
|
+
if conversation[-1].get("role") == "user" and len(conversation) < 3:
|
|
30
|
+
break
|
|
31
|
+
del conversation[:2]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def begin_turn(
|
|
35
|
+
question: str,
|
|
36
|
+
conversation: list[dict[str, str]],
|
|
37
|
+
max_context_messages: int,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Append the user row, then trim."""
|
|
40
|
+
conversation.append({"role": "user", "content": question})
|
|
41
|
+
trim(conversation, max_context_messages)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def finish_turn(conversation: list[dict[str, str]], answer: str) -> None:
|
|
45
|
+
"""Append the assistant row."""
|
|
46
|
+
conversation.append({"role": "assistant", "content": answer})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def fail_turn(conversation: list[dict[str, str]]) -> None:
|
|
50
|
+
"""Remove the trailing user row after a failed request."""
|
|
51
|
+
if conversation and conversation[-1].get("role") == "user":
|
|
52
|
+
conversation.pop()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ask(
|
|
56
|
+
question: str,
|
|
57
|
+
conversation: list[dict[str, str]],
|
|
58
|
+
provider: Provider,
|
|
59
|
+
model: str,
|
|
60
|
+
*,
|
|
61
|
+
max_context_messages: int,
|
|
62
|
+
) -> str:
|
|
63
|
+
"""Append one user turn, request a reply, and append that reply."""
|
|
64
|
+
begin_turn(question, conversation, max_context_messages)
|
|
65
|
+
try:
|
|
66
|
+
answer = provider.chat(list(conversation), model, SYSTEM_PROMPT)
|
|
67
|
+
except Exception:
|
|
68
|
+
fail_turn(conversation)
|
|
69
|
+
raise
|
|
70
|
+
finish_turn(conversation, answer)
|
|
71
|
+
return answer
|