ngpt 2.1.0__py3-none-any.whl → 2.3.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
@@ -85,7 +85,7 @@ def check_config(config):
85
85
 
86
86
  return True
87
87
 
88
- def interactive_chat_session(client, web_search=False, no_stream=False, temperature=0.7, top_p=1.0, max_length=None):
88
+ def interactive_chat_session(client, web_search=False, no_stream=False, temperature=0.7, top_p=1.0, max_length=None, log_file=None, preprompt=None):
89
89
  """Run an interactive chat session with conversation history."""
90
90
  # Define ANSI color codes for terminal output
91
91
  COLORS = {
@@ -127,16 +127,35 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
127
127
 
128
128
  print(f"\n{separator}\n")
129
129
 
130
+ # Initialize log file if provided
131
+ log_handle = None
132
+ if log_file:
133
+ try:
134
+ import datetime
135
+ timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
136
+ log_handle = open(log_file, 'a', encoding='utf-8')
137
+ log_handle.write(f"\n--- nGPT Session Log: {sys.argv} ---\n")
138
+ log_handle.write(f"Started at: {timestamp}\n\n")
139
+ print(f"{COLORS['green']}Logging conversation to: {log_file}{COLORS['reset']}")
140
+ except Exception as e:
141
+ print(f"{COLORS['yellow']}Warning: Could not open log file: {str(e)}{COLORS['reset']}")
142
+ log_handle = None
143
+
130
144
  # Custom separator - use the same length for consistency
131
145
  def print_separator():
132
146
  print(f"\n{separator}\n")
133
147
 
134
148
  # Initialize conversation history
135
- system_prompt = "You are a helpful assistant."
149
+ system_prompt = preprompt if preprompt else "You are a helpful assistant."
136
150
  conversation = []
137
151
  system_message = {"role": "system", "content": system_prompt}
138
152
  conversation.append(system_message)
139
153
 
154
+ # Log system prompt if logging is enabled
155
+ if log_handle and preprompt:
156
+ log_handle.write(f"System: {system_prompt}\n\n")
157
+ log_handle.flush()
158
+
140
159
  # Initialize prompt_toolkit history
141
160
  prompt_history = InMemoryHistory() if HAS_PROMPT_TOOLKIT else None
142
161
 
@@ -228,6 +247,11 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
228
247
  user_message = {"role": "user", "content": user_input}
229
248
  conversation.append(user_message)
230
249
 
250
+ # Log user message if logging is enabled
251
+ if log_handle:
252
+ log_handle.write(f"User: {user_input}\n")
253
+ log_handle.flush()
254
+
231
255
  # Print assistant indicator with formatting
232
256
  if not no_stream:
233
257
  print(f"\n{ngpt_header()}: {COLORS['reset']}", end="", flush=True)
@@ -253,6 +277,11 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
253
277
  # Print response if not streamed
254
278
  if no_stream:
255
279
  print(response)
280
+
281
+ # Log assistant response if logging is enabled
282
+ if log_handle:
283
+ log_handle.write(f"Assistant: {response}\n\n")
284
+ log_handle.flush()
256
285
 
257
286
  # Print separator between exchanges
258
287
  print_separator()
@@ -264,9 +293,14 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
264
293
  # Print traceback for debugging if it's a serious error
265
294
  import traceback
266
295
  traceback.print_exc()
296
+ finally:
297
+ # Close log file if it was opened
298
+ if log_handle:
299
+ log_handle.write(f"\n--- End of Session ---\n")
300
+ log_handle.close()
267
301
 
268
302
  def main():
269
- parser = argparse.ArgumentParser(description="nGPT - A CLI tool for interacting with custom OpenAI API endpoints")
303
+ parser = argparse.ArgumentParser(description="nGPT - A CLI tool for interacting with OpenAI-compatible APIs, supporting both official and self-hosted LLM endpoints")
270
304
 
271
305
  # Version flag
272
306
  parser.add_argument('-v', '--version', action='version', version=f'nGPT {__version__}', help='Show version information and exit')
@@ -295,6 +329,10 @@ def main():
295
329
  help='Set top_p (controls diversity, default: 1.0)')
296
330
  global_group.add_argument('--max_length', type=int,
297
331
  help='Set max response length in tokens')
332
+ global_group.add_argument('--log', metavar='FILE',
333
+ help='Set filepath to log conversation to (For interactive modes)')
334
+ global_group.add_argument('--preprompt',
335
+ help='Set preprompt')
298
336
 
299
337
  # Mode flags (mutually exclusive)
300
338
  mode_group = parser.add_argument_group('Modes (mutually exclusive)')
@@ -455,7 +493,7 @@ def main():
455
493
  # Interactive chat mode
