ngpt 2.2.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 +30 -6
- {ngpt-2.2.0.dist-info → ngpt-2.3.0.dist-info}/METADATA +42 -1
- ngpt-2.3.0.dist-info/RECORD +9 -0
- ngpt-2.2.0.dist-info/RECORD +0 -9
- {ngpt-2.2.0.dist-info → ngpt-2.3.0.dist-info}/WHEEL +0 -0
- {ngpt-2.2.0.dist-info → ngpt-2.3.0.dist-info}/entry_points.txt +0 -0
- {ngpt-2.2.0.dist-info → ngpt-2.3.0.dist-info}/licenses/LICENSE +0 -0
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, log_file=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 = {
|
@@ -146,11 +146,16 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
146
146
|
print(f"\n{separator}\n")
|
147
147
|
|
148
148
|
# Initialize conversation history
|
149
|
-
system_prompt = "You are a helpful assistant."
|
149
|
+
system_prompt = preprompt if preprompt else "You are a helpful assistant."
|
150
150
|
conversation = []
|
151
151
|
system_message = {"role": "system", "content": system_prompt}
|
152
152
|
conversation.append(system_message)
|
153
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
|
+
|
154
159
|
# Initialize prompt_toolkit history
|
155
160
|
prompt_history = InMemoryHistory() if HAS_PROMPT_TOOLKIT else None
|
156
161
|
|
@@ -326,6 +331,8 @@ def main():
|
|
326
331
|
help='Set max response length in tokens')
|
327
332
|
global_group.add_argument('--log', metavar='FILE',
|
328
333
|
help='Set filepath to log conversation to (For interactive modes)')
|
334
|
+
global_group.add_argument('--preprompt',
|
335
|
+
help='Set preprompt')
|
329
336
|
|
330
337
|
# Mode flags (mutually exclusive)
|
331
338
|
mode_group = parser.add_argument_group('Modes (mutually exclusive)')
|
@@ -486,7 +493,7 @@ def main():
|
|
486
493
|
# Interactive chat mode
|
487
494
|
interactive_chat_session(client, web_search=args.web_search, no_stream=args.no_stream,
|
488
495
|
temperature=args.temperature, top_p=args.top_p,
|
489
|
-
max_length=args.max_length, log_file=args.log)
|
496
|
+
max_length=args.max_length, log_file=args.log, preprompt=args.preprompt)
|
490
497
|
elif args.shell:
|
491
498
|
if args.prompt is None:
|
492
499
|
try:
|
@@ -543,7 +550,6 @@ def main():
|
|
543
550
|
print(f"\nGenerated code:\n{generated_code}")
|
544
551
|
|
545
552
|
elif args.text:
|
546
|
-
# Multi-line text input mode
|
547
553
|
if args.prompt is not None:
|
548
554
|
prompt = args.prompt
|
549
555
|
else:
|
@@ -651,9 +657,18 @@ def main():
|
|
651
657
|
sys.exit(130)
|
652
658
|
|
653
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
|
+
|
654
669
|
response = client.chat(prompt, stream=not args.no_stream, web_search=args.web_search,
|
655
670
|
temperature=args.temperature, top_p=args.top_p,
|
656
|
-
max_tokens=args.max_length)
|
671
|
+
max_tokens=args.max_length, messages=messages)
|
657
672
|
if args.no_stream and response:
|
658
673
|
print(response)
|
659
674
|
|
@@ -668,9 +683,18 @@ def main():
|
|
668
683
|
sys.exit(130)
|
669
684
|
else:
|
670
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
|
+
|
671
695
|
response = client.chat(prompt, stream=not args.no_stream, web_search=args.web_search,
|
672
696
|
temperature=args.temperature, top_p=args.top_p,
|
673
|
-
max_tokens=args.max_length)
|
697
|
+
max_tokens=args.max_length, messages=messages)
|
674
698
|
if args.no_stream and response:
|
675
699
|
print(response)
|
676
700
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ngpt
|
3
|
-
Version: 2.
|
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,,
|
ngpt-2.2.0.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
|
2
|
-
ngpt/cli.py,sha256=H_EIwZr-mSpw5JdlSD-CT6zWGWLldCJ4G-BKyWGIoOE,31536
|
3
|
-
ngpt/client.py,sha256=75xmzO7e9wQ7y_LzZCacg3mkZdheewcBxB6moPftqYw,13067
|
4
|
-
ngpt/config.py,sha256=BF0G3QeiPma8l7EQyc37bR7LWZog7FHJQNe7uj9cr4w,6896
|
5
|
-
ngpt-2.2.0.dist-info/METADATA,sha256=seHeG-0SZyJcCN_SXpfpzI3jfwLBs9XrPkcdXt1mMhI,11278
|
6
|
-
ngpt-2.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
ngpt-2.2.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
|
8
|
-
ngpt-2.2.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
|
9
|
-
ngpt-2.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|