ngpt 2.12.0__tar.gz → 2.13.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.
- {ngpt-2.12.0 → ngpt-2.13.0}/CONTRIBUTING.md +10 -1
- {ngpt-2.12.0 → ngpt-2.13.0}/PKG-INFO +54 -28
- {ngpt-2.12.0 → ngpt-2.13.0}/README.md +52 -27
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/CONTRIBUTING.md +12 -1
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/api/cli.md +130 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/configuration.md +4 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/examples/cli_components.md +191 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/usage/cli_framework.md +5 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/usage/cli_usage.md +153 -1
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/args.py +2 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/formatters.py +1 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/main.py +9 -1
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/modes/__init__.py +2 -1
- ngpt-2.13.0/ngpt/cli/modes/rewrite.py +209 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/pyproject.toml +2 -1
- {ngpt-2.12.0 → ngpt-2.13.0}/uv.lock +114 -106
- {ngpt-2.12.0 → ngpt-2.13.0}/.github/workflows/python-publish.yml +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/.gitignore +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/.python-version +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/COMMIT_GUIDELINES.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/LICENSE +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/LICENSE.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/README.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/_config.yml +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/api/README.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/api/cli_config.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/api/client.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/api/config.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/assets/css/style.scss +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/examples/README.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/examples/advanced.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/examples/basic.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/examples/integrations.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/installation.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/overview.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/usage/README.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/usage/cli_config.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/docs/usage/library_usage.md +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/__init__.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/__main__.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/__init__.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/config_manager.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/interactive.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/modes/chat.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/modes/code.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/modes/shell.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/modes/text.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/renderers.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/cli/ui.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/client.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/utils/__init__.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/utils/cli_config.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/utils/config.py +0 -0
- {ngpt-2.12.0 → ngpt-2.13.0}/ngpt/utils/log.py +0 -0
@@ -29,7 +29,12 @@ Thank you for your interest in contributing to NGPT! This document provides guid
|
|
29
29
|
- `config_manager.py` - CLI configuration handling
|
30
30
|
- `formatters.py` - Output formatting logic
|
31
31
|
- `interactive.py` - Interactive mode implementation
|
32
|
-
- `modes/` - Different operational modes
|
32
|
+
- `modes/` - Different operational modes
|
33
|
+
- `chat.py` - Chat mode functionality
|
34
|
+
- `code.py` - Code generation mode
|
35
|
+
- `shell.py` - Shell command generation
|
36
|
+
- `text.py` - Text generation mode
|
37
|
+
- `rewrite.py` - Text rewriting mode
|
33
38
|
- `renderers.py` - Output rendering logic (e.g., markdown)
|
34
39
|
- `ui.py` - User interface elements (e.g., prompts, spinners)
|
35
40
|
- `utils/` - Utility modules
|
@@ -37,6 +42,10 @@ Thank you for your interest in contributing to NGPT! This document provides guid
|
|
37
42
|
- `config.py` - API endpoint and general configuration management
|
38
43
|
- `cli_config.py` - CLI-specific option configuration management
|
39
44
|
- `log.py` - Logging setup and utilities
|
45
|
+
- `docs/` - Documentation files
|
46
|
+
- `api/` - API reference documentation
|
47
|
+
- `examples/` - Example code and usage
|
48
|
+
- `usage/` - Usage guides and tutorials
|
40
49
|
- `.github/` - GitHub workflows and templates
|
41
50
|
- `pyproject.toml` - Project configuration and dependencies
|
42
51
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ngpt
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.13.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
|
@@ -29,6 +29,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
29
|
Classifier: Topic :: Utilities
|
30
30
|
Requires-Python: >=3.8
|
31
31
|
Requires-Dist: prompt-toolkit>=3.0.0
|
32
|
+
Requires-Dist: pyperclip>=1.8.0
|
32
33
|
Requires-Dist: requests>=2.31.0
|
33
34
|
Requires-Dist: rich>=10.0.0
|
34
35
|
Description-Content-Type: text/markdown
|
@@ -103,6 +104,15 @@ ngpt --shell "list all files in the current directory"
|
|
103
104
|
# Read from stdin and use the content in your prompt
|
104
105
|
echo "What is this text about?" | ngpt --stdin "Analyze the following text: {}"
|
105
106
|
|
107
|
+
# Rewrite text to improve quality while preserving tone and meaning
|
108
|
+
echo "your text" | ngpt --rewrite
|
109
|
+
|
110
|
+
# Rewrite text from a command-line argument
|
111
|
+
ngpt --rewrite "your text to rewrite"
|
112
|
+
|
113
|
+
# Use interactive multiline editor to enter text to rewrite
|
114
|
+
ngpt --rewrite
|
115
|
+
|
106
116
|
# Display markdown responses with beautiful formatting
|
107
117
|
ngpt --prettify "Explain markdown syntax with examples"
|
108
118
|
|
@@ -138,10 +148,12 @@ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdri
|
|
138
148
|
- 💬 **Interactive Chat**: Continuous conversation with memory in modern UI
|
139
149
|
- 📊 **Streaming Responses**: Real-time output for better user experience
|
140
150
|
- 🔍 **Web Search**: Integrated with compatible API endpoints
|
151
|
+
- 📥 **Stdin Processing**: Process piped content by using `{}` placeholder in prompts
|
141
152
|
- 🎨 **Markdown Rendering**: Beautiful formatting of markdown and code with syntax highlighting
|
142
153
|
- ⚡ **Real-time Markdown**: Stream responses with live updating syntax highlighting and formatting
|
143
154
|
- ⚙️ **Multiple Configurations**: Cross-platform config system supporting different profiles
|
144
155
|
- 💻 **Shell Command Generation**: OS-aware command execution
|
156
|
+
- 🧠 **Text Rewriting**: Improve text quality while maintaining original tone and meaning
|
145
157
|
- 🧩 **Clean Code Generation**: Output code without markdown or explanations
|
146
158
|
- 📝 **Rich Multiline Editor**: Interactive multiline text input with syntax highlighting and intuitive controls
|
147
159
|
- 🎭 **System Prompts**: Customize model behavior with custom system prompts
|
@@ -349,38 +361,52 @@ For detailed information about building CLI tools with nGPT, see the [CLI Framew
|
|
349
361
|
|
350
362
|
### Command Line Options
|
351
363
|
|
352
|
-
You can configure
|
364
|
+
You can configure nGPT using the following options:
|
365
|
+
|
366
|
+
#### Mode Options (Mutually Exclusive)
|
367
|
+
|
368
|
+
| Option | Description |
|
369
|
+
|--------|-------------|
|
370
|
+
| `-i, --interactive` | Start an interactive chat session with conversation memory and special commands |
|
371
|
+
| `-s, --shell` | Generate and execute shell commands appropriate for your operating system |
|
372
|
+
| `-c, --code` | Generate clean code without markdown formatting or explanations |
|
373
|
+
| `-t, --text` | Open interactive multiline editor for complex prompts with syntax highlighting |
|
374
|
+
| `--stdin` | Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content |
|
375
|
+
| `--rewrite` | Rewrite text to improve quality while preserving original tone and meaning |
|
376
|
+
|
377
|
+
#### Global Options
|
353
378
|
|
354
379
|
| Option | Description |
|
355
380
|
|--------|-------------|
|
356
|
-
| `--api-key` | API key for the service |
|
357
|
-
| `--base-url` | Base URL for the API |
|
358
|
-
| `--model` | Model to use |
|
359
|
-
| `--
|
360
|
-
| `--
|
381
|
+
| `--api-key KEY` | API key for the service |
|
382
|
+
| `--base-url URL` | Base URL for the API |
|
383
|
+
| `--model MODEL` | Model to use |
|
384
|
+
| `--web-search` | Enable web search capability (if your API endpoint supports it) |
|
385
|
+
| `--temperature VALUE` | Set temperature (controls randomness, default: 0.7) |
|
386
|
+
| `--top_p VALUE` | Set top_p (controls diversity, default: 1.0) |
|
387
|
+
| `--max_tokens NUMBER` | Set maximum response length in tokens |
|
388
|
+
| `--preprompt TEXT` | Set custom system prompt to control AI behavior |
|
389
|
+
| `--language LANG` | Programming language to generate code in (for code mode, default: python) |
|
361
390
|
| `--no-stream` | Return the whole response without streaming |
|
362
|
-
| `--
|
363
|
-
| `--
|
364
|
-
| `--
|
365
|
-
| `--
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
|
370
|
-
|
371
|
-
| `--config` | Path to a custom
|
372
|
-
| `--config-index` | Index of the configuration to use (default: 0) |
|
373
|
-
| `--provider` | Provider name to identify the configuration to use
|
391
|
+
| `--prettify` | Render markdown responses and code with syntax highlighting and formatting |
|
392
|
+
| `--stream-prettify` | Enable streaming with markdown rendering (automatically uses Rich renderer) |
|
393
|
+
| `--renderer {auto,rich,glow}` | Select which markdown renderer to use with --prettify (default: auto) |
|
394
|
+
| `--log [FILE]` | Set filepath to log conversation to, or create a temporary log file if no path provided |
|
395
|
+
|
396
|
+
#### Configuration Options
|
397
|
+
|
398
|
+
| Option | Description |
|
399
|
+
|--------|-------------|
|
400
|
+
| `--config [PATH]` | Path to a custom config file or, if no value provided, enter interactive configuration mode |
|
401
|
+
| `--config-index INDEX` | Index of the configuration to use or edit (default: 0) |
|
402
|
+
| `--provider NAME` | Provider name to identify the configuration to use |
|
374
403
|
| `--remove` | Remove the configuration at the specified index (requires --config and --config-index or --provider) |
|
375
|
-
| `--show-config` | Show configuration
|
376
|
-
| `--all` |
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
| `-
|
381
|
-
| `--language` | Programming language to generate code in (for code mode, default: python) |
|
382
|
-
| `--cli-config` | Manage CLI configuration settings (set, get, unset, list, help) |
|
383
|
-
| `-v, --version` | Show version information |
|
404
|
+
| `--show-config` | Show the current configuration(s) and exit |
|
405
|
+
| `--all` | Show details for all configurations (requires --show-config) |
|
406
|
+
| `--list-models` | List all available models for the current configuration and exit |
|
407
|
+
| `--list-renderers` | Show available markdown renderers for use with --prettify |
|
408
|
+
| `--cli-config [COMMAND]` | Manage CLI configuration (set, get, unset, list, help) |
|
409
|
+
| `-v, --version` | Show version information and exit |
|
384
410
|
|
385
411
|
For a complete reference of all available options, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
|
386
412
|
|
@@ -68,6 +68,15 @@ ngpt --shell "list all files in the current directory"
|
|
68
68
|
# Read from stdin and use the content in your prompt
|
69
69
|
echo "What is this text about?" | ngpt --stdin "Analyze the following text: {}"
|
70
70
|
|
71
|
+
# Rewrite text to improve quality while preserving tone and meaning
|
72
|
+
echo "your text" | ngpt --rewrite
|
73
|
+
|
74
|
+
# Rewrite text from a command-line argument
|
75
|
+
ngpt --rewrite "your text to rewrite"
|
76
|
+
|
77
|
+
# Use interactive multiline editor to enter text to rewrite
|
78
|
+
ngpt --rewrite
|
79
|
+
|
71
80
|
# Display markdown responses with beautiful formatting
|
72
81
|
ngpt --prettify "Explain markdown syntax with examples"
|
73
82
|
|
@@ -103,10 +112,12 @@ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdri
|
|
103
112
|
- 💬 **Interactive Chat**: Continuous conversation with memory in modern UI
|
104
113
|
- 📊 **Streaming Responses**: Real-time output for better user experience
|
105
114
|
- 🔍 **Web Search**: Integrated with compatible API endpoints
|
115
|
+
- 📥 **Stdin Processing**: Process piped content by using `{}` placeholder in prompts
|
106
116
|
- 🎨 **Markdown Rendering**: Beautiful formatting of markdown and code with syntax highlighting
|
107
117
|
- ⚡ **Real-time Markdown**: Stream responses with live updating syntax highlighting and formatting
|
108
118
|
- ⚙️ **Multiple Configurations**: Cross-platform config system supporting different profiles
|
109
119
|
- 💻 **Shell Command Generation**: OS-aware command execution
|
120
|
+
- 🧠 **Text Rewriting**: Improve text quality while maintaining original tone and meaning
|
110
121
|
- 🧩 **Clean Code Generation**: Output code without markdown or explanations
|
111
122
|
- 📝 **Rich Multiline Editor**: Interactive multiline text input with syntax highlighting and intuitive controls
|
112
123
|
- 🎭 **System Prompts**: Customize model behavior with custom system prompts
|
@@ -314,38 +325,52 @@ For detailed information about building CLI tools with nGPT, see the [CLI Framew
|
|
314
325
|
|
315
326
|
### Command Line Options
|
316
327
|
|
317
|
-
You can configure
|
328
|
+
You can configure nGPT using the following options:
|
329
|
+
|
330
|
+
#### Mode Options (Mutually Exclusive)
|
331
|
+
|
332
|
+
| Option | Description |
|
333
|
+
|--------|-------------|
|
334
|
+
| `-i, --interactive` | Start an interactive chat session with conversation memory and special commands |
|
335
|
+
| `-s, --shell` | Generate and execute shell commands appropriate for your operating system |
|
336
|
+
| `-c, --code` | Generate clean code without markdown formatting or explanations |
|
337
|
+
| `-t, --text` | Open interactive multiline editor for complex prompts with syntax highlighting |
|
338
|
+
| `--stdin` | Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content |
|
339
|
+
| `--rewrite` | Rewrite text to improve quality while preserving original tone and meaning |
|
340
|
+
|
341
|
+
#### Global Options
|
318
342
|
|
319
343
|
| Option | Description |
|
320
344
|
|--------|-------------|
|
321
|
-
| `--api-key` | API key for the service |
|
322
|
-
| `--base-url` | Base URL for the API |
|
323
|
-
| `--model` | Model to use |
|
324
|
-
| `--
|
325
|
-
| `--
|
345
|
+
| `--api-key KEY` | API key for the service |
|
346
|
+
| `--base-url URL` | Base URL for the API |
|
347
|
+
| `--model MODEL` | Model to use |
|
348
|
+
| `--web-search` | Enable web search capability (if your API endpoint supports it) |
|
349
|
+
| `--temperature VALUE` | Set temperature (controls randomness, default: 0.7) |
|
350
|
+
| `--top_p VALUE` | Set top_p (controls diversity, default: 1.0) |
|
351
|
+
| `--max_tokens NUMBER` | Set maximum response length in tokens |
|
352
|
+
| `--preprompt TEXT` | Set custom system prompt to control AI behavior |
|
353
|
+
| `--language LANG` | Programming language to generate code in (for code mode, default: python) |
|
326
354
|
| `--no-stream` | Return the whole response without streaming |
|
327
|
-
| `--
|
328
|
-
| `--
|
329
|
-
| `--
|
330
|
-
| `--
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
|
335
|
-
|
336
|
-
| `--config` | Path to a custom
|
337
|
-
| `--config-index` | Index of the configuration to use (default: 0) |
|
338
|
-
| `--provider` | Provider name to identify the configuration to use
|
355
|
+
| `--prettify` | Render markdown responses and code with syntax highlighting and formatting |
|
356
|
+
| `--stream-prettify` | Enable streaming with markdown rendering (automatically uses Rich renderer) |
|
357
|
+
| `--renderer {auto,rich,glow}` | Select which markdown renderer to use with --prettify (default: auto) |
|
358
|
+
| `--log [FILE]` | Set filepath to log conversation to, or create a temporary log file if no path provided |
|
359
|
+
|
360
|
+
#### Configuration Options
|
361
|
+
|
362
|
+
| Option | Description |
|
363
|
+
|--------|-------------|
|
364
|
+
| `--config [PATH]` | Path to a custom config file or, if no value provided, enter interactive configuration mode |
|
365
|
+
| `--config-index INDEX` | Index of the configuration to use or edit (default: 0) |
|
366
|
+
| `--provider NAME` | Provider name to identify the configuration to use |
|
339
367
|
| `--remove` | Remove the configuration at the specified index (requires --config and --config-index or --provider) |
|
340
|
-
| `--show-config` | Show configuration
|
341
|
-
| `--all` |
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
| `-
|
346
|
-
| `--language` | Programming language to generate code in (for code mode, default: python) |
|
347
|
-
| `--cli-config` | Manage CLI configuration settings (set, get, unset, list, help) |
|
348
|
-
| `-v, --version` | Show version information |
|
368
|
+
| `--show-config` | Show the current configuration(s) and exit |
|
369
|
+
| `--all` | Show details for all configurations (requires --show-config) |
|
370
|
+
| `--list-models` | List all available models for the current configuration and exit |
|
371
|
+
| `--list-renderers` | Show available markdown renderers for use with --prettify |
|
372
|
+
| `--cli-config [COMMAND]` | Manage CLI configuration (set, get, unset, list, help) |
|
373
|
+
| `-v, --version` | Show version information and exit |
|
349
374
|
|
350
375
|
For a complete reference of all available options, see the [CLI Usage Guide](https://nazdridoy.github.io/ngpt/usage/cli_usage.html).
|
351
376
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
---
|
2
|
+
title: Contributing to NGPT
|
3
|
+
description: Guidelines and instructions for contributing to the NGPT project
|
2
4
|
---
|
3
5
|
|
4
6
|
# Contributing to NGPT
|
@@ -32,7 +34,12 @@ Thank you for your interest in contributing to NGPT! This document provides guid
|
|
32
34
|
- `config_manager.py` - CLI configuration handling
|
33
35
|
- `formatters.py` - Output formatting logic
|
34
36
|
- `interactive.py` - Interactive mode implementation
|
35
|
-
- `modes/` - Different operational modes
|
37
|
+
- `modes/` - Different operational modes
|
38
|
+
- `chat.py` - Chat mode functionality
|
39
|
+
- `code.py` - Code generation mode
|
40
|
+
- `shell.py` - Shell command generation
|
41
|
+
- `text.py` - Text generation mode
|
42
|
+
- `rewrite.py` - Text rewriting mode
|
36
43
|
- `renderers.py` - Output rendering logic (e.g., markdown)
|
37
44
|
- `ui.py` - User interface elements (e.g., prompts, spinners)
|
38
45
|
- `utils/` - Utility modules
|
@@ -40,6 +47,10 @@ Thank you for your interest in contributing to NGPT! This document provides guid
|
|
40
47
|
- `config.py` - API endpoint and general configuration management
|
41
48
|
- `cli_config.py` - CLI-specific option configuration management
|
42
49
|
- `log.py` - Logging setup and utilities
|
50
|
+
- `docs/` - Documentation files
|
51
|
+
- `api/` - API reference documentation
|
52
|
+
- `examples/` - Example code and usage
|
53
|
+
- `usage/` - Usage guides and tutorials
|
43
54
|
- `.github/` - GitHub workflows and templates
|
44
55
|
- `pyproject.toml` - Project configuration and dependencies
|
45
56
|
|
@@ -544,6 +544,136 @@ text_mode(
|
|
544
544
|
)
|
545
545
|
```
|
546
546
|
|
547
|
+
### Rewrite Mode
|
548
|
+
|
549
|
+
```python
|
550
|
+
from ngpt.cli.modes.rewrite import rewrite_mode
|
551
|
+
|
552
|
+
def rewrite_mode(
|
553
|
+
client,
|
554
|
+
args,
|
555
|
+
logger=None
|
556
|
+
)
|
557
|
+
```
|
558
|
+
|
559
|
+
Executes a text rewriting operation to improve text quality while preserving meaning and tone.
|
560
|
+
|
561
|
+
**Parameters:**
|
562
|
+
- `client` (NGPTClient): The initialized client for the operation
|
563
|
+
- `args` (namespace): Parsed command-line arguments including:
|
564
|
+
- `prompt` (str, optional): Text to rewrite from command line
|
565
|
+
- `temperature` (float): Temperature setting (0.0-1.0)
|
566
|
+
- `top_p` (float): Top-p sampling value (0.0-1.0)
|
567
|
+
- `max_tokens` (int, optional): Maximum tokens to generate
|
568
|
+
- `no_stream` (bool): Whether to disable streaming
|
569
|
+
- `prettify` (bool): Whether to prettify markdown output
|
570
|
+
- `stream_prettify` (bool): Enable real-time markdown rendering
|
571
|
+
- `renderer` (str): Markdown renderer to use
|
572
|
+
- `web_search` (bool): Whether to enable web search
|
573
|
+
- `logger` (object, optional): Logger instance
|
574
|
+
|
575
|
+
**Input Methods:**
|
576
|
+
The rewrite mode supports three input methods:
|
577
|
+
1. Stdin (piped input): Content read from stdin if available
|
578
|
+
2. Command-line argument: Text provided via args.prompt
|
579
|
+
3. Multiline editor: If neither stdin nor prompt is available, opens interactive editor
|
580
|
+
|
581
|
+
**Features:**
|
582
|
+
- **Text Quality Improvement**: Fixes grammar, flow, readability while preserving meaning
|
583
|
+
- **Multiline Editor**: Interactive editor with syntax highlighting for entering text when no input is piped or provided as argument
|
584
|
+
- **Clipboard Integration**: Offers to copy rewritten text to clipboard with cross-platform support
|
585
|
+
- **Format Preservation**: Maintains original formatting including code blocks, lists, and markdown
|
586
|
+
|
587
|
+
**Example with Stdin:**
|
588
|
+
```python
|
589
|
+
import sys
|
590
|
+
import subprocess
|
591
|
+
from ngpt import NGPTClient, load_config
|
592
|
+
from ngpt.cli.modes.rewrite import rewrite_mode
|
593
|
+
import argparse
|
594
|
+
|
595
|
+
client = NGPTClient(**load_config())
|
596
|
+
|
597
|
+
# Create args namespace with required parameters
|
598
|
+
args = argparse.Namespace()
|
599
|
+
args.prompt = None
|
600
|
+
args.temperature = 0.7
|
601
|
+
args.top_p = 1.0
|
602
|
+
args.max_tokens = None
|
603
|
+
args.no_stream = False
|
604
|
+
args.prettify = True
|
605
|
+
args.stream_prettify = False
|
606
|
+
args.renderer = 'rich'
|
607
|
+
args.web_search = False
|
608
|
+
|
609
|
+
# Redirect stdin from a string or file
|
610
|
+
original_stdin = sys.stdin
|
611
|
+
sys.stdin = open('text_to_rewrite.txt', 'r')
|
612
|
+
|
613
|
+
# Call rewrite mode
|
614
|
+
rewrite_mode(client=client, args=args)
|
615
|
+
|
616
|
+
# Restore stdin
|
617
|
+
sys.stdin = original_stdin
|
618
|
+
```
|
619
|
+
|
620
|
+
**Example with Command-line Argument:**
|
621
|
+
```python
|
622
|
+
from ngpt import NGPTClient, load_config
|
623
|
+
from ngpt.cli.modes.rewrite import rewrite_mode
|
624
|
+
import argparse
|
625
|
+
|
626
|
+
client = NGPTClient(**load_config())
|
627
|
+
|
628
|
+
# Create args namespace with required parameters
|
629
|
+
args = argparse.Namespace()
|
630
|
+
args.prompt = "We was hoping you could help with this issue what we are having with the server."
|
631
|
+
args.temperature = 0.7
|
632
|
+
args.top_p = 1.0
|
633
|
+
args.max_tokens = None
|
634
|
+
args.no_stream = False
|
635
|
+
args.prettify = True
|
636
|
+
args.stream_prettify = False
|
637
|
+
args.renderer = 'rich'
|
638
|
+
args.web_search = False
|
639
|
+
|
640
|
+
rewrite_mode(
|
641
|
+
client=client,
|
642
|
+
args=args
|
643
|
+
)
|
644
|
+
```
|
645
|
+
|
646
|
+
**Example with Multiline Editor:**
|
647
|
+
```python
|
648
|
+
from ngpt import NGPTClient, load_config
|
649
|
+
from ngpt.cli.modes.rewrite import rewrite_mode
|
650
|
+
import argparse
|
651
|
+
import sys
|
652
|
+
|
653
|
+
client = NGPTClient(**load_config())
|
654
|
+
|
655
|
+
# Create args namespace with required parameters
|
656
|
+
args = argparse.Namespace()
|
657
|
+
args.prompt = None
|
658
|
+
args.temperature = 0.7
|
659
|
+
args.top_p = 1.0
|
660
|
+
args.max_tokens = None
|
661
|
+
args.no_stream = False
|
662
|
+
args.prettify = True
|
663
|
+
args.stream_prettify = False
|
664
|
+
args.renderer = 'rich'
|
665
|
+
args.web_search = False
|
666
|
+
|
667
|
+
# Ensure stdin appears to be a TTY
|
668
|
+
# (This will trigger the multiline editor in a real terminal)
|
669
|
+
# Note: This is just to illustrate how the condition works
|
670
|
+
if sys.stdin.isatty():
|
671
|
+
print("Multiline editor will open in a real terminal")
|
672
|
+
rewrite_mode(client=client, args=args)
|
673
|
+
else:
|
674
|
+
print("This example would open a multiline editor in a real terminal")
|
675
|
+
```
|
676
|
+
|
547
677
|
## Reference Tables
|
548
678
|
|
549
679
|
### Markdown Renderers
|
@@ -124,6 +124,7 @@ You can also set configuration options directly via command-line arguments:
|
|
124
124
|
- `-c, --code`: Generate code.
|
125
125
|
- `--language <lang>`: Specify the programming language for code generation (e.g., `python`, `javascript`, default: `python`).
|
126
126
|
- `-t, --text`: Use a multiline editor for input.
|
127
|
+
- `--stdin`: Read from stdin and use content in your prompt with {} placeholder.
|
127
128
|
- `--no-stream`: Disable streaming output.
|
128
129
|
- `--prettify`: Enable formatted markdown/code output (disables streaming).
|
129
130
|
- `--renderer <name>`: Choose the renderer (`auto`, `rich`, `glow`).
|
@@ -162,6 +163,9 @@ ngpt --interactive --log conversation.log
|
|
162
163
|
|
163
164
|
# Create a temporary log file automatically
|
164
165
|
ngpt --log "Tell me about quantum computing"
|
166
|
+
|
167
|
+
# Process text from stdin using the {} placeholder
|
168
|
+
echo "What is this text about?" | ngpt --stdin "Analyze the following text: {}"
|
165
169
|
```
|
166
170
|
|
167
171
|
## Environment Variables
|
@@ -397,6 +397,197 @@ Save this as `code-review.py` and use it:
|
|
397
397
|
python code-review.py --language javascript --prettify
|
398
398
|
```
|
399
399
|
|
400
|
+
## Building a Text Rewriting Tool
|
401
|
+
|
402
|
+
This example creates a text improvement tool that uses nGPT's rewrite mode to enhance text quality while preserving the original meaning and tone:
|
403
|
+
|
404
|
+
```python
|
405
|
+
#!/usr/bin/env python3
|
406
|
+
import argparse
|
407
|
+
import sys
|
408
|
+
from pathlib import Path
|
409
|
+
from ngpt import NGPTClient
|
410
|
+
from ngpt.utils.config import load_config
|
411
|
+
from ngpt.cli.ui import multiline_editor
|
412
|
+
from ngpt.cli.renderers import prettify_markdown, prettify_streaming_markdown
|
413
|
+
from ngpt.cli.formatters import ColoredHelpFormatter, COLORS
|
414
|
+
|
415
|
+
def main():
|
416
|
+
parser = argparse.ArgumentParser(
|
417
|
+
description="Text improvement assistant",
|
418
|
+
formatter_class=ColoredHelpFormatter
|
419
|
+
)
|
420
|
+
|
421
|
+
# Command line arguments
|
422
|
+
parser.add_argument("text", nargs="?", help="Text to rewrite (optional)")
|
423
|
+
parser.add_argument("--file", "-f", help="Read text from file")
|
424
|
+
parser.add_argument("--output", "-o", help="Save output to file")
|
425
|
+
parser.add_argument("--type", "-t", choices=["formal", "casual", "academic", "creative", "general"],
|
426
|
+
default="general", help="Style of rewriting")
|
427
|
+
parser.add_argument("--stream", "-s", action="store_true",
|
428
|
+
help="Stream results with live updates")
|
429
|
+
parser.add_argument("--prettify", "-p", action="store_true",
|
430
|
+
help="Format output with markdown rendering")
|
431
|
+
|
432
|
+
args = parser.parse_args()
|
433
|
+
|
434
|
+
# Get input text
|
435
|
+
text = ""
|
436
|
+
if args.text:
|
437
|
+
# Text from command line
|
438
|
+
text = args.text
|
439
|
+
elif args.file:
|
440
|
+
# Text from file
|
441
|
+
try:
|
442
|
+
file_path = Path(args.file)
|
443
|
+
if not file_path.exists():
|
444
|
+
print(f"Error: File '{args.file}' not found", file=sys.stderr)
|
445
|
+
sys.exit(1)
|
446
|
+
with open(file_path, 'r') as f:
|
447
|
+
text = f.read()
|
448
|
+
except Exception as e:
|
449
|
+
print(f"Error reading file: {e}", file=sys.stderr)
|
450
|
+
sys.exit(1)
|
451
|
+
else:
|
452
|
+
# No text provided, use multiline editor
|
453
|
+
try:
|
454
|
+
import prompt_toolkit
|
455
|
+
except ImportError:
|
456
|
+
print("Error: prompt_toolkit is required for multiline editor", file=sys.stderr)
|
457
|
+
print("Install with: pip install prompt_toolkit", file=sys.stderr)
|
458
|
+
sys.exit(1)
|
459
|
+
|
460
|
+
print(f"{COLORS['cyan']}Text Improvement Assistant{COLORS['reset']}")
|
461
|
+
print("Enter or paste the text you want to improve.")
|
462
|
+
print("Press Ctrl+D to submit, or Esc to cancel.")
|
463
|
+
|
464
|
+
try:
|
465
|
+
text = multiline_editor(
|
466
|
+
message="Enter text to rewrite:",
|
467
|
+
default_text="",
|
468
|
+
lexer_name="markdown" # Use markdown for general text
|
469
|
+
)
|
470
|
+
except KeyboardInterrupt:
|
471
|
+
print("\nOperation cancelled.")
|
472
|
+
sys.exit(0)
|
473
|
+
|
474
|
+
if not text.strip():
|
475
|
+
print("No text entered. Exiting.")
|
476
|
+
sys.exit(0)
|
477
|
+
|
478
|
+
# Initialize client
|
479
|
+
try:
|
480
|
+
config = load_config()
|
481
|
+
client = NGPTClient(**config)
|
482
|
+
except Exception as e:
|
483
|
+
print(f"{COLORS['yellow']}Error initializing AI client: {e}{COLORS['reset']}",
|
484
|
+
file=sys.stderr)
|
485
|
+
sys.exit(1)
|
486
|
+
|
487
|
+
# Style instructions
|
488
|
+
style_guide = {
|
489
|
+
"formal": "Use formal language, proper grammar, and professional tone.",
|
490
|
+
"casual": "Use conversational, friendly tone while improving clarity.",
|
491
|
+
"academic": "Use academic language with precise terminology and citations where appropriate.",
|
492
|
+
"creative": "Make the text more engaging and vibrant while maintaining meaning.",
|
493
|
+
"general": "Improve clarity and correctness while preserving the original tone."
|
494
|
+
}
|
495
|
+
|
496
|
+
# System prompt for rewriting
|
497
|
+
system_prompt = f"""You are a text improvement assistant.
|
498
|
+
Rewrite the text to improve quality while preserving the original meaning and intent.
|
499
|
+
{style_guide[args.type]}
|
500
|
+
Focus on:
|
501
|
+
1. Fixing grammar and spelling errors
|
502
|
+
2. Improving clarity and readability
|
503
|
+
3. Enhancing flow and structure
|
504
|
+
4. Maintaining the author's voice and meaning
|
505
|
+
Return ONLY the improved text without explanations or notes."""
|
506
|
+
|
507
|
+
print(f"\n{COLORS['cyan']}Rewriting text ({args.type} style)...{COLORS['reset']}")
|
508
|
+
|
509
|
+
# Process with AI
|
510
|
+
try:
|
511
|
+
if args.stream:
|
512
|
+
# Stream with live updates
|
513
|
+
if args.prettify:
|
514
|
+
streamer = prettify_streaming_markdown(
|
515
|
+
renderer='rich',
|
516
|
+
header_text="Improved Text"
|
517
|
+
)
|
518
|
+
|
519
|
+
full_response = ""
|
520
|
+
for chunk in client.chat(
|
521
|
+
text,
|
522
|
+
system_prompt=system_prompt,
|
523
|
+
stream=True
|
524
|
+
):
|
525
|
+
full_response += chunk
|
526
|
+
streamer.update_content(full_response)
|
527
|
+
|
528
|
+
improved_text = full_response
|
529
|
+
else:
|
530
|
+
# Simple streaming
|
531
|
+
print(f"\n{COLORS['green']}Improved Text:{COLORS['reset']}\n")
|
532
|
+
improved_text = ""
|
533
|
+
for chunk in client.chat(
|
534
|
+
text,
|
535
|
+
system_prompt=system_prompt,
|
536
|
+
stream=True
|
537
|
+
):
|
538
|
+
improved_text += chunk
|
539
|
+
print(chunk, end="", flush=True)
|
540
|
+
print() # Final newline
|
541
|
+
else:
|
542
|
+
# Get complete response
|
543
|
+
improved_text = client.chat(
|
544
|
+
text,
|
545
|
+
system_prompt=system_prompt
|
546
|
+
)
|
547
|
+
|
548
|
+
if args.prettify:
|
549
|
+
print(f"\n{COLORS['green']}Improved Text:{COLORS['reset']}\n")
|
550
|
+
print(prettify_markdown(improved_text))
|
551
|
+
else:
|
552
|
+
print(f"\n{COLORS['green']}Improved Text:{COLORS['reset']}\n")
|
553
|
+
print(improved_text)
|
554
|
+
|
555
|
+
# Save to file if requested
|
556
|
+
if args.output:
|
557
|
+
try:
|
558
|
+
with open(args.output, 'w') as f:
|
559
|
+
f.write(improved_text)
|
560
|
+
print(f"\n{COLORS['green']}Improved text saved to {args.output}{COLORS['reset']}")
|
561
|
+
except Exception as e:
|
562
|
+
print(f"{COLORS['yellow']}Error saving to file: {e}{COLORS['reset']}",
|
563
|
+
file=sys.stderr)
|
564
|
+
|
565
|
+
except KeyboardInterrupt:
|
566
|
+
print("\nOperation cancelled.")
|
567
|
+
except Exception as e:
|
568
|
+
print(f"\n{COLORS['yellow']}Error: {e}{COLORS['reset']}", file=sys.stderr)
|
569
|
+
sys.exit(1)
|
570
|
+
|
571
|
+
if __name__ == "__main__":
|
572
|
+
main()
|
573
|
+
```
|
574
|
+
|
575
|
+
Save this as `text-improver.py` and use it like:
|
576
|
+
|
577
|
+
```bash
|
578
|
+
# Use multiline editor for input
|
579
|
+
python text-improver.py --type formal --prettify
|
580
|
+
|
581
|
+
# Provide text directly from command line
|
582
|
+
python text-improver.py "I aint never seen nothing like it" --type formal --prettify
|
583
|
+
|
584
|
+
# Read from file and save to another file
|
585
|
+
python text-improver.py --file rough_draft.txt --output improved.txt --type academic
|
586
|
+
|
587
|
+
# Stream results with live updates
|
588
|
+
python text-improver.py --file notes.txt --type casual --stream --prettify
|
589
|
+
```
|
590
|
+
|
400
591
|
## Advanced CLI Configuration Example
|
401
592
|
|
402
593
|
Create a CLI tool with persistent configuration:
|
@@ -259,6 +259,7 @@ from ngpt.cli.modes.chat import chat_mode
|
|
259
259
|
from ngpt.cli.modes.code import code_mode
|
260
260
|
from ngpt.cli.modes.shell import shell_mode
|
261
261
|
from ngpt.cli.modes.text import text_mode
|
262
|
+
from ngpt.cli.modes.rewrite import rewrite_mode
|
262
263
|
|
263
264
|
# Initialize the client
|
264
265
|
client = NGPTClient(**load_config())
|
@@ -276,6 +277,10 @@ shell_mode(client, prompt="Find all PNG files in current directory")
|
|
276
277
|
|
277
278
|
# Text mode - handle multiline text input
|
278
279
|
text_mode(client, prettify=True)
|
280
|
+
|
281
|
+
# Rewrite mode - improve text quality while preserving meaning and tone
|
282
|
+
rewrite_mode(client, text="We was hoping you could help with this issue what we are having.",
|
283
|
+
prettify=True, stream=True)
|
279
284
|
```
|
280
285
|
|
281
286
|
Each mode handler encapsulates the specialized behavior for that particular mode of operation.
|