456
494
  interactive_chat_session(client, web_search=args.web_search, no_stream=args.no_stream,
457
495
  temperature=args.temperature, top_p=args.top_p,
458
- max_length=args.max_length)
496
+ max_length=args.max_length, log_file=args.log, preprompt=args.preprompt)
459
497
  elif args.shell:
460
498
  if args.prompt is None:
461
499
  try:
@@ -512,7 +550,6 @@ def main():
512
550
  print(f"\nGenerated code:\n{generated_code}")
513
551
 
514
552
  elif args.text:
515
- # Multi-line text input mode
516
553
  if args.prompt is not None:
517
554
  prompt = args.prompt
518
555
  else:
@@ -620,9 +657,18 @@ def main():
620
657
  sys.exit(130)
621
658
 
622
659
  print("\nSubmission successful. Waiting for response...")
660
+
661
+ # Create messages array with preprompt if available
662
+ messages = None
663
+ if args.preprompt:
664
+ messages = [
665
+ {"role": "system", "content": args.preprompt},
666
+ {"role": "user", "content": prompt}
667
+ ]
668
+
623
669
  response = client.chat(prompt, stream=not args.no_stream, web_search=args.web_search,
624
670
  temperature=args.temperature, top_p=args.top_p,
625
- max_tokens=args.max_length)
671
+ max_tokens=args.max_length, messages=messages)
626
672
  if args.no_stream and response:
627
673
  print(response)
628
674
 
@@ -637,9 +683,18 @@ def main():
637
683
  sys.exit(130)
638
684
  else:
639
685
  prompt = args.prompt
686
+
687
+ # Create messages array with preprompt if available
688
+ messages = None
689
+ if args.preprompt:
690
+ messages = [
691
+ {"role": "system", "content": args.preprompt},
692
+ {"role": "user", "content": prompt}
693
+ ]
694
+
640
695
  response = client.chat(prompt, stream=not args.no_stream, web_search=args.web_search,
641
696
  temperature=args.temperature, top_p=args.top_p,
642
- max_tokens=args.max_length)
697
+ max_tokens=args.max_length, messages=messages)
643
698
  if args.no_stream and response:
644
699
  print(response)
645
700
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngpt
3
- Version: 2.1.0
3
+ Version: 2.3.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
@@ -81,8 +81,16 @@ ngpt --shell "list all files in the current directory"
81
81
 
82
82
  # Use multiline editor for complex prompts
83
83
  ngpt --text
84
+
85
+ # Use custom system prompt
86
+ ngpt --preprompt "You are a Linux expert" "How do I find large files?"
87
+
88
+ # Log your conversation to a file
89
+ ngpt --interactive --log conversation.log
84
90
  ```
85
91
 
92
+ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
93
+
86
94
  ## Features
87
95
 
88
96
  - ✅ **Dual Mode**: Use as a CLI tool or import as a Python library
@@ -95,6 +103,10 @@ ngpt --text
95
103
  - 💻 **Shell Command Generation**: OS-aware command execution
96
104
  - 🧩 **Clean Code Generation**: Output code without markdown or explanations
97
105
  - 📝 **Rich Multiline Editor**: Interactive multiline text input with syntax highlighting and intuitive controls
106
+ - 🎭 **System Prompts**: Customize model behavior with custom system prompts
107
+ - 📃 **Conversation Logging**: Save your conversations to text files for later reference
108
+
109
+ See the [Feature Overview](https://nazdridoy.github.io/ngpt/overview.html) for more details.
98
110
 
99
111
  ## Documentation
100
112
 
@@ -102,6 +114,13 @@ Comprehensive documentation, including API reference, usage guides, and examples
102
114
 
103
115
  **[https://nazdridoy.github.io/ngpt/](https://nazdridoy.github.io/ngpt/)**
104
116
 
117
+ Key documentation sections:
118
+ - [Installation Guide](https://nazdridoy.github.io/ngpt/installation.html)
119
+ - [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html)
120
+ - [Library Usage Guide](https://nazdridoy.github.io/ngpt/usage/library_usage.html)
121
+ - [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html)
122
+ - [Examples & Tutorials](https://nazdridoy.github.io/ngpt/examples/basic.html)
123
+
105
124
  ## Installation
106
125
 
107
126
  ```bash
@@ -110,6 +129,8 @@ pip install ngpt
110
129
 
111
130
  Requires Python 3.8 or newer.
112
131
 
