ngpt 2.1.0__tar.gz → 2.3.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.
Files changed (32) hide show
  1. {ngpt-2.1.0 → ngpt-2.3.0}/PKG-INFO +42 -1
  2. {ngpt-2.1.0 → ngpt-2.3.0}/README.md +41 -0
  3. {ngpt-2.1.0 → ngpt-2.3.0}/docs/configuration.md +6 -0
  4. {ngpt-2.1.0 → ngpt-2.3.0}/docs/examples/advanced.md +46 -0
  5. {ngpt-2.1.0 → ngpt-2.3.0}/docs/usage/cli_usage.md +44 -0
  6. {ngpt-2.1.0 → ngpt-2.3.0}/ngpt/cli.py +62 -7
  7. {ngpt-2.1.0 → ngpt-2.3.0}/pyproject.toml +1 -1
  8. {ngpt-2.1.0 → ngpt-2.3.0}/uv.lock +1 -1
  9. {ngpt-2.1.0 → ngpt-2.3.0}/.github/workflows/python-publish.yml +0 -0
  10. {ngpt-2.1.0 → ngpt-2.3.0}/.gitignore +0 -0
  11. {ngpt-2.1.0 → ngpt-2.3.0}/.python-version +0 -0
  12. {ngpt-2.1.0 → ngpt-2.3.0}/COMMIT_GUIDELINES.md +0 -0
  13. {ngpt-2.1.0 → ngpt-2.3.0}/CONTRIBUTING.md +0 -0
  14. {ngpt-2.1.0 → ngpt-2.3.0}/LICENSE +0 -0
  15. {ngpt-2.1.0 → ngpt-2.3.0}/docs/CONTRIBUTING.md +0 -0
  16. {ngpt-2.1.0 → ngpt-2.3.0}/docs/LICENSE.md +0 -0
  17. {ngpt-2.1.0 → ngpt-2.3.0}/docs/README.md +0 -0
  18. {ngpt-2.1.0 → ngpt-2.3.0}/docs/_config.yml +0 -0
  19. {ngpt-2.1.0 → ngpt-2.3.0}/docs/api/README.md +0 -0
  20. {ngpt-2.1.0 → ngpt-2.3.0}/docs/api/client.md +0 -0
  21. {ngpt-2.1.0 → ngpt-2.3.0}/docs/api/config.md +0 -0
  22. {ngpt-2.1.0 → ngpt-2.3.0}/docs/assets/css/style.scss +0 -0
  23. {ngpt-2.1.0 → ngpt-2.3.0}/docs/examples/README.md +0 -0
  24. {ngpt-2.1.0 → ngpt-2.3.0}/docs/examples/basic.md +0 -0
  25. {ngpt-2.1.0 → ngpt-2.3.0}/docs/examples/integrations.md +0 -0
  26. {ngpt-2.1.0 → ngpt-2.3.0}/docs/installation.md +0 -0
  27. {ngpt-2.1.0 → ngpt-2.3.0}/docs/overview.md +0 -0
  28. {ngpt-2.1.0 → ngpt-2.3.0}/docs/usage/README.md +0 -0
  29. {ngpt-2.1.0 → ngpt-2.3.0}/docs/usage/library_usage.md +0 -0
  30. {ngpt-2.1.0 → ngpt-2.3.0}/ngpt/__init__.py +0 -0
  31. {ngpt-2.1.0 → ngpt-2.3.0}/ngpt/client.py +0 -0
  32. {ngpt-2.1.0 → ngpt-2.3.0}/ngpt/config.py +0 -0
@@ -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):
@@ -47,8 +47,16 @@ ngpt --shell "list all files in the current directory"
47
47
 
48
48
  # Use multiline editor for complex prompts
49
49
  ngpt --text
