ngpt 1.6.0__tar.gz → 1.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngpt
3
- Version: 1.6.0
3
+ Version: 1.7.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
@@ -121,6 +121,9 @@ ngpt --show-config
121
121
  # Show all configurations
122
122
  ngpt --show-config --all
123
123
 
124
+ # List available models for the current configuration
125
+ ngpt --list-models
126
+
124
127
  # With custom options
125
128
  ngpt --api-key your-key --base-url http://your-endpoint --model your-model "Hello"
126
129
 
@@ -211,6 +214,7 @@ You can configure the client using the following options:
211
214
  | `--api-key` | API key for the service |
212
215
  | `--base-url` | Base URL for the API |
213
216
  | `--model` | Model to use |
217
+ | `--list-models` | List all available models for the current configuration |
214
218
  | `--web-search` | Enable web search capability |
215
219
  | `-n, --no-stream` | Return the whole response without streaming |
216
220
  | `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
@@ -87,6 +87,9 @@ ngpt --show-config
87
87
  # Show all configurations
88
88
  ngpt --show-config --all
89
89
 
90
+ # List available models for the current configuration
91
+ ngpt --list-models
92
+
90
93
  # With custom options
91
94
  ngpt --api-key your-key --base-url http://your-endpoint --model your-model "Hello"
92
95
 
@@ -177,6 +180,7 @@ You can configure the client using the following options:
177
180
  | `--api-key` | API key for the service |
178
181
  | `--base-url` | Base URL for the API |
179
182
  | `--model` | Model to use |
183
+ | `--list-models` | List all available models for the current configuration |
180
184
  | `--web-search` | Enable web search capability |
181
185
  | `-n, --no-stream` | Return the whole response without streaming |
182
186
  | `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
@@ -68,6 +68,8 @@ def show_config_help():
68
68
  print(" ngpt --config --config-index 1")
69
69
  print(" 7. Remove a configuration at a specific index:")
70
70
  print(" ngpt --config --remove --config-index 1")
71
+ print(" 8. List available models for the current configuration:")
72
+ print(" ngpt --list-models")
71
73
 
72
74
  def check_config(config):
73
75
  """Check config for common issues and provide guidance."""
@@ -273,6 +275,7 @@ def main():
273
275
  config_group.add_argument('--remove', action='store_true', help='Remove the configuration at the specified index (requires --config and --config-index)')
274
276
  config_group.add_argument('--show-config', action='store_true', help='Show the current configuration(s) and exit')
275
277
  config_group.add_argument('--all', action='store_true', help='Show details for all configurations (requires --show-config)')
278
+ config_group.add_argument('--list-models', action='store_true', help='List all available models for the current configuration and exit')
276
279
 
277
280
  # Global options
278
281
  global_group = parser.add_argument_group('Global Options')
@@ -409,18 +412,35 @@ def main():
409
412
  return
410
413
 
411
414
  # For interactive mode, we'll allow continuing without a specific prompt
412
- if not args.prompt and not (args.shell or args.code or args.text or args.interactive):
415
+ if not args.prompt and not (args.shell or args.code or args.text or args.interactive or args.show_config or args.list_models):
413
416
  parser.print_help()
414
417
  return
415
418
 
416
419
  # Check configuration (using the potentially overridden active_config)
417
- if not check_config(active_config):
420
+ if not args.show_config and not args.list_models and not check_config(active_config):
418
421
  return
419
422
 
420
423
  # Initialize client using the potentially overridden active_config
421
424
  client = NGPTClient(**active_config)
422
425
 
423
426
  try:
427
+ # Handle listing models
428
+ if args.list_models:
429
+ print("Retrieving available models...")
430
+ models = client.list_models()
431
+ if models:
432
+ print(f"\nAvailable models for {active_config.get('provider', 'API')}:")
433
+ print("-" * 50)
434
+ for model in models:
435
+ if "id" in model:
436
+ owned_by = f" ({model.get('owned_by', 'Unknown')})" if "owned_by" in model else ""
437
+ current = " [active]" if model["id"] == active_config["model"] else ""
438
+ print(f"- {model['id']}{owned_by}{current}")
439
+ print("\nUse --model MODEL_NAME to select a specific model")
440
+ else:
441
+ print("No models available or could not retrieve models.")
442
+ return
443
+
424
444
  # Handle modes
425
445
  if args.interactive:
426
446
  # Interactive chat mode
@@ -259,4 +259,48 @@ Code:"""
259
259
  )
260
260
  except Exception as e:
261
261
  print(f"Error generating code: {e}")
262
- return ""
262
+ return ""
263
+
264
+ def list_models(self) -> list:
265
+ """
266
+ Retrieve the list of available models from the API.
267
+
268
+ Returns:
269
+ List of available model objects or empty list if failed
270
+ """
271
+ if not self.api_key:
272
+ print("Error: API key is not set. Please configure your API key in the config file or provide it with --api-key.")
273
+ return []
274
+
275
+ # Endpoint for models
276
+ url = f"{self.base_url}models"
277
+
278
+ try:
279
+ response = requests.get(url, headers=self.headers)
280
+ response.raise_for_status() # Raise exception for HTTP errors
281
+ result = response.json()
282
+
283
+ if "data" in result:
284
+ return result["data"]
285
+ else:
286
+ print("Error: Unexpected response format when retrieving models.")
287
+ return []
288
+
289
+ except requests.exceptions.HTTPError as e:
290
+ if e.response.status_code == 401:
291
+ print("Error: Authentication failed. Please check your API key.")
292
+ elif e.response.status_code == 404:
293
+ print(f"Error: Models endpoint not found at {url}")
294
+ elif e.response.status_code == 429:
295
+ print("Error: Rate limit exceeded. Please try again later.")
296
+ else:
297
+ print(f"HTTP Error: {e}")
298
+ return []
299
+
300
+ except requests.exceptions.ConnectionError:
301
+ print(f"Error: Could not connect to {self.base_url}. Please check your internet connection and base URL.")
302
+ return []
303
+
304
+ except Exception as e:
305
+ print(f"Error: An unexpected error occurred while retrieving models: {e}")
306
+ return []
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ngpt"
3
- version = "1.6.0"
3
+ version = "1.7.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"},
@@ -113,7 +113,7 @@ wheels = [
113
113
 
114
114
  [[package]]
115
115
  name = "ngpt"
116
- version = "1.6.0"
116
+ version = "1.7.0"
117
117
  source = { editable = "." }
118
118
  dependencies = [
119
119
  { name = "prompt-toolkit" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes