kryten-llm 0.2.2__py3-none-any.whl
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.
- kryten_llm/__init__.py +22 -0
- kryten_llm/__main__.py +148 -0
- kryten_llm/components/__init__.py +24 -0
- kryten_llm/components/config_reloader.py +286 -0
- kryten_llm/components/context_manager.py +186 -0
- kryten_llm/components/formatter.py +383 -0
- kryten_llm/components/health_monitor.py +266 -0
- kryten_llm/components/heartbeat.py +122 -0
- kryten_llm/components/listener.py +79 -0
- kryten_llm/components/llm_manager.py +349 -0
- kryten_llm/components/prompt_builder.py +148 -0
- kryten_llm/components/rate_limiter.py +478 -0
- kryten_llm/components/response_logger.py +105 -0
- kryten_llm/components/spam_detector.py +388 -0
- kryten_llm/components/trigger_engine.py +278 -0
- kryten_llm/components/validator.py +269 -0
- kryten_llm/config.py +93 -0
- kryten_llm/models/__init__.py +25 -0
- kryten_llm/models/config.py +496 -0
- kryten_llm/models/events.py +16 -0
- kryten_llm/models/phase3.py +59 -0
- kryten_llm/service.py +572 -0
- kryten_llm/utils/__init__.py +0 -0
- kryten_llm-0.2.2.dist-info/METADATA +271 -0
- kryten_llm-0.2.2.dist-info/RECORD +28 -0
- kryten_llm-0.2.2.dist-info/WHEEL +4 -0
- kryten_llm-0.2.2.dist-info/entry_points.txt +3 -0
- kryten_llm-0.2.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kryten-llm
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Kryten LLM integration service - provides AI chat responses and interactions
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: cytube,moderation,chat,nats,microservices
|
|
8
|
+
Author: Kryten Robot Team
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
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 :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Communications :: Chat
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Dist: aiohttp (>=3.13.2,<4.0.0)
|
|
22
|
+
Requires-Dist: emoji (>=2.15.0,<3.0.0)
|
|
23
|
+
Requires-Dist: kryten-py (>=0.9.4)
|
|
24
|
+
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
25
|
+
Requires-Dist: pydantic-settings (>=2.12.0,<3.0.0)
|
|
26
|
+
Project-URL: Documentation, https://github.com/grobertson/kryten-llm/blob/main/README.md
|
|
27
|
+
Project-URL: Homepage, https://github.com/grobertson/kryten-llm
|
|
28
|
+
Project-URL: Repository, https://github.com/grobertson/kryten-llm
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Kryten LLM
|
|
32
|
+
|
|
33
|
+
AI-powered chat bot service for CyTube, part of the Kryten ecosystem.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Trigger-Based Responses**: Configurable trigger words with probabilities
|
|
38
|
+
- **Direct Mentions**: Responds when mentioned by name
|
|
39
|
+
- **LLM Integration**: Multiple LLM provider support (OpenAI, OpenRouter, local)
|
|
40
|
+
- **Rate Limiting**: Per-user, per-trigger, and global rate limits
|
|
41
|
+
- **Spam Detection**: Automatic spam detection with exponential backoff penalties
|
|
42
|
+
- **Context Awareness**: Tracks chat history and video context
|
|
43
|
+
- **Hot-Reload**: Reload configuration without restart (SIGHUP)
|
|
44
|
+
- **Service Discovery**: Publishes heartbeats and responds to discovery polls
|
|
45
|
+
- **Dry-Run Mode**: Test responses without sending to chat
|
|
46
|
+
|
|
47
|
+
## Requirements
|
|
48
|
+
|
|
49
|
+
- Python 3.10+
|
|
50
|
+
- Poetry
|
|
51
|
+
- NATS server
|
|
52
|
+
- kryten-py library
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
### Using Poetry
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Install dependencies
|
|
60
|
+
poetry install
|
|
61
|
+
|
|
62
|
+
# Copy example configuration
|
|
63
|
+
cp config.example.json config.json
|
|
64
|
+
|
|
65
|
+
# Edit configuration with your settings
|
|
66
|
+
# See config.example.json for all options
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Using pip
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install kryten-llm
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
Configuration is stored in a JSON file. See `config.example.json` for a complete example.
|
|
78
|
+
|
|
79
|
+
### Key Sections
|
|
80
|
+
|
|
81
|
+
| Section | Description |
|
|
82
|
+
|---------|-------------|
|
|
83
|
+
| `nats` | NATS connection settings |
|
|
84
|
+
| `channels` | CyTube channel connections |
|
|
85
|
+
| `personality` | Bot character and behavior |
|
|
86
|
+
| `llm_providers` | LLM API configurations |
|
|
87
|
+
| `triggers` | Trigger words with patterns and probabilities |
|
|
88
|
+
| `rate_limits` | Rate limiting rules |
|
|
89
|
+
| `spam_detection` | Spam detection settings |
|
|
90
|
+
| `testing` | Dry-run and logging options |
|
|
91
|
+
|
|
92
|
+
### Environment Variables
|
|
93
|
+
|
|
94
|
+
Override configuration with environment variables:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export OPENROUTER_API_KEY="your-api-key"
|
|
98
|
+
export KRYTEN_LLM_DRY_RUN="true"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Usage
|
|
102
|
+
|
|
103
|
+
### Running the Service
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Using Poetry
|
|
107
|
+
poetry run kryten-llm --config config.json
|
|
108
|
+
|
|
109
|
+
# Direct Python execution
|
|
110
|
+
python -m kryten_llm --config config.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Command Line Options
|
|
114
|
+
|
|
115
|
+
| Option | Description |
|
|
116
|
+
|--------|-------------|
|
|
117
|
+
| `--config PATH` | Path to configuration file (default: `config.json`) |
|
|
118
|
+
| `--log-level LEVEL` | Logging level: DEBUG, INFO, WARNING, ERROR |
|
|
119
|
+
| `--dry-run` | Generate responses but don't send to chat |
|
|
120
|
+
| `--validate-config` | Validate configuration and exit |
|
|
121
|
+
|
|
122
|
+
### Validation Mode
|
|
123
|
+
|
|
124
|
+
Validate your configuration without starting the service:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
poetry run kryten-llm --config config.json --validate-config
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Dry-Run Mode
|
|
131
|
+
|
|
132
|
+
Test responses without sending to chat:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
poetry run kryten-llm --config config.json --dry-run
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Hot-Reload (POSIX)
|
|
139
|
+
|
|
140
|
+
Reload configuration without restarting the service:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Send SIGHUP to reload configuration
|
|
144
|
+
kill -HUP $(pgrep -f kryten_llm)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Safe changes that can be hot-reloaded:
|
|
148
|
+
- Triggers (patterns, probabilities, enabled status)
|
|
149
|
+
- Rate limits
|
|
150
|
+
- Spam detection settings
|
|
151
|
+
- Personality configuration
|
|
152
|
+
- LLM provider settings
|
|
153
|
+
|
|
154
|
+
Unsafe changes (require restart):
|
|
155
|
+
- NATS connection settings
|
|
156
|
+
- Channel configuration
|
|
157
|
+
- Service name
|
|
158
|
+
|
|
159
|
+
## Production Deployment
|
|
160
|
+
|
|
161
|
+
### Systemd Service
|
|
162
|
+
|
|
163
|
+
Install the systemd service file:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Copy service file
|
|
167
|
+
sudo cp kryten-llm.service /etc/systemd/system/
|
|
168
|
+
|
|
169
|
+
# Create config directory
|
|
170
|
+
sudo mkdir -p /etc/kryten-llm
|
|
171
|
+
sudo cp config.json /etc/kryten-llm/
|
|
172
|
+
|
|
173
|
+
# Create log directory
|
|
174
|
+
sudo mkdir -p /var/log/kryten-llm
|
|
175
|
+
sudo chown kryten:kryten /var/log/kryten-llm
|
|
176
|
+
|
|
177
|
+
# Enable and start service
|
|
178
|
+
sudo systemctl daemon-reload
|
|
179
|
+
sudo systemctl enable kryten-llm
|
|
180
|
+
sudo systemctl start kryten-llm
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Service Management
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Check status
|
|
187
|
+
sudo systemctl status kryten-llm
|
|
188
|
+
|
|
189
|
+
# View logs
|
|
190
|
+
sudo journalctl -u kryten-llm -f
|
|
191
|
+
|
|
192
|
+
# Reload configuration
|
|
193
|
+
sudo systemctl reload kryten-llm
|
|
194
|
+
|
|
195
|
+
# Restart service
|
|
196
|
+
sudo systemctl restart kryten-llm
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
### Running Tests
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Run all tests
|
|
205
|
+
poetry run pytest
|
|
206
|
+
|
|
207
|
+
# Run with coverage
|
|
208
|
+
poetry run pytest --cov=kryten_llm
|
|
209
|
+
|
|
210
|
+
# Run specific test file
|
|
211
|
+
poetry run pytest tests/test_trigger_engine.py -v
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Code Quality
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Linting
|
|
218
|
+
poetry run ruff check .
|
|
219
|
+
|
|
220
|
+
# Formatting
|
|
221
|
+
poetry run black .
|
|
222
|
+
|
|
223
|
+
# Type checking
|
|
224
|
+
poetry run mypy kryten_llm
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Architecture
|
|
228
|
+
|
|
229
|
+
The service processes messages through a pipeline:
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
Chat Message
|
|
233
|
+
↓
|
|
234
|
+
MessageListener (parse/filter)
|
|
235
|
+
↓
|
|
236
|
+
TriggerEngine (detect triggers/mentions)
|
|
237
|
+
↓
|
|
238
|
+
RateLimiter (check rate limits)
|
|
239
|
+
↓
|
|
240
|
+
SpamDetector (check spam)
|
|
241
|
+
↓
|
|
242
|
+
ContextManager (gather context)
|
|
243
|
+
↓
|
|
244
|
+
PromptBuilder (build LLM prompt)
|
|
245
|
+
↓
|
|
246
|
+
LLMManager (call LLM API)
|
|
247
|
+
↓
|
|
248
|
+
ResponseValidator (validate response)
|
|
249
|
+
↓
|
|
250
|
+
ResponseFormatter (format for chat)
|
|
251
|
+
↓
|
|
252
|
+
Send to Chat
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Service Discovery
|
|
256
|
+
|
|
257
|
+
The service publishes:
|
|
258
|
+
|
|
259
|
+
- **Startup event**: When service starts
|
|
260
|
+
- **Heartbeat**: Every 30s with health status
|
|
261
|
+
- **Shutdown event**: When service stops gracefully
|
|
262
|
+
|
|
263
|
+
Subscribe to service events:
|
|
264
|
+
- `kryten.lifecycle.llm.startup`
|
|
265
|
+
- `kryten.heartbeat.llm`
|
|
266
|
+
- `kryten.lifecycle.llm.shutdown`
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
271
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
kryten_llm/__init__.py,sha256=d9mOIXiZjLOIdUmq5JQV2We6YQG1k-PqkwjeeeFayAs,565
|
|
2
|
+
kryten_llm/__main__.py,sha256=xXCE70ZpcVcIBJQYDkblyPKZSo5gAolhPf-G6W7a8m8,4711
|
|
3
|
+
kryten_llm/components/__init__.py,sha256=_f77534WF7_FQEJ5S4kwTzGECjL1xKzrlUPT_80FR0I,896
|
|
4
|
+
kryten_llm/components/config_reloader.py,sha256=CZCD1FmWD03VUYL12HLaFR3rLYtacttgc1YDfwYI8yY,10671
|
|
5
|
+
kryten_llm/components/context_manager.py,sha256=8AOeh0qTW8W3LYoTjIc_6OzfoZ7Eew9AAf-9mk1fwPg,7001
|
|
6
|
+
kryten_llm/components/formatter.py,sha256=6Z455HvfMK1hiMdsiw2bq2Yx9N6MElZ_mIv8UcQMzhg,13254
|
|
7
|
+
kryten_llm/components/health_monitor.py,sha256=fz1cbNw87WdQ9HENHeS_pY_csDPPEAAFKbXe7xZerGA,9281
|
|
8
|
+
kryten_llm/components/heartbeat.py,sha256=aPjRZLDvZAVI_lr-qgYRfAl-dvmCVtPtfJFAlL-dNyc,3887
|
|
9
|
+
kryten_llm/components/listener.py,sha256=qIUzOvrxRAyDYlpidP58kBV2FI5BqykxZvMUIOe_Hr8,2590
|
|
10
|
+
kryten_llm/components/llm_manager.py,sha256=Weow6xd3c5IDYcjFgmjMuTtqBWEV6OneFwNPBZSr2dg,13237
|
|
11
|
+
kryten_llm/components/prompt_builder.py,sha256=SBgtCKP3v2pkBEvszX1n64AbjJMctLdBQT8Zb6lh9gM,5671
|
|
12
|
+
kryten_llm/components/rate_limiter.py,sha256=K77h7O7rU9llc2saY8Kol74Fpz-57-0V4l9gFVqVUMs,18271
|
|
13
|
+
kryten_llm/components/response_logger.py,sha256=LVaqp_FQvCEhGFbE_VqKX9SgNLIhT9FlzhrKd0kO3XI,3879
|
|
14
|
+
kryten_llm/components/spam_detector.py,sha256=40Zxg53U-ACSJkfG71gP8a8iR8sQ7wBd23eGB5jwkHg,14036
|
|
15
|
+
kryten_llm/components/trigger_engine.py,sha256=RGQn6PJ_V5RMsZavqKKbG7LlSSK4sL5p8P2r2tu9dkY,10472
|
|
16
|
+
kryten_llm/components/validator.py,sha256=oR0jp-iH-gOeR3GWVp5AxaeauEFPjN8iUN_JOUN8tzs,9586
|
|
17
|
+
kryten_llm/config.py,sha256=qLJdaNt46vId0Yx8RS5kN80sTYaAwFzqkgMT-WhvhMQ,3132
|
|
18
|
+
kryten_llm/models/__init__.py,sha256=743neYCwAB2FVZwy1aE4TafFw1otYJGKyhkPer2yz_4,494
|
|
19
|
+
kryten_llm/models/config.py,sha256=BA4PSKAiJlf9pHIrHoRhIZs8ovK6tKnmGU13CWHD1hE,20269
|
|
20
|
+
kryten_llm/models/events.py,sha256=kwC1EngFdKUFHLyG2hafC4se25nlb9LkaKUHCq5MfW0,371
|
|
21
|
+
kryten_llm/models/phase3.py,sha256=QXOgI7PTGVKonnXVdREUmWfYWlX8fPQWTXpP-Vw0AF0,1318
|
|
22
|
+
kryten_llm/service.py,sha256=KjMfufmHSUIYIMhzn0m1tho5wPQjlM0Z4PF6sO6qfd8,22247
|
|
23
|
+
kryten_llm/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
kryten_llm-0.2.2.dist-info/entry_points.txt,sha256=bbnT67yByV9T1FSfv5hPYgEG1zgdS2_s_UXm6cej0lk,55
|
|
25
|
+
kryten_llm-0.2.2.dist-info/licenses/LICENSE,sha256=4-aY9N48r38gULWwGnXZB0cFBoTcFneVGswDSK2bVi4,1095
|
|
26
|
+
kryten_llm-0.2.2.dist-info/METADATA,sha256=rYY-_VziVdTfwGrSqRMiEj4lNaI_aRQqVRUXDEr5HaU,6277
|
|
27
|
+
kryten_llm-0.2.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
28
|
+
kryten_llm-0.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kryten Robot Team
|
|
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.
|