132
+ For detailed installation instructions, see the [Installation Guide](https://nazdridoy.github.io/ngpt/installation.html).
133
+
113
134
  ## Usage
114
135
 
115
136
  ### As a CLI Tool
@@ -121,6 +142,12 @@ ngpt "Hello, how are you?"
121
142
  # Interactive chat session with conversation history
122
143
  ngpt -i
123
144
 
145
+ # Log conversation to a file
146
+ ngpt --interactive --log conversation.log
147
+
148
+ # Use custom system prompt to guide AI behavior
149
+ ngpt --preprompt "You are a Python programming tutor" "Explain decorators"
150
+
124
151
  # Show version information
125
152
  ngpt -v
126
153
 
@@ -157,6 +184,8 @@ ngpt -c "create a python function that calculates fibonacci numbers"
157
184
  ngpt -t
158
185
  ```
159
186
 
187
+ For more CLI examples and detailed usage information, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
188
+
160
189
  ### As a Library
161
190
 
162
191
  ```python
@@ -189,6 +218,8 @@ command = client.generate_shell_command("list all files")
189
218
  code = client.generate_code("create a python function that calculates fibonacci numbers")
190
219
  ```
191
220
 
221
+ For more library examples and advanced usage, see the [Library Usage Guide](https://nazdridoy.github.io/ngpt/usage/library_usage.html).
222
+
192
223
  #### Advanced Library Usage
193
224
 
194
225
  ```python
@@ -215,6 +246,8 @@ code = client.generate_code("function that converts Celsius to Fahrenheit")
215
246
  print(code)
216
247
  ```
217
248
 
249
+ For advanced usage patterns and integrations, check out the [Advanced Examples](https://nazdridoy.github.io/ngpt/examples/advanced.html).
250
+
218
251
  ## Configuration
219
252
 
220
253
  ### Command Line Options
@@ -232,6 +265,8 @@ You can configure the client using the following options:
232
265
  | `--temperature` | Set temperature (controls randomness, default: 0.7) |
233
266
  | `--top_p` | Set top_p (controls diversity, default: 1.0) |
234
267
  | `--max_length` | Set maximum response length in tokens |
268
+ | `--preprompt` | Set custom system prompt to control AI behavior |
269
+ | `--log` | Set filepath to log conversation to (for interactive modes) |
235
270
  | `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
236
271
  | `--config-index` | Index of the configuration to use (default: 0) |
237
272
  | `--remove` | Remove the configuration at the specified index (requires --config and --config-index) |
@@ -243,6 +278,8 @@ You can configure the client using the following options:
243
278
  | `-t, --text` | Open interactive multiline editor for complex prompts |
244
279
  | `-v, --version` | Show version information |
245
280
 
281
+ For a complete reference of all available options, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
282
+
246
283
  ### Interactive Configuration
247
284
 
248
285
  The `--config` option without arguments enters interactive configuration mode, allowing you to add or edit configurations:
@@ -264,6 +301,8 @@ In interactive mode:
264
301
  - For security, your API key is not displayed when editing configurations
265
302
  - When removing a configuration, you'll be asked to confirm before deletion
266
303
 
304
+ For more details on configuring nGPT, see the [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html).
305
+
267
306
  ### Configuration File
268
307
 
269
308
  nGPT uses a configuration file stored in the standard user config directory for your operating system:
@@ -298,6 +337,8 @@ The configuration file uses a JSON list format, allowing you to store multiple c
298
337
  ]
299
338
  ```
300
339
 
340
+ For details on the configuration file format and structure, see the [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html).
341
+
301
342
  ### Configuration Priority
302
343
 
303
344
  nGPT determines configuration values in the following order (highest priority first):
@@ -0,0 +1,9 @@
1
+ ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
2
+ ngpt/cli.py,sha256=MfZ_QDKdylLvhPwUPRgCCBUD3iRDDh8Gy2Xnzf1MbbY,32511
3
+ ngpt/client.py,sha256=75xmzO7e9wQ7y_LzZCacg3mkZdheewcBxB6moPftqYw,13067
4
+ ngpt/config.py,sha256=BF0G3QeiPma8l7EQyc37bR7LWZog7FHJQNe7uj9cr4w,6896
5
+ ngpt-2.3.0.dist-info/METADATA,sha256=TG0WxgRFDG8oWOE3dtJgqRoyrJUfWB-QlgLkEq34Sqg,13535
6
+ ngpt-2.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ ngpt-2.3.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
8
+ ngpt-2.3.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
9
+ ngpt-2.3.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
2
- ngpt/cli.py,sha256=wNjY-qUuvzODdzffbYqyydJiLfhIsEXXUs9qalqcpvs,30082
3
- ngpt/client.py,sha256=75xmzO7e9wQ7y_LzZCacg3mkZdheewcBxB6moPftqYw,13067
4
- ngpt/config.py,sha256=BF0G3QeiPma8l7EQyc37bR7LWZog7FHJQNe7uj9cr4w,6896
5
- ngpt-2.1.0.dist-info/METADATA,sha256=47qdylepQUHyR-TsJTtB8ezMnRLnZie0uSI1WVbHUNg,11278
6
- ngpt-2.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- ngpt-2.1.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
8
- ngpt-2.1.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
9
- ngpt-2.1.0.dist-info/RECORD,,
File without changes