ngpt 1.1.4__py3-none-any.whl → 1.2.0__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.
ngpt/cli.py CHANGED
@@ -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 or edit a configuration:")
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
- add_config_entry(config_path, args.config_index)
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)
ngpt/config.py CHANGED
@@ -157,4 +157,29 @@ def load_config(custom_path: Optional[str] = None, config_index: int = 0) -> Dic
157
157
  if env_var in os.environ and os.environ[env_var]:
158
158
  config[config_key] = os.environ[env_var]
159
159
 
160
- 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
  Metadata-Version: 2.4
2
2
  Name: ngpt
3
- Version: 1.1.4
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
@@ -195,6 +195,7 @@ You can configure the client using the following options:
195
195
  | `--web-search` | Enable web search capability |
196
196
  | `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
197
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) |
198
199
  | `--show-config` | Show configuration details and exit |
199
200
  | `--all` | Used with `--show-config` to display all configurations |
200
201
  | `-s, --shell` | Generate and execute shell commands |
@@ -211,12 +212,16 @@ ngpt --config
211
212
 
212
213
  # Edit an existing configuration at index 1
213
214
  ngpt --config --config-index 1
215
+
216
+ # Remove a configuration at index 2
217
+ ngpt --config --remove --config-index 2
214
218
  ```
215
219
 
216
220
  In interactive mode:
217
221
  - When editing an existing configuration, press Enter to keep the current values
218
222
  - When creating a new configuration, press Enter to use default values
219
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
220
225
 
221
226
  ### Configuration File
222
227
 
@@ -0,0 +1,9 @@
1
+ ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
2
+ ngpt/cli.py,sha256=tIKXjKfh4K19UcZ0uG8JqTVz-9Lxg-p16dkYTiOmp7o,13582
3
+ ngpt/client.py,sha256=O0dPYeQCJlpWZWBBsroo-5UxeyBVwqC6o3Pm8lRnDiY,10329
4
+ ngpt/config.py,sha256=BF0G3QeiPma8l7EQyc37bR7LWZog7FHJQNe7uj9cr4w,6896
5
+ ngpt-1.2.0.dist-info/METADATA,sha256=o8iptGfiLJbibZZLKYFrg584Ppw6BMLkZuZQfvOzAFk,9497
6
+ ngpt-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ ngpt-1.2.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
8
+ ngpt-1.2.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
9
+ ngpt-1.2.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
2
- ngpt/cli.py,sha256=_nu7eY76_y4KQ59cKC91VijVvzSASAaSJI1FFfJ9l04,10655
3
- ngpt/client.py,sha256=O0dPYeQCJlpWZWBBsroo-5UxeyBVwqC6o3Pm8lRnDiY,10329
4
- ngpt/config.py,sha256=STnYKJor2nE_dKpK9NcnWlz3A8HeB8ufp-xOewGmRVo,5947
5
- ngpt-1.1.4.dist-info/METADATA,sha256=kCn6kuMVbjmD0_LTjVyq1D_5MXrB6aNJpgF7Qf9QopE,9240
6
- ngpt-1.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- ngpt-1.1.4.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
8
- ngpt-1.1.4.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
9
- ngpt-1.1.4.dist-info/RECORD,,
File without changes