50
+
51
+ # Use custom system prompt
52
+ ngpt --preprompt "You are a Linux expert" "How do I find large files?"
53
+
54
+ # Log your conversation to a file
55
+ ngpt --interactive --log conversation.log
50
56
  ```
51
57
 
58
+ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
59
+
52
60
  ## Features
53
61
 
54
62
  - ✅ **Dual Mode**: Use as a CLI tool or import as a Python library
@@ -61,6 +69,10 @@ ngpt --text
61
69
  - 💻 **Shell Command Generation**: OS-aware command execution
62
70
  - 🧩 **Clean Code Generation**: Output code without markdown or explanations
63
71
  - 📝 **Rich Multiline Editor**: Interactive multiline text input with syntax highlighting and intuitive controls
72
+ - 🎭 **System Prompts**: Customize model behavior with custom system prompts
73
+ - 📃 **Conversation Logging**: Save your conversations to text files for later reference
74
+
75
+ See the [Feature Overview](https://nazdridoy.github.io/ngpt/overview.html) for more details.
64
76
 
65
77
  ## Documentation
66
78
 
@@ -68,6 +80,13 @@ Comprehensive documentation, including API reference, usage guides, and examples
68
80
 
69
81
  **[https://nazdridoy.github.io/ngpt/](https://nazdridoy.github.io/ngpt/)**
70
82
 
83
+ Key documentation sections:
84
+ - [Installation Guide](https://nazdridoy.github.io/ngpt/installation.html)
85
+ - [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html)
86
+ - [Library Usage Guide](https://nazdridoy.github.io/ngpt/usage/library_usage.html)
87
+ - [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html)
88
+ - [Examples & Tutorials](https://nazdridoy.github.io/ngpt/examples/basic.html)
89
+
71
90
  ## Installation
72
91
 
73
92
  ```bash
@@ -76,6 +95,8 @@ pip install ngpt
76
95
 
77
96
  Requires Python 3.8 or newer.
78
97
 
98
+ For detailed installation instructions, see the [Installation Guide](https://nazdridoy.github.io/ngpt/installation.html).
99
+
79
100
  ## Usage
80
101
 
81
102
  ### As a CLI Tool
@@ -87,6 +108,12 @@ ngpt "Hello, how are you?"
87
108
  # Interactive chat session with conversation history
88
109
  ngpt -i
89
110
 
111
+ # Log conversation to a file
112
+ ngpt --interactive --log conversation.log
113
+
114
+ # Use custom system prompt to guide AI behavior
115
+ ngpt --preprompt "You are a Python programming tutor" "Explain decorators"
116
+
90
117
  # Show version information
91
118
  ngpt -v
92
119
 
@@ -123,6 +150,8 @@ ngpt -c "create a python function that calculates fibonacci numbers"
123
150
  ngpt -t
124
151
  ```
125
152
 
153
+ For more CLI examples and detailed usage information, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
154
+
126
155
  ### As a Library
127
156
 
128
157
  ```python
@@ -155,6 +184,8 @@ command = client.generate_shell_command("list all files")
155
184
  code = client.generate_code("create a python function that calculates fibonacci numbers")
156
185
  ```
157
186
 
187
+ For more library examples and advanced usage, see the [Library Usage Guide](https://nazdridoy.github.io/ngpt/usage/library_usage.html).
188
+
158
189
  #### Advanced Library Usage
159
190
 
160
191
  ```python
@@ -181,6 +212,8 @@ code = client.generate_code("function that converts Celsius to Fahrenheit")
181
212
  print(code)
182
213
  ```
183
214
 
215
+ For advanced usage patterns and integrations, check out the [Advanced Examples](https://nazdridoy.github.io/ngpt/examples/advanced.html).
216
+
184
217
  ## Configuration
185
218
 
186
219
  ### Command Line Options
@@ -198,6 +231,8 @@ You can configure the client using the following options:
198
231
  | `--temperature` | Set temperature (controls randomness, default: 0.7) |
199
232
  | `--top_p` | Set top_p (controls diversity, default: 1.0) |
200
233
  | `--max_length` | Set maximum response length in tokens |
234
+ | `--preprompt` | Set custom system prompt to control AI behavior |
235
+ | `--log` | Set filepath to log conversation to (for interactive modes) |
201
236
  | `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
202
237
  | `--config-index` | Index of the configuration to use (default: 0) |
203
238
  | `--remove` | Remove the configuration at the specified index (requires --config and --config-index) |
@@ -209,6 +244,8 @@ You can configure the client using the following options:
209
244
  | `-t, --text` | Open interactive multiline editor for complex prompts |
210
245
  | `-v, --version` | Show version information |
211
246
 
247
+ For a complete reference of all available options, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
248
+
212
249
  ### Interactive Configuration
213
250
 
214
251
  The `--config` option without arguments enters interactive configuration mode, allowing you to add or edit configurations:
@@ -230,6 +267,8 @@ In interactive mode:
230
267
  - For security, your API key is not displayed when editing configurations
231
268
  - When removing a configuration, you'll be asked to confirm before deletion
232
269
 
270
+ For more details on configuring nGPT, see the [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html).
271
+
233
272
  ### Configuration File
234
273
 
235
274
  nGPT uses a configuration file stored in the standard user config directory for your operating system:
@@ -264,6 +303,8 @@ The configuration file uses a JSON list format, allowing you to store multiple c
264
303
  ]
