ifs-rag-assistant-cli 2.2.2__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.
@@ -0,0 +1,536 @@
1
+ Metadata-Version: 2.4
2
+ Name: ifs-rag-assistant-cli
3
+ Version: 2.2.2
4
+ Summary: Command-line interface for IFS RAG Assistant Q&A system
5
+ Home-page: https://github.com/maricaantonacci/ifs-rag-assistant-cli
6
+ Author: Marica Antonacci
7
+ Author-email: Marica Antonacci <marica.antonacci@ecmwf.int>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/maricaantonacci/ifs-rag-assistant-cli
10
+ Project-URL: Repository, https://github.com/maricaantonacci/ifs-rag-assistant-cli
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: typer[all]>=0.9.0
23
+ Requires-Dist: requests>=2.28.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: rich>=10.0.0
26
+ Dynamic: author
27
+ Dynamic: home-page
28
+ Dynamic: requires-python
29
+
30
+ # IFS RAG Assistant CLI
31
+
32
+ [![Tests](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/test.yml/badge.svg)](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/test.yml)
33
+ [![Security](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/security.yml/badge.svg)](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/security.yml)
34
+ [![Semantic Release](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/release.yml/badge.svg)](https://github.com/maricaantonacci/ifs-rag-assistant-cli/actions/workflows/release.yml)
35
+ [![Python Version](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37
+
38
+ Command-line interface for the IFS RAG Assistant (Retrieval-Augmented Generation) Q&A system.
39
+
40
+ ## Features
41
+
42
+ - 🔐 **OAuth 2.0 Device Flow Authentication** - Secure authentication using Keycloak
43
+ - 💬 **Interactive Chat Mode** - Conversational interface with context preservation
44
+ - 🔍 **Search** - Search the Fortran codebase index
45
+ - 📚 **Citations** - View source code references with line numbers
46
+ - 👍 **Interactive Feedback** - Provide thumbs up/down feedback on answers
47
+ - 🎨 **Rich Output** - Beautiful terminal output with tables and formatting
48
+ - 💾 **Session Caching** - Automatic session management for seamless use
49
+
50
+ ## Installation
51
+
52
+ ### Prerequisites
53
+
54
+ - Python 3.9 or higher
55
+
56
+ ### Install from PyPI (Recommended)
57
+
58
+ You can install the CLI directly from PyPI:
59
+
60
+ ```bash
61
+ pip install ifs-rag-assistant-cli
62
+ ```
63
+
64
+ Check installation:
65
+
66
+ ```bash
67
+ ifs-rag-assistant-cli --version
68
+ ```
69
+
70
+ ### Should I create a virtual environment first?
71
+
72
+ Short answer: not strictly required, but strongly recommended.
73
+
74
+ - Use a virtual environment if you want to avoid dependency conflicts with other Python tools.
75
+ - Skip it only if you already manage Python globally in another way.
76
+
77
+ Recommended setup:
78
+
79
+ ```bash
80
+ python -m venv .venv
81
+ source .venv/bin/activate
82
+ pip install --upgrade pip
83
+ pip install ifs-rag-assistant-cli
84
+ ```
85
+
86
+ ### Install from source
87
+
88
+ ```bash
89
+ # Clone the repository
90
+ git clone https://github.com/maricaantonacci/ifs-rag-assistant-cli.git
91
+ cd ifs-rag-assistant-cli
92
+
93
+ # Install the package
94
+ pip install .
95
+ ```
96
+
97
+ For development (editable install):
98
+
99
+ ```bash
100
+ pip install -e .
101
+ ```
102
+
103
+ ## Quick Start
104
+
105
+ ### For ECMWF Users
106
+
107
+ If you're using the ECMWF production environment, setup is simple:
108
+
109
+ 1. **Initialize configuration** (pre-configured for ECMWF):
110
+
111
+ ```bash
112
+ ifs-rag-assistant-cli init
113
+ ```
114
+
115
+ 2. **Start using the CLI**:
116
+
117
+ ```bash
118
+ ifs-rag-assistant-cli chat
119
+ ```
120
+
121
+ On first use, you'll be prompted to authenticate via OAuth Device Flow.
122
+
123
+ That's it! The configuration is already set up for ECMWF's production environment.
124
+
125
+ ### For Custom Environments
126
+
127
+ 1. **Initialize and customize configuration**:
128
+
129
+ ```bash
130
+ ifs-rag-assistant-cli init
131
+ # Edit ~/.ifs-rag-assistant-cli/config.yaml to match your setup
132
+ ```
133
+
134
+ Or manually create the config:
135
+
136
+ ```bash
137
+ mkdir -p ~/.ifs-rag-assistant-cli
138
+ cp config.yaml.example ~/.ifs-rag-assistant-cli/config.yaml
139
+ # Edit ~/.ifs-rag-assistant-cli/config.yaml as needed
140
+ ```
141
+
142
+ 2. **Check the backend is running**:
143
+
144
+ ```bash
145
+ ifs-rag-assistant-cli health
146
+ ```
147
+
148
+ 3. **Start chatting**:
149
+
150
+ ```bash
151
+ ifs-rag-assistant-cli chat
152
+ ```
153
+
154
+ ## Configuration
155
+
156
+ The CLI loads configuration from multiple sources in this priority order:
157
+
158
+ 1. Explicit `--config` flag
159
+ 2. `~/.ifs-rag-assistant-cli/config.yaml` (user config)
160
+ 3. `./config.yaml` (current directory)
161
+ 4. Environment variables
162
+ 5. Default values
163
+
164
+ ### Configuration File
165
+
166
+ The easiest way to create a configuration file is using the `init` command:
167
+
168
+ ```bash
169
+ ifs-rag-assistant-cli init
170
+ ```
171
+
172
+ This creates `~/.ifs-rag-assistant-cli/config.yaml` with the following defaults for ECMWF production:
173
+
174
+ ```yaml
175
+ # Backend API (ECMWF Production)
176
+ api_root: "https://ifs-assistant-api.apps.ifs-llm.ewcloud.host"
177
+ timeout: 300
178
+
179
+ # OAuth configuration (ECMWF Production)
180
+ oauth_device_flow_mode: "custom_wrapper"
181
+ oauth_custom_wrapper_url: "https://accounts.ecmwf.int/ecmwf-token-generator"
182
+ keycloak_client_id: "ifs-rag"
183
+
184
+ # Session cache
185
+ cache_dir: "~/.ifs-rag-assistant-cli"
186
+ verbose: false
187
+ ```
188
+
189
+ For **local development** or **custom environments**, edit the file to use standard Keycloak:
190
+
191
+ ```yaml
192
+ api_root: "http://localhost:8000"
193
+ timeout: 300
194
+ oauth_device_flow_mode: "standard"
195
+ keycloak_server_url: "http://localhost:8080"
196
+ keycloak_realm: "master"
197
+ keycloak_client_id: "ifs-rag"
198
+ auth_mode: "oauth"
199
+ cache_dir: "~/.ifs-rag-assistant-cli"
200
+ verbose: true
201
+ ```
202
+
203
+ For **local development without authentication**, you can disable OAuth:
204
+
205
+ ```yaml
206
+ api_root: "http://localhost:8000"
207
+ timeout: 300
208
+ auth_mode: "disabled"
209
+ cache_dir: "~/.ifs-rag-assistant-cli"
210
+ verbose: true
211
+ ```
212
+
213
+ > **Security note:** `auth_mode: "disabled"` is intended for local development only. The CLI will reject this mode when `api_root` is not localhost/loopback.
214
+
215
+ ### Configuration Parameters
216
+
217
+ | Parameter | Description | Required | Notes |
218
+ |-----------|-------------|----------|-------|
219
+ | `api_root` | Backend API base URL | Mandatory | ECMWF production URL or local dev server |
220
+ | `timeout` | Request timeout in seconds | Optional | Default: `300.0` (5 minutes) |
221
+ | `oauth_device_flow_mode` | OAuth mode: `standard` or `custom_wrapper` | Optional | Default: `custom_wrapper` (ECMWF) |
222
+ | `oauth_custom_wrapper_url` | Custom wrapper API URL | Mandatory* | Required for `custom_wrapper` mode |
223
+ | `keycloak_client_id` | OAuth client ID | Mandatory | Default: `ifs-rag`, used for both modes |
224
+ | `keycloak_server_url` | Keycloak server base URL | Optional* | Required only for `standard` OAuth mode |
225
+ | `keycloak_realm` | Keycloak realm name | Optional* | Required only for `standard` OAuth mode |
226
+ | `auth_mode` | Authentication mode: `oauth` or `disabled` | Optional | Default: `oauth`; `disabled` allowed only for localhost/loopback `api_root` |
227
+ | `cache_dir` | Session cache directory | Optional | Default: `~/.ifs-rag-assistant-cli` |
228
+
229
+ > **Note on OAuth Modes:**
230
+ > The `standard` mode implements the OAuth 2.0 Device Flow (RFC 8628) for use with public clients when available. However, some environments like ECMWF enforce policies that prohibit public clients. In such cases, the `custom_wrapper` mode uses a specialized wrapper around the Keycloak server that enables device flow authentication while issuing offline tokens (refresh tokens) for users, maintaining security without requiring public client support.
231
+
232
+ ### Environment Variables
233
+
234
+ ```bash
235
+ export IFS_RAG_API_ROOT="http://localhost:8000"
236
+ export IFS_RAG_TIMEOUT="30"
237
+ export IFS_RAG_KEYCLOAK_SERVER_URL="http://localhost:8080"
238
+ export IFS_RAG_KEYCLOAK_REALM="master"
239
+ export IFS_RAG_KEYCLOAK_CLIENT_ID="ifs-rag"
240
+ export IFS_RAG_CACHE_DIR="~/.ifs-rag-assistant-cli"
241
+ export IFS_RAG_OAUTH_DEVICE_FLOW_MODE="standard"
242
+ export IFS_RAG_AUTH_MODE="oauth"
243
+ ```
244
+
245
+ ## Usage
246
+
247
+ ### Available Commands
248
+
249
+ ```bash
250
+ ifs-rag-assistant-cli --help
251
+ ```
252
+
253
+ **Commands:**
254
+ - `init` - Initialize configuration file (pre-configured for ECMWF)
255
+ - `chat` - Start an interactive chat session
256
+ - `ask` - Ask a single question
257
+ - `search` - Search the RAG index
258
+ - `logout` - Logout and clear cached session
259
+ - `health` - Check backend health status
260
+ - `models` - List available models from the backend
261
+ - `usage` - Display usage guide from the backend
262
+ - `version` - Display version information (also: `--version`, `-v`)
263
+
264
+ ### Interactive Chat
265
+
266
+ Start a conversational session with automatic feedback prompts:
267
+
268
+ ```bash
269
+ ifs-rag-assistant-cli chat
270
+ ```
271
+
272
+ Resume a previous conversation:
273
+
274
+ ```bash
275
+ ifs-rag-assistant-cli chat --resume <conversation-id>
276
+ ```
277
+
278
+ Plain text output (for copy-paste):
279
+
280
+ ```bash
281
+ ifs-rag-assistant-cli chat --plain
282
+ ```
283
+
284
+ **Chat Features:**
285
+ - Ask multiple questions in sequence
286
+ - Conversation context is maintained
287
+ - Optional feedback after each answer (thumbs up/down with comments)
288
+ - Type `exit` or `quit` to end the session
289
+
290
+ ### Single Question
291
+
292
+ Ask a single question:
293
+
294
+ ```bash
295
+ ifs-rag-assistant-cli ask "What is RRTM?"
296
+ ```
297
+
298
+ Plain text output:
299
+
300
+ ```bash
301
+ ifs-rag-assistant-cli ask "Explain subroutine X" --plain
302
+ ```
303
+
304
+ **Ask Features:**
305
+ - Get an immediate answer with citations
306
+ - Optional interactive feedback prompt
307
+ - Shows conversation ID to continue in chat mode
308
+
309
+ ### Search
310
+
311
+ Search the codebase index:
312
+
313
+ ```bash
314
+ ifs-rag-assistant-cli search "subroutine"
315
+ ifs-rag-assistant-cli search "RRTM radiative transfer"
316
+ ```
317
+
318
+ Returns relevant code citations with file paths, line numbers, and symbol types.
319
+
320
+ ### Models
321
+
322
+ List available LLM models:
323
+
324
+ ```bash
325
+ ifs-rag-assistant-cli models
326
+ ```
327
+
328
+ ### Usage Guide
329
+
330
+ View the backend's usage guide:
331
+
332
+ ```bash
333
+ ifs-rag-assistant-cli usage
334
+ ```
335
+
336
+ Raw markdown output:
337
+
338
+ ```bash
339
+ ifs-rag-assistant-cli usage --raw
340
+ ```
341
+
342
+ ### Authentication
343
+
344
+ Logout and clear cached session:
345
+
346
+ ```bash
347
+ ifs-rag-assistant-cli logout
348
+ ```
349
+
350
+ ### Initialize Configuration
351
+
352
+ Create a configuration file pre-configured for ECMWF production:
353
+
354
+ ```bash
355
+ ifs-rag-assistant-cli init
356
+ ```
357
+
358
+ The configuration file will be created at `~/.ifs-rag-assistant-cli/config.yaml`.
359
+
360
+ **For ECMWF users:**
361
+ - No manual editing required - works out of the box
362
+ - Backend endpoint: ECMWF IFS RAG Assistant production service
363
+ - OAuth: Pre-configured with ECMWF's authentication system
364
+
365
+ **For other environments:**
366
+ - Edit the generated file to match your setup
367
+ - Update both backend endpoint and OAuth settings
368
+ - See comments in the file for guidance
369
+
370
+ Overwrite an existing configuration:
371
+
372
+ ```bash
373
+ ifs-rag-assistant-cli init --force
374
+ ```
375
+
376
+ ### Health Check
377
+
378
+ Check backend status:
379
+
380
+ ```bash
381
+ ifs-rag-assistant-cli health
382
+ ```
383
+
384
+ ## Interactive Feedback
385
+
386
+ After receiving an answer from the `ask` or `chat` commands, you'll be prompted to provide optional feedback:
387
+
388
+ ```
389
+ 💬 Would you like to provide feedback for this answer? [Y/n]:
390
+ ```
391
+
392
+ **Note:** The default is **Yes** - just press Enter to provide feedback, or type `n` to skip.
393
+
394
+ If you choose to provide feedback:
395
+
396
+ 1. **Select a vote:**
397
+ - 1 = 👍 Up (helpful)
398
+ - 2 = 👎 Down (not helpful)
399
+ - 3 = Skip
400
+
401
+ 2. **Optionally add a comment** explaining your feedback
402
+
403
+ Your feedback helps improve the RAG system's quality and accuracy.
404
+
405
+ ## OAuth Authentication
406
+
407
+ The CLI uses OAuth 2.0 Device Flow for authentication. On first use:
408
+
409
+ 1. You'll see a device code (e.g., `ABCD-EFGH`)
410
+ 2. Visit the verification URL in your browser
411
+ 3. Enter the device code
412
+ 4. Log in with your credentials
413
+ 5. The CLI will automatically continue once authorized
414
+
415
+ Sessions are cached in `~/.ifs-rag-assistant-cli/session` and valid for 24 hours.
416
+
417
+ ### OAuth Modes
418
+
419
+ #### Standard Mode (RFC 8628)
420
+
421
+ Works with standard Keycloak OIDC endpoints:
422
+
423
+ ```yaml
424
+ oauth_device_flow_mode: "standard"
425
+ keycloak_server_url: "http://localhost:8080"
426
+ keycloak_realm: "master"
427
+ ```
428
+
429
+ #### Custom Wrapper Mode
430
+
431
+ For custom OAuth wrapper APIs (e.g., ECMWF):
432
+
433
+ ```yaml
434
+ oauth_device_flow_mode: "custom_wrapper"
435
+ oauth_custom_wrapper_url: "https://api.example.com"
436
+ ```
437
+
438
+ ## Development
439
+
440
+ ### Project Structure
441
+
442
+ ```
443
+ ifs-rag-assistant-cli/
444
+ ├── ifs_rag_assistant_cli/
445
+ │ ├── __init__.py
446
+ │ ├── auth_client.py # Authentication client
447
+ │ ├── backend_client.py # Backend API client
448
+ │ ├── cli.py # CLI commands
449
+ │ ├── config.py # Configuration management
450
+ │ ├── models.py # Data models
451
+ │ ├── oauth.py # OAuth Device Flow
452
+ │ └── session.py # Session management
453
+ ├── setup.py
454
+ ├── requirements.txt
455
+ ├── config.yaml.example
456
+ └── README.md
457
+ ```
458
+
459
+ ### Contributing
460
+
461
+ We use conventional commits and semantic versioning for automated releases. See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
462
+
463
+ #### Commit Convention
464
+
465
+ Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification:
466
+
467
+ ```
468
+ <type>(<scope>): <description>
469
+
470
+ [optional body]
471
+
472
+ [optional footer(s)]
473
+ ```
474
+
475
+ **Types:**
476
+ - `feat`: New feature (triggers minor version bump)
477
+ - `fix`: Bug fix (triggers patch version bump)
478
+ - `docs`: Documentation changes
479
+ - `style`: Code style changes (formatting, etc.)
480
+ - `refactor`: Code refactoring
481
+ - `perf`: Performance improvements (triggers patch version bump)
482
+ - `test`: Adding or updating tests
483
+ - `build`: Build system changes
484
+ - `ci`: CI/CD changes
485
+ - `chore`: Other changes
486
+
487
+ **Examples:**
488
+ ```
489
+ feat(cli): add support for streaming responses
490
+ fix(auth): resolve token refresh issue
491
+ docs(readme): update installation instructions
492
+ ```
493
+
494
+ ### CI/CD Workflows
495
+
496
+ The project uses GitHub Actions for automated testing, security checks, and releases:
497
+
498
+ #### 🔒 Security Checks (`.github/workflows/security.yml`)
499
+ - Runs on push, pull requests, and weekly schedule
500
+ - **Bandit**: Python security vulnerability scanner (fails on HIGH severity)
501
+ - **pip-audit**: Official PyPA dependency vulnerability checker (fails on any CVE)
502
+
503
+ #### 🚀 Semantic Release (`.github/workflows/release.yml`)
504
+ - Automatically triggered on push to `main` branch
505
+ - Analyzes commit messages to determine version bump
506
+ - Updates `CHANGELOG.md`
507
+ - Creates GitHub releases with release notes
508
+ - Publishes the package to PyPI (requires repository secret `PYPI_TOKEN`)
509
+
510
+ #### ✅ Tests (`.github/workflows/test.yml`)
511
+ - Tests across Python 3.9, 3.10, 3.11, and 3.12
512
+ - Linting with `ruff`
513
+ - Type checking with `mypy`
514
+ - CLI installation verification
515
+
516
+ #### 🔄 Dependabot
517
+ - Automated dependency updates
518
+ - Weekly schedule for Python and GitHub Actions dependencies
519
+
520
+ ## Requirements
521
+
522
+ - Python >= 3.9
523
+ - Access to an IFS RAG Assistant backend
524
+ - ECMWF users: Backend is already deployed and configured
525
+ - Custom setups: Requires a running backend instance
526
+ - OAuth authentication provider
527
+ - ECMWF users: Authentication is pre-configured
528
+ - Custom setups: Keycloak server or compatible OAuth provider
529
+
530
+ ## License
531
+
532
+ MIT License
533
+
534
+ ## Support
535
+
536
+ For issues and questions, please open an issue on GitHub.