ngpt 1.1.3__tar.gz → 1.2.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.
- ngpt-1.2.0/COMMIT_GUIDELINES.md +116 -0
- ngpt-1.2.0/CONTRIBUTING.md +90 -0
- {ngpt-1.1.3 → ngpt-1.2.0}/PKG-INFO +40 -2
- {ngpt-1.1.3 → ngpt-1.2.0}/README.md +39 -1
- {ngpt-1.1.3 → ngpt-1.2.0}/ngpt/cli.py +60 -6
- {ngpt-1.1.3 → ngpt-1.2.0}/ngpt/client.py +1 -1
- {ngpt-1.1.3 → ngpt-1.2.0}/ngpt/config.py +59 -14
- {ngpt-1.1.3 → ngpt-1.2.0}/pyproject.toml +1 -1
- {ngpt-1.1.3 → ngpt-1.2.0}/uv.lock +1 -1
- {ngpt-1.1.3 → ngpt-1.2.0}/.github/workflows/python-publish.yml +0 -0
- {ngpt-1.1.3 → ngpt-1.2.0}/.gitignore +0 -0
- {ngpt-1.1.3 → ngpt-1.2.0}/.python-version +0 -0
- {ngpt-1.1.3 → ngpt-1.2.0}/LICENSE +0 -0
- {ngpt-1.1.3 → ngpt-1.2.0}/ngpt/__init__.py +0 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
# Commit Message Guidelines
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Consistent and well-formatted commit messages provide a better project history, make it easier to understand changes, facilitate automatic changelog generation, and help identify bugs. These guidelines ensure that our commit messages remain uniform, descriptive, and useful to all project contributors.
|
6
|
+
|
7
|
+
## Message Format
|
8
|
+
|
9
|
+
```
|
10
|
+
type: <brief summary (max 50 chars)>
|
11
|
+
|
12
|
+
- [type] key change 1 (max 60 chars per line)
|
13
|
+
- [type] key change 2
|
14
|
+
- [type] key change N (include all significant changes)
|
15
|
+
```
|
16
|
+
|
17
|
+
## Best Practices
|
18
|
+
|
19
|
+
- Use the imperative mood in the subject line (e.g., "Add feature" not "Added feature")
|
20
|
+
- Don't end the subject line with a period
|
21
|
+
- Start with a capital letter
|
22
|
+
- Separate subject from body with a blank line
|
23
|
+
- Wrap body text at 72 characters
|
24
|
+
- Use the body to explain what and why vs. how
|
25
|
+
|
26
|
+
## Atomic Commits
|
27
|
+
|
28
|
+
Each commit should represent a single logical change:
|
29
|
+
- Make focused commits that address a single concern
|
30
|
+
- Split work into multiple commits when appropriate
|
31
|
+
- Avoid mixing unrelated changes in the same commit
|
32
|
+
|
33
|
+
## Issue References
|
34
|
+
|
35
|
+
Link to issues in your commit messages:
|
36
|
+
- Use "Fixes #123" to automatically close an issue
|
37
|
+
- Use "Relates to #123" for changes related to but not resolving an issue
|
38
|
+
- Always include issue numbers for bug fixes
|
39
|
+
|
40
|
+
## Valid Types
|
41
|
+
|
42
|
+
Choose the most specific type for your changes:
|
43
|
+
|
44
|
+
- `feat`: New user features (not for new files without user features)
|
45
|
+
- `fix`: Bug fixes/corrections to errors
|
46
|
+
- `refactor`: Restructured code (no behavior change)
|
47
|
+
- `style`: Formatting/whitespace changes
|
48
|
+
- `docs`: Documentation only
|
49
|
+
- `test`: Test-related changes
|
50
|
+
- `perf`: Performance improvements
|
51
|
+
- `build`: Build system changes
|
52
|
+
- `ci`: CI pipeline changes
|
53
|
+
- `chore`: Routine maintenance tasks
|
54
|
+
- `revert`: Reverting previous changes
|
55
|
+
- `add`: New files/resources with no user-facing features
|
56
|
+
- `remove`: Removing files/code
|
57
|
+
- `update`: Changes to existing functionality
|
58
|
+
- `security`: Security-related changes
|
59
|
+
- `i18n`: Internationalization
|
60
|
+
- `a11y`: Accessibility improvements
|
61
|
+
- `api`: API-related changes
|
62
|
+
- `ui`: User interface changes
|
63
|
+
- `data`: Database changes
|
64
|
+
- `config`: Configuration changes
|
65
|
+
- `init`: Initial commit/project setup
|
66
|
+
|
67
|
+
## Examples
|
68
|
+
|
69
|
+
### Good Examples
|
70
|
+
|
71
|
+
#### Bug Fix:
|
72
|
+
```
|
73
|
+
fix: Address memory leak in data processing pipeline
|
74
|
+
|
75
|
+
- [fix] Release resources in DataProcessor.cleanUp()
|
76
|
+
- [fix] Add null checks to prevent NPE in edge cases
|
77
|
+
- [perf] Optimize large dataset handling
|
78
|
+
|
79
|
+
Fixes #456
|
80
|
+
```
|
81
|
+
|
82
|
+
#### New Feature:
|
83
|
+
```
|
84
|
+
feat: Add user profile export functionality
|
85
|
+
|
86
|
+
- [feat] Create export button in profile settings
|
87
|
+
- [feat] Implement JSON and CSV export options
|
88
|
+
- [security] Apply rate limiting to prevent abuse
|
89
|
+
|
90
|
+
Relates to #789
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Refactoring:
|
94
|
+
```
|
95
|
+
refactor: Simplify authentication flow
|
96
|
+
|
97
|
+
- [refactor] Extract login logic to separate service
|
98
|
+
- [refactor] Reduce complexity in AuthManager
|
99
|
+
- [test] Add unit tests for new service
|
100
|
+
|
101
|
+
Part of #234
|
102
|
+
```
|
103
|
+
|
104
|
+
### Poor Example:
|
105
|
+
```
|
106
|
+
Made some changes to fix stuff
|
107
|
+
|
108
|
+
Changed a bunch of files to make the login work better.
|
109
|
+
Also fixed that other bug people were complaining about.
|
110
|
+
```
|
111
|
+
|
112
|
+
## Additional Resources
|
113
|
+
|
114
|
+
- [Conventional Commits](https://www.conventionalcommits.org/)
|
115
|
+
- [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/)
|
116
|
+
- [A Note About Git Commit Messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Contributing to NGPT
|
2
|
+
|
3
|
+
Thank you for your interest in contributing to NGPT! This document provides guidelines and instructions for contributing to this project.
|
4
|
+
|
5
|
+
## Development Setup
|
6
|
+
|
7
|
+
1. Fork the repository
|
8
|
+
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/ngpt.git`
|
9
|
+
3. Navigate to the project directory: `cd ngpt`
|
10
|
+
4. Set up Python environment:
|
11
|
+
- It's recommended to use a virtual environment
|
12
|
+
- Create a virtual environment: `python -m venv .venv`
|
13
|
+
- Activate the virtual environment:
|
14
|
+
- Windows: `.venv\Scripts\activate`
|
15
|
+
- Unix/MacOS: `source .venv/bin/activate`
|
16
|
+
5. Install dependencies: `pip install -e .`
|
17
|
+
6. Open the project in your preferred code editor
|
18
|
+
|
19
|
+
## Code Structure
|
20
|
+
|
21
|
+
- `ngpt/` - Main package directory
|
22
|
+
- `__init__.py` - Package initialization
|
23
|
+
- `cli.py` - Command-line interface implementation
|
24
|
+
- `config.py` - Configuration management
|
25
|
+
- `client.py` - Client implementation
|
26
|
+
- `.github/` - GitHub workflows and templates
|
27
|
+
- `pyproject.toml` - Project configuration and dependencies
|
28
|
+
|
29
|
+
## Code Style Guidelines
|
30
|
+
|
31
|
+
- Follow PEP 8 style guidelines for Python code
|
32
|
+
- Use consistent indentation (4 spaces)
|
33
|
+
- Write descriptive docstrings for functions and classes
|
34
|
+
- Add type hints where appropriate
|
35
|
+
- Add comments for complex logic
|
36
|
+
|
37
|
+
## Pull Request Guidelines
|
38
|
+
|
39
|
+
Before submitting a pull request, please make sure that:
|
40
|
+
|
41
|
+
- Your code follows the project's coding conventions
|
42
|
+
- You have tested your changes thoroughly
|
43
|
+
- All existing tests pass (if applicable)
|
44
|
+
- The commit messages are clear and follow conventional commit guidelines as specified in [COMMIT_GUIDELINES.md](COMMIT_GUIDELINES.md)
|
45
|
+
- You have provided a detailed explanation of the changes in the pull request description
|
46
|
+
|
47
|
+
## Submitting Changes
|
48
|
+
|
49
|
+
1. Create a new branch: `git checkout -b feature/your-feature-name`
|
50
|
+
2. Make your changes
|
51
|
+
3. Test thoroughly
|
52
|
+
4. Commit with clear messages: `git commit -m "feat: description"`
|
53
|
+
5. Push to your fork: `git push origin feature/your-feature-name`
|
54
|
+
6. Open a Pull Request against the main repository
|
55
|
+
|
56
|
+
## Testing
|
57
|
+
|
58
|
+
Before submitting your changes, please test:
|
59
|
+
|
60
|
+
- Basic functionality
|
61
|
+
- Any new features you've added
|
62
|
+
- Any components you've modified
|
63
|
+
- Ensure all tests pass if there's a test suite
|
64
|
+
|
65
|
+
## Issue Reporting
|
66
|
+
|
67
|
+
When opening an issue, please:
|
68
|
+
|
69
|
+
- Use a clear and descriptive title
|
70
|
+
- Provide a detailed description of the issue, including the environment and steps to reproduce
|
71
|
+
- Include any relevant logs or code snippets
|
72
|
+
- Specify your Python version and operating system
|
73
|
+
- Search the repository for similar issues before creating a new one
|
74
|
+
|
75
|
+
## Feature Requests
|
76
|
+
|
77
|
+
Feature requests are welcome! To submit a feature request:
|
78
|
+
|
79
|
+
- Use a clear and descriptive title
|
80
|
+
- Provide a detailed description of the proposed feature
|
81
|
+
- Explain why this feature would be useful to NGPT users
|
82
|
+
- If possible, suggest how it might be implemented
|
83
|
+
|
84
|
+
## Questions and Discussions
|
85
|
+
|
86
|
+
For questions about the project that aren't bugs or feature requests, please use GitHub Discussions instead of opening an issue. This helps keep the issue tracker focused on bugs and features.
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
By contributing to this project, you agree that your contributions will be licensed under the same [LICENSE](LICENSE) as the project.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ngpt
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.2.0
|
4
4
|
Summary: A lightweight Python CLI and library for interacting with OpenAI-compatible APIs, supporting both official and self-hosted LLM endpoints.
|
5
5
|
Project-URL: Homepage, https://github.com/nazdridoy/ngpt
|
6
6
|
Project-URL: Repository, https://github.com/nazdridoy/ngpt
|
@@ -48,8 +48,10 @@ A lightweight Python CLI and library for interacting with OpenAI-compatible APIs
|
|
48
48
|
- [Python Library](#as-a-library)
|
49
49
|
- [Configuration](#configuration)
|
50
50
|
- [Command Line Options](#command-line-options)
|
51
|
+
- [Interactive Configuration](#interactive-configuration)
|
51
52
|
- [Configuration File](#configuration-file)
|
52
53
|
- [Configuration Priority](#configuration-priority)
|
54
|
+
- [Contributing](#contributing)
|
53
55
|
- [License](#license)
|
54
56
|
|
55
57
|
## Quick Start
|
@@ -191,14 +193,36 @@ You can configure the client using the following options:
|
|
191
193
|
| `--base-url` | Base URL for the API |
|
192
194
|
| `--model` | Model to use |
|
193
195
|
| `--web-search` | Enable web search capability |
|
194
|
-
| `--config` | Path to a custom configuration file |
|
196
|
+
| `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
|
195
197
|
| `--config-index` | Index of the configuration to use (default: 0) |
|
198
|
+
| `--remove` | Remove the configuration at the specified index (requires --config and --config-index) |
|
196
199
|
| `--show-config` | Show configuration details and exit |
|
197
200
|
| `--all` | Used with `--show-config` to display all configurations |
|
198
201
|
| `-s, --shell` | Generate and execute shell commands |
|
199
202
|
| `-c, --code` | Generate clean code output |
|
200
203
|
| `-v, --version` | Show version information |
|
201
204
|
|
205
|
+
### Interactive Configuration
|
206
|
+
|
207
|
+
The `--config` option without arguments enters interactive configuration mode, allowing you to add or edit configurations:
|
208
|
+
|
209
|
+
```bash
|
210
|
+
# Add a new configuration
|
211
|
+
ngpt --config
|
212
|
+
|
213
|
+
# Edit an existing configuration at index 1
|
214
|
+
ngpt --config --config-index 1
|
215
|
+
|
216
|
+
# Remove a configuration at index 2
|
217
|
+
ngpt --config --remove --config-index 2
|
218
|
+
```
|
219
|
+
|
220
|
+
In interactive mode:
|
221
|
+
- When editing an existing configuration, press Enter to keep the current values
|
222
|
+
- When creating a new configuration, press Enter to use default values
|
223
|
+
- For security, your API key is not displayed when editing configurations
|
224
|
+
- When removing a configuration, you'll be asked to confirm before deletion
|
225
|
+
|
202
226
|
### Configuration File
|
203
227
|
|
204
228
|
nGPT uses a configuration file stored in the standard user config directory for your operating system:
|
@@ -242,6 +266,20 @@ nGPT determines configuration values in the following order (highest priority fi
|
|
242
266
|
3. Configuration file (selected by `--config-index`, defaults to index 0)
|
243
267
|
4. Default values
|
244
268
|
|
269
|
+
## Contributing
|
270
|
+
|
271
|
+
We welcome contributions to nGPT! Whether it's bug fixes, feature additions, or documentation improvements, your help is appreciated.
|
272
|
+
|
273
|
+
To contribute:
|
274
|
+
|
275
|
+
1. Fork the repository
|
276
|
+
2. Create a feature branch: `git checkout -b feature/your-feature-name`
|
277
|
+
3. Make your changes
|
278
|
+
4. Commit with clear messages following conventional commit guidelines
|
279
|
+
5. Push to your fork and submit a pull request
|
280
|
+
|
281
|
+
Please check the [CONTRIBUTING.md](CONTRIBUTING.md) file for detailed guidelines on code style, pull request process, and development setup.
|
282
|
+
|
245
283
|
## License
|
246
284
|
|
247
285
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
@@ -15,8 +15,10 @@ A lightweight Python CLI and library for interacting with OpenAI-compatible APIs
|
|
15
15
|
- [Python Library](#as-a-library)
|
16
16
|
- [Configuration](#configuration)
|
17
17
|
- [Command Line Options](#command-line-options)
|
18
|
+
- [Interactive Configuration](#interactive-configuration)
|
18
19
|
- [Configuration File](#configuration-file)
|
19
20
|
- [Configuration Priority](#configuration-priority)
|
21
|
+
- [Contributing](#contributing)
|
20
22
|
- [License](#license)
|
21
23
|
|
22
24
|
## Quick Start
|
@@ -158,14 +160,36 @@ You can configure the client using the following options:
|
|
158
160
|
| `--base-url` | Base URL for the API |
|
159
161
|
| `--model` | Model to use |
|
160
162
|
| `--web-search` | Enable web search capability |
|
161
|
-
| `--config` | Path to a custom configuration file |
|
163
|
+
| `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
|
162
164
|
| `--config-index` | Index of the configuration to use (default: 0) |
|
165
|
+
| `--remove` | Remove the configuration at the specified index (requires --config and --config-index) |
|
163
166
|
| `--show-config` | Show configuration details and exit |
|
164
167
|
| `--all` | Used with `--show-config` to display all configurations |
|
165
168
|
| `-s, --shell` | Generate and execute shell commands |
|
166
169
|
| `-c, --code` | Generate clean code output |
|
167
170
|
| `-v, --version` | Show version information |
|
168
171
|
|
172
|
+
### Interactive Configuration
|
173
|
+
|
174
|
+
The `--config` option without arguments enters interactive configuration mode, allowing you to add or edit configurations:
|
175
|
+
|
176
|
+
```bash
|
177
|
+
# Add a new configuration
|
178
|
+
ngpt --config
|
179
|
+
|
180
|
+
# Edit an existing configuration at index 1
|
181
|
+
ngpt --config --config-index 1
|
182
|
+
|
183
|
+
# Remove a configuration at index 2
|
184
|
+
ngpt --config --remove --config-index 2
|
185
|
+
```
|
186
|
+
|
187
|
+
In interactive mode:
|
188
|
+
- When editing an existing configuration, press Enter to keep the current values
|
189
|
+
- When creating a new configuration, press Enter to use default values
|
190
|
+
- For security, your API key is not displayed when editing configurations
|
191
|
+
- When removing a configuration, you'll be asked to confirm before deletion
|
192
|
+
|
169
193
|
### Configuration File
|
170
194
|
|
171
195
|
nGPT uses a configuration file stored in the standard user config directory for your operating system:
|
@@ -209,6 +233,20 @@ nGPT determines configuration values in the following order (highest priority fi
|
|
209
233
|
3. Configuration file (selected by `--config-index`, defaults to index 0)
|
210
234
|
4. Default values
|
211
235
|
|
236
|
+
## Contributing
|
237
|
+
|
238
|
+
We welcome contributions to nGPT! Whether it's bug fixes, feature additions, or documentation improvements, your help is appreciated.
|
239
|
+
|
240
|
+
To contribute:
|
241
|
+
|
242
|
+
1. Fork the repository
|
243
|
+
2. Create a feature branch: `git checkout -b feature/your-feature-name`
|
244
|
+
3. Make your changes
|
245
|
+
4. Commit with clear messages following conventional commit guidelines
|
246
|
+
5. Push to your fork and submit a pull request
|
247
|
+
|
248
|
+
Please check the [CONTRIBUTING.md](CONTRIBUTING.md) file for detailed guidelines on code style, pull request process, and development setup.
|
249
|
+
|
212
250
|
## License
|
213
251
|
|
214
252
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
@@ -2,7 +2,7 @@ import argparse
|
|
2
2
|
import sys
|
3
3
|
import os
|
4
4
|
from .client import NGPTClient
|
5
|
-
from .config import load_config, get_config_path, load_configs, add_config_entry
|
5
|
+
from .config import load_config, get_config_path, load_configs, add_config_entry, remove_config_entry
|
6
6
|
from . import __version__
|
7
7
|
|
8
8
|
def show_config_help():
|
@@ -40,11 +40,15 @@ def show_config_help():
|
|
40
40
|
print(" 4. Or provide command line arguments:")
|
41
41
|
print(" ngpt --api-key your-key --base-url https://api.example.com --model your-model \"Your prompt\"")
|
42
42
|
|
43
|
-
print(" 5. Use --config-index to specify which configuration to use:")
|
43
|
+
print(" 5. Use --config-index to specify which configuration to use or edit:")
|
44
44
|
print(" ngpt --config-index 1 \"Your prompt\"")
|
45
45
|
|
46
|
-
print(" 6. Use --config without arguments to add
|
46
|
+
print(" 6. Use --config without arguments to add a new configuration:")
|
47
|
+
print(" ngpt --config")
|
48
|
+
print(" Or specify an index to edit an existing configuration:")
|
47
49
|
print(" ngpt --config --config-index 1")
|
50
|
+
print(" 7. Remove a configuration at a specific index:")
|
51
|
+
print(" ngpt --config --remove --config-index 1")
|
48
52
|
|
49
53
|
def check_config(config):
|
50
54
|
"""Check config for common issues and provide guidance."""
|
@@ -68,8 +72,9 @@ def main():
|
|
68
72
|
|
69
73
|
# Config options
|
70
74
|
config_group = parser.add_argument_group('Configuration Options')
|
71
|
-
config_group.add_argument('--config', nargs='?', const=True, help='Path to a custom config file or, if no value provided, enter interactive configuration mode')
|
72
|
-
config_group.add_argument('--config-index', type=int, default=0, help='Index of the configuration to use (default: 0)')
|
75
|
+
config_group.add_argument('--config', nargs='?', const=True, help='Path to a custom config file or, if no value provided, enter interactive configuration mode to create a new config')
|
76
|
+
config_group.add_argument('--config-index', type=int, default=0, help='Index of the configuration to use or edit (default: 0)')
|
77
|
+
config_group.add_argument('--remove', action='store_true', help='Remove the configuration at the specified index (requires --config and --config-index)')
|
73
78
|
config_group.add_argument('--show-config', action='store_true', help='Show the current configuration(s) and exit')
|
74
79
|
config_group.add_argument('--all', action='store_true', help='Show details for all configurations (requires --show-config)')
|
75
80
|
|
@@ -103,7 +108,56 @@ def main():
|
|
103
108
|
# Handle interactive configuration mode
|
104
109
|
if args.config is True: # --config was used without a value
|
105
110
|
config_path = get_config_path()
|
106
|
-
|
111
|
+
|
112
|
+
# Handle configuration removal if --remove flag is present
|
113
|
+
if args.remove:
|
114
|
+
# Validate that config_index is explicitly provided
|
115
|
+
if '--config-index' not in sys.argv:
|
116
|
+
parser.error("--remove requires explicitly specifying --config-index")
|
117
|
+
|
118
|
+
# Show config details before asking for confirmation
|
119
|
+
configs = load_configs(str(config_path))
|
120
|
+
|
121
|
+
# Check if index is valid
|
122
|
+
if args.config_index < 0 or args.config_index >= len(configs):
|
123
|
+
print(f"Error: Configuration index {args.config_index} is out of range. Valid range: 0-{len(configs)-1}")
|
124
|
+
return
|
125
|
+
|
126
|
+
# Show the configuration that will be removed
|
127
|
+
config = configs[args.config_index]
|
128
|
+
print(f"Configuration to remove (index {args.config_index}):")
|
129
|
+
print(f" Provider: {config.get('provider', 'N/A')}")
|
130
|
+
print(f" Model: {config.get('model', 'N/A')}")
|
131
|
+
print(f" Base URL: {config.get('base_url', 'N/A')}")
|
132
|
+
print(f" API Key: {'[Set]' if config.get('api_key') else '[Not Set]'}")
|
133
|
+
|
134
|
+
# Ask for confirmation
|
135
|
+
try:
|
136
|
+
print("\nAre you sure you want to remove this configuration? [y/N] ", end='')
|
137
|
+
response = input().lower()
|
138
|
+
if response in ('y', 'yes'):
|
139
|
+
remove_config_entry(config_path, args.config_index)
|
140
|
+
else:
|
141
|
+
print("Configuration removal cancelled.")
|
142
|
+
except KeyboardInterrupt:
|
143
|
+
print("\nConfiguration removal cancelled by user.")
|
144
|
+
|
145
|
+
return
|
146
|
+
|
147
|
+
# Regular config addition/editing (existing code)
|
148
|
+
# If --config-index was not explicitly specified, create a new entry by passing None
|
149
|
+
# This will cause add_config_entry to create a new entry at the end of the list
|
150
|
+
# Otherwise, edit the existing config at the specified index
|
151
|
+
config_index = None if args.config_index == 0 and '--config-index' not in sys.argv else args.config_index
|
152
|
+
|
153
|
+
# Load existing configs to determine the new index if creating a new config
|
154
|
+
configs = load_configs(str(config_path))
|
155
|
+
if config_index is None:
|
156
|
+
print(f"Creating new configuration at index {len(configs)}")
|
157
|
+
else:
|
158
|
+
print(f"Editing existing configuration at index {config_index}")
|
159
|
+
|
160
|
+
add_config_entry(config_path, config_index)
|
107
161
|
return
|
108
162
|
|
109
163
|
# Load configuration using the specified index (needed for active config display)
|
@@ -10,7 +10,7 @@ class NGPTClient:
|
|
10
10
|
self,
|
11
11
|
api_key: str = "",
|
12
12
|
base_url: str = "https://api.openai.com/v1/",
|
13
|
-
provider: str = "OpenAI",
|
13
|
+
provider: str = "OpenAI",
|
14
14
|
model: str = "gpt-3.5-turbo"
|
15
15
|
):
|
16
16
|
self.api_key = api_key
|
@@ -51,23 +51,44 @@ def add_config_entry(config_path: Path, config_index: Optional[int] = None) -> N
|
|
51
51
|
"""Add a new configuration entry or update existing one at the specified index."""
|
52
52
|
configs = load_configs(custom_path=str(config_path))
|
53
53
|
|
54
|
-
#
|
55
|
-
|
54
|
+
# Determine if we're editing an existing config or creating a new one
|
55
|
+
is_existing_config = config_index is not None and config_index < len(configs)
|
56
|
+
|
57
|
+
# Set up entry based on whether we're editing or creating
|
58
|
+
if is_existing_config:
|
59
|
+
# Use existing config as the base when editing
|
60
|
+
entry = configs[config_index].copy()
|
61
|
+
print("Enter configuration details (press Enter to keep current values):")
|
62
|
+
else:
|
63
|
+
# Use default config as the base when creating new
|
64
|
+
entry = DEFAULT_CONFIG_ENTRY.copy()
|
65
|
+
print("Enter configuration details (press Enter to use default values):")
|
56
66
|
|
57
|
-
# Interactive configuration
|
58
|
-
print("Enter configuration details (press Enter to use default values):")
|
59
67
|
try:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
# For API key, just show the prompt without the current value for security
|
69
|
+
user_input = input(f"API Key: ")
|
70
|
+
if user_input:
|
71
|
+
entry["api_key"] = user_input
|
72
|
+
|
73
|
+
# For other fields, show current/default value and keep it if Enter is pressed
|
74
|
+
user_input = input(f"Base URL [{entry['base_url']}]: ")
|
75
|
+
if user_input:
|
76
|
+
entry["base_url"] = user_input
|
77
|
+
|
78
|
+
user_input = input(f"Provider [{entry['provider']}]: ")
|
79
|
+
if user_input:
|
80
|
+
entry["provider"] = user_input
|
81
|
+
|
82
|
+
user_input = input(f"Model [{entry['model']}]: ")
|
83
|
+
if user_input:
|
84
|
+
entry["model"] = user_input
|
64
85
|
|
65
86
|
# Add or update the entry
|
66
|
-
if
|
67
|
-
configs[config_index] =
|
87
|
+
if is_existing_config:
|
88
|
+
configs[config_index] = entry
|
68
89
|
print(f"Updated configuration at index {config_index}")
|
69
90
|
else:
|
70
|
-
configs.append(
|
91
|
+
configs.append(entry)
|
71
92
|
print(f"Added new configuration at index {len(configs)-1}")
|
72
93
|
|
73
94
|
# Save the updated configs
|
@@ -128,8 +149,7 @@ def load_config(custom_path: Optional[str] = None, config_index: int = 0) -> Dic
|
|
128
149
|
# Override with environment variables if they exist
|
129
150
|
env_mapping = {
|
130
151
|
"OPENAI_API_KEY": "api_key",
|
131
|
-
"OPENAI_BASE_URL": "base_url",
|
132
|
-
"OPENAI_PROVIDER": "provider",
|
152
|
+
"OPENAI_BASE_URL": "base_url",
|
133
153
|
"OPENAI_MODEL": "model"
|
134
154
|
}
|
135
155
|
|
@@ -137,4 +157,29 @@ def load_config(custom_path: Optional[str] = None, config_index: int = 0) -> Dic
|
|
137
157
|
if env_var in os.environ and os.environ[env_var]:
|
138
158
|
config[config_key] = os.environ[env_var]
|
139
159
|
|
140
|
-
return config
|
160
|
+
return config
|
161
|
+
|
162
|
+
def remove_config_entry(config_path: Path, config_index: int) -> bool:
|
163
|
+
"""
|
164
|
+
Remove a configuration entry at the specified index.
|
165
|
+
Returns True if successful, False otherwise.
|
166
|
+
"""
|
167
|
+
configs = load_configs(custom_path=str(config_path))
|
168
|
+
|
169
|
+
# Check if index is valid
|
170
|
+
if config_index < 0 or config_index >= len(configs):
|
171
|
+
print(f"Error: Configuration index {config_index} is out of range. Valid range: 0-{len(configs)-1}")
|
172
|
+
return False
|
173
|
+
|
174
|
+
# Remove the config at the specified index
|
175
|
+
removed_config = configs.pop(config_index)
|
176
|
+
|
177
|
+
try:
|
178
|
+
# Save the updated configs
|
179
|
+
with open(config_path, "w") as f:
|
180
|
+
json.dump(configs, f, indent=2)
|
181
|
+
print(f"Removed configuration at index {config_index} for provider '{removed_config.get('provider', 'Unknown')}'")
|
182
|
+
return True
|
183
|
+
except Exception as e:
|
184
|
+
print(f"Error saving configuration: {e}")
|
185
|
+
return False
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "ngpt"
|
3
|
-
version = "1.
|
3
|
+
version = "1.2.0"
|
4
4
|
description = "A lightweight Python CLI and library for interacting with OpenAI-compatible APIs, supporting both official and self-hosted LLM endpoints."
|
5
5
|
authors = [
|
6
6
|
{name = "nazDridoy", email = "nazdridoy399@gmail.com"},
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|