265
304
  ```
266
305
 
306
+ For details on the configuration file format and structure, see the [Configuration Guide](https://nazdridoy.github.io/ngpt/configuration.html).
307
+
267
308
  ### Configuration Priority
268
309
 
269
310
  nGPT determines configuration values in the following order (highest priority first):
@@ -106,6 +106,12 @@ ngpt --config-index 2 "Your prompt here"
106
106
 
107
107
  # Control response generation parameters
108
108
  ngpt --temperature 0.8 --top_p 0.95 --max_length 300 "Write a creative story"
109
+
110
+ # Set a custom system prompt (preprompt)
111
+ ngpt --preprompt "You are a Linux command line expert. Focus on efficient solutions." "How do I find the largest files in a directory?"
112
+
113
+ # Save conversation to a log file (for interactive modes)
114
+ ngpt --interactive --log conversation.log
109
115
  ```
110
116
 
111
117
  ## Environment Variables
@@ -61,6 +61,52 @@ response = client.chat("", messages=messages)
61
61
  print(response)
62
62
  ```
63
63
 
64
+ Using preprompts in the CLI:
65
+
66
+ ```bash
67
+ # Make the model respond as a specific expert
68
+ ngpt --preprompt "You are a Linux command line expert. Focus on efficient solutions." \
69
+ "How do I find the largest files in a directory?"
70
+
71
+ # Set content and formatting constraints
72
+ ngpt --preprompt "Your responses should be concise and include code examples." \
73
+ "How to parse JSON in JavaScript?"
74
+
75
+ # Create a specialized tutor for interactive sessions
76
+ ngpt --interactive --preprompt "You are a Python programming tutor. Explain concepts clearly and provide helpful examples."
77
+ ```
78
+
79
+ ### Conversation Logging
80
+
81
+ Save your conversation history to a file for reference:
82
+
83
+ ```bash
84
+ # Basic interactive session with logging
85
+ ngpt --interactive --log python_tutoring.log
86
+
87
+ # Combine logging with custom system prompt
88
+ ngpt --interactive \
89
+ --preprompt "You are a data science expert helping analyze experimental results." \
90
+ --log data_analysis_session.log
91
+
92
+ # Log a focused session on a specific topic
93
+ ngpt --interactive \
94
+ --preprompt "You are helping plan the architecture for a microservices application." \
95
+ --log architecture_planning.log
96
+ ```
97
+
98
+ The log file contains the complete conversation transcript, including:
99
+ - Session metadata (timestamp, command used)
100
+ - All user messages
101
+ - All AI responses
102
+ - System prompts when custom preprompts are used
103
+
104
+ This is particularly useful for:
105
+ - Documenting important planning discussions
106
+ - Saving educational sessions for later review
107
+ - Keeping records of complex problem-solving processes
108
+ - Sharing conversations with team members
109
+
64
110
  ## Advanced Conversation Management
65
111
 
66
112
  ### Managing Conversation History
@@ -42,6 +42,8 @@ Here are the most commonly used options:
42
42
  | `-c, --code` | Generate clean code without markdown formatting |
43
43
  | `-t, --text` | Open interactive multiline editor for complex prompts |
44
44
  | `-v, --version` | Show version information |
45
+ | `--preprompt` | Set custom system prompt to control AI behavior |
46
+ | `--log` | Set filepath to log conversation to (for interactive modes) |
45
47
  | `--web-search` | Enable web search capability (if supported by your API) |
46
48
  | `--temperature` | Set temperature (controls randomness, default: 0.7) |
47
49
  | `--top_p` | Set top_p (controls diversity, default: 1.0) |
@@ -73,6 +75,36 @@ This opens a continuous chat session where the AI remembers previous exchanges.
73
75
  - Use arrow keys to navigate message history
74
76
  - Press Ctrl+C to exit the session
75
77
 
78
+ You can log your conversation to a file for later reference:
79
+
80
+ ```bash
81
+ ngpt -i --log conversation.log
82
+ ```
83
+
84
+ This saves the entire conversation, including both user inputs and AI responses, to the specified file.
85
+
86
+ ### Custom System Prompts
87
+
88
+ Use custom system prompts to guide the AI's behavior and responses:
89
+
90
+ ```bash
91
+ ngpt --preprompt "You are a Linux command line expert. Focus on efficient solutions." "How do I find the largest files in a directory?"
92
+ ```
93
+
94
+ This replaces the default "You are a helpful assistant" system prompt with your custom instruction.
95
+
96
+ You can also use custom prompts in interactive mode:
97
+
98
+ ```bash
99
+ ngpt -i --preprompt "You are a Python programming tutor. Explain concepts clearly and provide helpful examples."
100
+ ```
101
+
102
+ Custom prompts can be used to:
103
+ - Set the AI's persona or role
104
+ - Provide background information or context
105
+ - Specify output format preferences
106
+ - Set constraints or guidelines
107
+
76
108
  ### Generating Shell Commands
77
109
 
78
110
  Generate and execute shell commands appropriate for your operating system:
@@ -192,6 +224,12 @@ ngpt -c --web-search "function to get current weather using an API"
192
224
 
193
225
  # Use a specific model and no streaming
194
226
  ngpt --model gpt-4o-mini -n "Explain quantum entanglement"
227
+
228
+ # Interactive session with custom prompt and logging
229
+ ngpt -i --preprompt "You are a data science tutor" --log datasci_tutoring.txt
230
+
231
+ # Constrain output format with a custom system prompt
232
+ ngpt --preprompt "Your responses should be concise and include code examples." "How to parse JSON in JavaScript?"
195
233
  ```
196
234
 
197
235
  ### Using a Custom Configuration File
@@ -268,6 +306,9 @@ ngpt "Explain quantum computing for beginners"
268
306
 
269
307
  # Get current information (with web search)
270
308
  ngpt --web-search "What are the latest advancements in AI?"
309
+
310
+ # Learn with a specialized tutor using custom prompt
311
+ ngpt --preprompt "You are an expert physicist explaining concepts to a beginner. Use analogies and simple language." "Explain quantum entanglement"
271
312
  ```
272
313
 
273
314
  ### Productivity
@@ -279,6 +320,9 @@ ngpt -s "find large files over 100MB and list them by size"
279
320
  # Create a structured document
280
321
  ngpt -t
281
322
  # (Enter multiline text for generating a complex document)
323
+
324
+ # Log an important session for reference
325
+ ngpt -i --log project_planning.log --preprompt "You are a project management expert helping plan a software project"
282
326
  ```
283
327
 
284
328
  ## Troubleshooting
@@ -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
  [project]
2
2
  name = "ngpt"
3
- version = "2.1.0"
3
+ version = "2.3.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 = "2.1.0"
116
+ version = "2.3.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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes