ngpt 2.4.0__py3-none-any.whl → 2.5.1__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 +262 -17
- ngpt/client.py +22 -3
- {ngpt-2.4.0.dist-info → ngpt-2.5.1.dist-info}/METADATA +16 -1
- ngpt-2.5.1.dist-info/RECORD +9 -0
- ngpt-2.4.0.dist-info/RECORD +0 -9
- {ngpt-2.4.0.dist-info → ngpt-2.5.1.dist-info}/WHEEL +0 -0
- {ngpt-2.4.0.dist-info → ngpt-2.5.1.dist-info}/entry_points.txt +0 -0
- {ngpt-2.4.0.dist-info → ngpt-2.5.1.dist-info}/licenses/LICENSE +0 -0
ngpt/cli.py
CHANGED
@@ -5,6 +5,23 @@ from .client import NGPTClient
|
|
5
5
|
from .config import load_config, get_config_path, load_configs, add_config_entry, remove_config_entry
|
6
6
|
from . import __version__
|
7
7
|
|
8
|
+
# Try to import markdown rendering libraries
|
9
|
+
try:
|
10
|
+
import rich
|
11
|
+
from rich.markdown import Markdown
|
12
|
+
from rich.console import Console
|
13
|
+
HAS_RICH = True
|
14
|
+
except ImportError:
|
15
|
+
HAS_RICH = False
|
16
|
+
|
17
|
+
# Try to import the glow command if available
|
18
|
+
def has_glow_installed():
|
19
|
+
"""Check if glow is installed in the system."""
|
20
|
+
import shutil
|
21
|
+
return shutil.which("glow") is not None
|
22
|
+
|
23
|
+
HAS_GLOW = has_glow_installed()
|
24
|
+
|
8
25
|
# ANSI color codes for terminal output
|
9
26
|
COLORS = {
|
10
27
|
"reset": "\033[0m",
|
@@ -68,6 +85,162 @@ if not HAS_COLOR:
|
|
68
85
|
for key in COLORS:
|
69
86
|
COLORS[key] = ""
|
70
87
|
|
88
|
+
def has_markdown_renderer(renderer='auto'):
|
89
|
+
"""Check if the specified markdown renderer is available.
|
90
|
+
|
91
|
+
Args:
|
92
|
+
renderer (str): Which renderer to check: 'auto', 'rich', or 'glow'
|
93
|
+
|
94
|
+
Returns:
|
95
|
+
bool: True if the renderer is available, False otherwise
|
96
|
+
"""
|
97
|
+
if renderer == 'auto':
|
98
|
+
return HAS_RICH or HAS_GLOW
|
99
|
+
elif renderer == 'rich':
|
100
|
+
return HAS_RICH
|
101
|
+
elif renderer == 'glow':
|
102
|
+
return HAS_GLOW
|
103
|
+
else:
|
104
|
+
return False
|
105
|
+
|
106
|
+
def show_available_renderers():
|
107
|
+
"""Show which markdown renderers are available and their status."""
|
108
|
+
print(f"\n{COLORS['cyan']}{COLORS['bold']}Available Markdown Renderers:{COLORS['reset']}")
|
109
|
+
|
110
|
+
if HAS_GLOW:
|
111
|
+
print(f" {COLORS['green']}✓ Glow{COLORS['reset']} - Terminal-based Markdown renderer")
|
112
|
+
else:
|
113
|
+
print(f" {COLORS['yellow']}✗ Glow{COLORS['reset']} - Not installed (https://github.com/charmbracelet/glow)")
|
114
|
+
|
115
|
+
if HAS_RICH:
|
116
|
+
print(f" {COLORS['green']}✓ Rich{COLORS['reset']} - Python library for terminal formatting (Recommended)")
|
117
|
+
else:
|
118
|
+
print(f" {COLORS['yellow']}✗ Rich{COLORS['reset']} - Not installed (pip install rich)")
|
119
|
+
|
120
|
+
if not HAS_GLOW and not HAS_RICH:
|
121
|
+
print(f"\n{COLORS['yellow']}To enable prettified markdown output, install one of the above renderers.{COLORS['reset']}")
|
122
|
+
else:
|
123
|
+
renderers = []
|
124
|
+
if HAS_RICH:
|
125
|
+
renderers.append("rich")
|
126
|
+
if HAS_GLOW:
|
127
|
+
renderers.append("glow")
|
128
|
+
print(f"\n{COLORS['green']}Usage examples:{COLORS['reset']}")
|
129
|
+
print(f" ngpt --prettify \"Your prompt here\" {COLORS['gray']}# Beautify markdown responses{COLORS['reset']}")
|
130
|
+
print(f" ngpt -c --prettify \"Write a sort function\" {COLORS['gray']}# Syntax highlight generated code{COLORS['reset']}")
|
131
|
+
if renderers:
|
132
|
+
renderer = renderers[0]
|
133
|
+
print(f" ngpt --prettify --renderer={renderer} \"Your prompt\" {COLORS['gray']}# Specify renderer{COLORS['reset']}")
|
134
|
+
|
135
|
+
print("")
|
136
|
+
|
137
|
+
def warn_if_no_markdown_renderer(renderer='auto'):
|
138
|
+
"""Warn the user if the specified markdown renderer is not available.
|
139
|
+
|
140
|
+
Args:
|
141
|
+
renderer (str): Which renderer to check: 'auto', 'rich', or 'glow'
|
142
|
+
|
143
|
+
Returns:
|
144
|
+
bool: True if the renderer is available, False otherwise
|
145
|
+
"""
|
146
|
+
if has_markdown_renderer(renderer):
|
147
|
+
return True
|
148
|
+
|
149
|
+
if renderer == 'auto':
|
150
|
+
print(f"{COLORS['yellow']}Warning: No markdown rendering library available.{COLORS['reset']}")
|
151
|
+
print(f"{COLORS['yellow']}Install 'rich' package with: pip install rich{COLORS['reset']}")
|
152
|
+
print(f"{COLORS['yellow']}Or install 'glow' from https://github.com/charmbracelet/glow{COLORS['reset']}")
|
153
|
+
elif renderer == 'rich':
|
154
|
+
print(f"{COLORS['yellow']}Warning: Rich is not available.{COLORS['reset']}")
|
155
|
+
print(f"{COLORS['yellow']}Install with: pip install rich{COLORS['reset']}")
|
156
|
+
elif renderer == 'glow':
|
157
|
+
print(f"{COLORS['yellow']}Warning: Glow is not available.{COLORS['reset']}")
|
158
|
+
print(f"{COLORS['yellow']}Install from https://github.com/charmbracelet/glow{COLORS['reset']}")
|
159
|
+
else:
|
160
|
+
print(f"{COLORS['yellow']}Error: Invalid renderer '{renderer}'. Use 'auto', 'rich', or 'glow'.{COLORS['reset']}")
|
161
|
+
|
162
|
+
return False
|
163
|
+
|
164
|
+
def prettify_markdown(text, renderer='auto'):
|
165
|
+
"""Render markdown text with beautiful formatting using either Rich or Glow.
|
166
|
+
|
167
|
+
The function handles both general markdown and code blocks with syntax highlighting.
|
168
|
+
For code generation mode, it automatically wraps the code in markdown code blocks.
|
169
|
+
|
170
|
+
Args:
|
171
|
+
text (str): Markdown text to render
|
172
|
+
renderer (str): Which renderer to use: 'auto', 'rich', or 'glow'
|
173
|
+
|
174
|
+
Returns:
|
175
|
+
bool: True if rendering was successful, False otherwise
|
176
|
+
"""
|
177
|
+
# For 'auto', prefer rich if available, otherwise use glow
|
178
|
+
if renderer == 'auto':
|
179
|
+
if HAS_RICH:
|
180
|
+
return prettify_markdown(text, 'rich')
|
181
|
+
elif HAS_GLOW:
|
182
|
+
return prettify_markdown(text, 'glow')
|
183
|
+
else:
|
184
|
+
return False
|
185
|
+
|
186
|
+
# Use glow for rendering
|
187
|
+
elif renderer == 'glow':
|
188
|
+
if not HAS_GLOW:
|
189
|
+
print(f"{COLORS['yellow']}Warning: Glow is not available. Install from https://github.com/charmbracelet/glow{COLORS['reset']}")
|
190
|
+
# Fall back to rich if available
|
191
|
+
if HAS_RICH:
|
192
|
+
print(f"{COLORS['yellow']}Falling back to Rich renderer.{COLORS['reset']}")
|
193
|
+
return prettify_markdown(text, 'rich')
|
194
|
+
return False
|
195
|
+
|
196
|
+
# Use glow
|
197
|
+
import tempfile
|
198
|
+
import subprocess
|
199
|
+
|
200
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as temp:
|
201
|
+
temp_filename = temp.name
|
202
|
+
temp.write(text)
|
203
|
+
|
204
|
+
try:
|
205
|
+
# Execute glow on the temporary file
|
206
|
+
subprocess.run(["glow", temp_filename], check=True)
|
207
|
+
os.unlink(temp_filename)
|
208
|
+
return True
|
209
|
+
except Exception as e:
|
210
|
+
print(f"{COLORS['yellow']}Error using glow: {str(e)}{COLORS['reset']}")
|
211
|
+
os.unlink(temp_filename)
|
212
|
+
|
213
|
+
# Fall back to rich if available
|
214
|
+
if HAS_RICH:
|
215
|
+
print(f"{COLORS['yellow']}Falling back to Rich renderer.{COLORS['reset']}")
|
216
|
+
return prettify_markdown(text, 'rich')
|
217
|
+
return False
|
218
|
+
|
219
|
+
# Use rich for rendering
|
220
|
+
elif renderer == 'rich':
|
221
|
+
if not HAS_RICH:
|
222
|
+
print(f"{COLORS['yellow']}Warning: Rich is not available. Install with: pip install rich{COLORS['reset']}")
|
223
|
+
# Fall back to glow if available
|
224
|
+
if HAS_GLOW:
|
225
|
+
print(f"{COLORS['yellow']}Falling back to Glow renderer.{COLORS['reset']}")
|
226
|
+
return prettify_markdown(text, 'glow')
|
227
|
+
return False
|
228
|
+
|
229
|
+
# Use rich
|
230
|
+
try:
|
231
|
+
console = Console()
|
232
|
+
md = Markdown(text)
|
233
|
+
console.print(md)
|
234
|
+
return True
|
235
|
+
except Exception as e:
|
236
|
+
print(f"{COLORS['yellow']}Error using rich for markdown: {str(e)}{COLORS['reset']}")
|
237
|
+
return False
|
238
|
+
|
239
|
+
# Invalid renderer specified
|
240
|
+
else:
|
241
|
+
print(f"{COLORS['yellow']}Error: Invalid renderer '{renderer}'. Use 'auto', 'rich', or 'glow'.{COLORS['reset']}")
|
242
|
+
return False
|
243
|
+
|
71
244
|
# Custom help formatter with color support
|
72
245
|
class ColoredHelpFormatter(argparse.HelpFormatter):
|
73
246
|
"""Help formatter that properly handles ANSI color codes without breaking alignment."""
|
@@ -332,7 +505,7 @@ def check_config(config):
|
|
332
505
|
|
333
506
|
return True
|
334
507
|
|
335
|
-
def interactive_chat_session(client, web_search=False, no_stream=False, temperature=0.7, top_p=1.0, max_tokens=None, log_file=None, preprompt=None):
|
508
|
+
def interactive_chat_session(client, web_search=False, no_stream=False, temperature=0.7, top_p=1.0, max_tokens=None, log_file=None, preprompt=None, prettify=False, renderer='auto'):
|
336
509
|
"""Run an interactive chat session with conversation history."""
|
337
510
|
# Get terminal width for better formatting
|
338
511
|
try:
|
@@ -380,6 +553,14 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
380
553
|
|
381
554
|
# Initialize conversation history
|
382
555
|
system_prompt = preprompt if preprompt else "You are a helpful assistant."
|
556
|
+
|
557
|
+
# Add markdown formatting instruction to system prompt if prettify is enabled
|
558
|
+
if prettify:
|
559
|
+
if system_prompt:
|
560
|
+
system_prompt += " You can use markdown formatting in your responses where appropriate."
|
561
|
+
else:
|
562
|
+
system_prompt = "You are a helpful assistant. You can use markdown formatting in your responses where appropriate."
|
563
|
+
|
383
564
|
conversation = []
|
384
565
|
system_message = {"role": "system", "content": system_prompt}
|
385
566
|
conversation.append(system_message)
|
@@ -492,15 +673,24 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
492
673
|
else:
|
493
674
|
print(f"\n{ngpt_header()}: {COLORS['reset']}", flush=True)
|
494
675
|
|
676
|
+
# If prettify is enabled, we need to disable streaming to collect the full response
|
677
|
+
should_stream = not no_stream and not prettify
|
678
|
+
|
679
|
+
# If prettify is enabled with streaming, inform the user
|
680
|
+
if prettify and not no_stream:
|
681
|
+
print(f"\n{COLORS['yellow']}Note: Streaming disabled to enable markdown rendering.{COLORS['reset']}")
|
682
|
+
print(f"\n{ngpt_header()}: {COLORS['reset']}", flush=True)
|
683
|
+
|
495
684
|
# Get AI response with conversation history
|
496
685
|
response = client.chat(
|
497
686
|
prompt=user_input,
|
498
687
|
messages=conversation,
|
499
|
-
stream=
|
688
|
+
stream=should_stream,
|
500
689
|
web_search=web_search,
|
501
690
|
temperature=temperature,
|
502
691
|
top_p=top_p,
|
503
|
-
max_tokens=max_tokens
|
692
|
+
max_tokens=max_tokens,
|
693
|
+
markdown_format=prettify
|
504
694
|
)
|
505
695
|
|
506
696
|
# Add AI response to conversation history
|
@@ -508,9 +698,12 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
508
698
|
assistant_message = {"role": "assistant", "content": response}
|
509
699
|
conversation.append(assistant_message)
|
510
700
|
|
511
|
-
# Print response if not streamed
|
512
|
-
if no_stream:
|
513
|
-
|
701
|
+
# Print response if not streamed (either due to no_stream or prettify)
|
702
|
+
if no_stream or prettify:
|
703
|
+
if prettify:
|
704
|
+
prettify_markdown(response, renderer)
|
705
|
+
else:
|
706
|
+
print(response)
|
514
707
|
|
515
708
|
# Log assistant response if logging is enabled
|
516
709
|
if log_handle:
|
@@ -567,6 +760,7 @@ def main():
|
|
567
760
|
config_group.add_argument('--show-config', action='store_true', help='Show the current configuration(s) and exit')
|
568
761
|
config_group.add_argument('--all', action='store_true', help='Show details for all configurations (requires --show-config)')
|
569
762
|
config_group.add_argument('--list-models', action='store_true', help='List all available models for the current configuration and exit')
|
763
|
+
config_group.add_argument('--list-renderers', action='store_true', help='Show available markdown renderers for use with --prettify')
|
570
764
|
|
571
765
|
# Global options
|
572
766
|
global_group = parser.add_argument_group('Global Options')
|
@@ -587,6 +781,10 @@ def main():
|
|
587
781
|
help='Set filepath to log conversation to (For interactive modes)')
|
588
782
|
global_group.add_argument('--preprompt',
|
589
783
|
help='Set custom system prompt to control AI behavior')
|
784
|
+
global_group.add_argument('--prettify', action='store_const', const='auto',
|
785
|
+
help='Render markdown responses and code with syntax highlighting and formatting')
|
786
|
+
global_group.add_argument('--renderer', choices=['auto', 'rich', 'glow'], default='auto',
|
787
|
+
help='Select which markdown renderer to use with --prettify (auto, rich, or glow)')
|
590
788
|
|
591
789
|
# Mode flags (mutually exclusive)
|
592
790
|
mode_group = parser.add_argument_group('Modes (mutually exclusive)')
|
@@ -609,6 +807,11 @@ def main():
|
|
609
807
|
if args.all and not args.show_config:
|
610
808
|
parser.error("--all can only be used with --show-config")
|
611
809
|
|
810
|
+
# Handle --renderers flag to show available markdown renderers
|
811
|
+
if args.list_renderers:
|
812
|
+
show_available_renderers()
|
813
|
+
return
|
814
|
+
|
612
815
|
# Check for mutual exclusivity between --config-index and --provider
|
613
816
|
if args.config_index != 0 and args.provider:
|
614
817
|
parser.error("--config-index and --provider cannot be used together")
|
@@ -808,6 +1011,17 @@ def main():
|
|
808
1011
|
if not args.show_config and not args.list_models and not check_config(active_config):
|
809
1012
|
return
|
810
1013
|
|
1014
|
+
# Check if --prettify is used but no markdown renderer is available
|
1015
|
+
# This will warn the user immediately if they request prettify but don't have the tools
|
1016
|
+
has_renderer = True
|
1017
|
+
if args.prettify:
|
1018
|
+
has_renderer = warn_if_no_markdown_renderer(args.renderer)
|
1019
|
+
if not has_renderer:
|
1020
|
+
# Set a flag to disable prettify since we already warned the user
|
1021
|
+
print(f"{COLORS['yellow']}Continuing without markdown rendering.{COLORS['reset']}")
|
1022
|
+
show_available_renderers()
|
1023
|
+
args.prettify = False
|
1024
|
+
|
811
1025
|
# Initialize client using the potentially overridden active_config
|
812
1026
|
client = NGPTClient(**active_config)
|
813
1027
|
|
@@ -834,7 +1048,7 @@ def main():
|
|
834
1048
|
# Interactive chat mode
|
835
1049
|
interactive_chat_session(client, web_search=args.web_search, no_stream=args.no_stream,
|
836
1050
|
temperature=args.temperature, top_p=args.top_p,
|
837
|
-
max_tokens=args.max_tokens, log_file=args.log, preprompt=args.preprompt)
|
1051
|
+
max_tokens=args.max_tokens, log_file=args.log, preprompt=args.preprompt, prettify=args.prettify, renderer=args.renderer)
|
838
1052
|
elif args.shell:
|
839
1053
|
if args.prompt is None:
|
840
1054
|
try:
|
@@ -886,9 +1100,14 @@ def main():
|
|
886
1100
|
|
887
1101
|
generated_code = client.generate_code(prompt, args.language, web_search=args.web_search,
|
888
1102
|
temperature=args.temperature, top_p=args.top_p,
|
889
|
-
max_tokens=args.max_tokens
|
1103
|
+
max_tokens=args.max_tokens,
|
1104
|
+
markdown_format=args.prettify)
|
890
1105
|
if generated_code:
|
891
|
-
|
1106
|
+
if args.prettify:
|
1107
|
+
print("\nGenerated code:")
|
1108
|
+
prettify_markdown(generated_code, args.renderer)
|
1109
|
+
else:
|
1110
|
+
print(f"\nGenerated code:\n{generated_code}")
|
892
1111
|
|
893
1112
|
elif args.text:
|
894
1113
|
if args.prompt is not None:
|
@@ -1006,12 +1225,25 @@ def main():
|
|
1006
1225
|
{"role": "system", "content": args.preprompt},
|
1007
1226
|
{"role": "user", "content": prompt}
|
1008
1227
|
]
|
1228
|
+
|
1229
|
+
# If prettify is enabled, we need to disable streaming to collect the full response
|
1230
|
+
should_stream = not args.no_stream and not args.prettify
|
1231
|
+
|
1232
|
+
# If prettify is enabled with streaming, inform the user
|
1233
|
+
if args.prettify and not args.no_stream:
|
1234
|
+
print(f"{COLORS['yellow']}Note: Streaming disabled to enable markdown rendering.{COLORS['reset']}")
|
1009
1235
|
|
1010
|
-
response = client.chat(prompt, stream=
|
1236
|
+
response = client.chat(prompt, stream=should_stream, web_search=args.web_search,
|
1011
1237
|
temperature=args.temperature, top_p=args.top_p,
|
1012
|
-
max_tokens=args.max_tokens, messages=messages
|
1013
|
-
|
1014
|
-
|
1238
|
+
max_tokens=args.max_tokens, messages=messages,
|
1239
|
+
markdown_format=args.prettify)
|
1240
|
+
|
1241
|
+
# Handle non-stream response (either because no_stream was set or prettify forced it)
|
1242
|
+
if (args.no_stream or args.prettify) and response:
|
1243
|
+
if args.prettify:
|
1244
|
+
prettify_markdown(response, args.renderer)
|
1245
|
+
else:
|
1246
|
+
print(response)
|
1015
1247
|
|
1016
1248
|
else:
|
1017
1249
|
# Default to chat mode
|
@@ -1032,12 +1264,25 @@ def main():
|
|
1032
1264
|
{"role": "system", "content": args.preprompt},
|
1033
1265
|
{"role": "user", "content": prompt}
|
1034
1266
|
]
|
1267
|
+
|
1268
|
+
# If prettify is enabled, we need to disable streaming to collect the full response
|
1269
|
+
should_stream = not args.no_stream and not args.prettify
|
1270
|
+
|
1271
|
+
# If prettify is enabled with streaming, inform the user
|
1272
|
+
if args.prettify and not args.no_stream:
|
1273
|
+
print(f"{COLORS['yellow']}Note: Streaming disabled to enable markdown rendering.{COLORS['reset']}")
|
1035
1274
|
|
1036
|
-
response = client.chat(prompt, stream=
|
1275
|
+
response = client.chat(prompt, stream=should_stream, web_search=args.web_search,
|
1037
1276
|
temperature=args.temperature, top_p=args.top_p,
|
1038
|
-
max_tokens=args.max_tokens, messages=messages
|
1039
|
-
|
1040
|
-
|
1277
|
+
max_tokens=args.max_tokens, messages=messages,
|
1278
|
+
markdown_format=args.prettify)
|
1279
|
+
|
1280
|
+
# Handle non-stream response (either because no_stream was set or prettify forced it)
|
1281
|
+
if (args.no_stream or args.prettify) and response:
|
1282
|
+
if args.prettify:
|
1283
|
+
prettify_markdown(response, args.renderer)
|
1284
|
+
else:
|
1285
|
+
print(response)
|
1041
1286
|
|
1042
1287
|
except KeyboardInterrupt:
|
1043
1288
|
print("\nOperation cancelled by user. Exiting gracefully.")
|
ngpt/client.py
CHANGED
@@ -33,6 +33,7 @@ class NGPTClient:
|
|
33
33
|
top_p: float = 1.0,
|
34
34
|
messages: Optional[List[Dict[str, str]]] = None,
|
35
35
|
web_search: bool = False,
|
36
|
+
markdown_format: bool = False,
|
36
37
|
**kwargs
|
37
38
|
) -> str:
|
38
39
|
"""
|
@@ -46,6 +47,7 @@ class NGPTClient:
|
|
46
47
|
top_p: Controls diversity via nucleus sampling
|
47
48
|
messages: Optional list of message objects to override default behavior
|
48
49
|
web_search: Whether to enable web search capability
|
50
|
+
markdown_format: If True, allow markdown-formatted responses, otherwise plain text
|
49
51
|
**kwargs: Additional arguments to pass to the API
|
50
52
|
|
51
53
|
Returns:
|
@@ -56,7 +58,11 @@ class NGPTClient:
|
|
56
58
|
return ""
|
57
59
|
|
58
60
|
if messages is None:
|
59
|
-
|
61
|
+
if markdown_format:
|
62
|
+
system_message = {"role": "system", "content": "You can use markdown formatting in your responses where appropriate."}
|
63
|
+
messages = [system_message, {"role": "user", "content": prompt}]
|
64
|
+
else:
|
65
|
+
messages = [{"role": "user", "content": prompt}]
|
60
66
|
|
61
67
|
# Prepare API parameters
|
62
68
|
payload = {
|
@@ -241,7 +247,8 @@ Command:"""
|
|
241
247
|
web_search: bool = False,
|
242
248
|
temperature: float = 0.4,
|
243
249
|
top_p: float = 0.95,
|
244
|
-
max_tokens: Optional[int] = None
|
250
|
+
max_tokens: Optional[int] = None,
|
251
|
+
markdown_format: bool = False
|
245
252
|
) -> str:
|
246
253
|
"""
|
247
254
|
Generate code based on the prompt.
|
@@ -253,6 +260,7 @@ Command:"""
|
|
253
260
|
temperature: Controls randomness in the response
|
254
261
|
top_p: Controls diversity via nucleus sampling
|
255
262
|
max_tokens: Maximum number of tokens to generate
|
263
|
+
markdown_format: If True, request markdown-formatted code, otherwise plain text
|
256
264
|
|
257
265
|
Returns:
|
258
266
|
The generated code
|
@@ -262,7 +270,18 @@ Command:"""
|
|
262
270
|
print("Error: API key is not set. Please configure your API key in the config file or provide it with --api-key.")
|
263
271
|
return ""
|
264
272
|
|
265
|
-
|
273
|
+
if markdown_format:
|
274
|
+
system_prompt = f"""Your Role: Provide only code as output without any description with proper markdown formatting.
|
275
|
+
IMPORTANT: Format the code using markdown code blocks with the appropriate language syntax highlighting.
|
276
|
+
IMPORTANT: You must use markdown code blocks. with ```{language}
|
277
|
+
If there is a lack of details, provide most logical solution. You are not allowed to ask for more details.
|
278
|
+
Ignore any potential risk of errors or confusion.
|
279
|
+
|
280
|
+
Language: {language}
|
281
|
+
Request: {prompt}
|
282
|
+
Code:"""
|
283
|
+
else:
|
284
|
+
system_prompt = f"""Your Role: Provide only code as output without any description.
|
266
285
|
IMPORTANT: Provide only plain text without Markdown formatting.
|
267
286
|
IMPORTANT: Do not include markdown formatting.
|
268
287
|
If there is a lack of details, provide most logical solution. You are not allowed to ask for more details.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ngpt
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.5.1
|
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
|
@@ -30,6 +30,8 @@ Classifier: Topic :: Utilities
|
|
30
30
|
Requires-Python: >=3.8
|
31
31
|
Requires-Dist: prompt-toolkit>=3.0.0
|
32
32
|
Requires-Dist: requests>=2.31.0
|
33
|
+
Provides-Extra: prettify
|
34
|
+
Requires-Dist: rich>=10.0.0; extra == 'prettify'
|
33
35
|
Description-Content-Type: text/markdown
|
34
36
|
|
35
37
|
# nGPT
|
@@ -76,9 +78,18 @@ ngpt -n "Tell me about quantum computing"
|
|
76
78
|
# Generate code
|
77
79
|
ngpt --code "function to calculate the Fibonacci sequence"
|
78
80
|
|
81
|
+
# Generate code with syntax highlighting
|
82
|
+
ngpt --code --prettify "function to calculate the Fibonacci sequence"
|
83
|
+
|
79
84
|
# Generate and execute shell commands
|
80
85
|
ngpt --shell "list all files in the current directory"
|
81
86
|
|
87
|
+
# Display markdown responses with beautiful formatting
|
88
|
+
ngpt --prettify "Explain markdown syntax with examples"
|
89
|
+
|
90
|
+
# Use a specific markdown renderer
|
91
|
+
ngpt --prettify --renderer=rich "Create a markdown table"
|
92
|
+
|
82
93
|
# Use multiline editor for complex prompts
|
83
94
|
ngpt --text
|
84
95
|
|
@@ -99,6 +110,7 @@ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdri
|
|
99
110
|
- 💬 **Interactive Chat**: Continuous conversation with memory in modern UI
|
100
111
|
- 📊 **Streaming Responses**: Real-time output for better user experience
|
101
112
|
- 🔍 **Web Search**: Integrated with compatible API endpoints
|
113
|
+
- 🎨 **Markdown Rendering**: Beautiful formatting of markdown and code with syntax highlighting
|
102
114
|
- ⚙️ **Multiple Configurations**: Cross-platform config system supporting different profiles
|
103
115
|
- 💻 **Shell Command Generation**: OS-aware command execution
|
104
116
|
- 🧩 **Clean Code Generation**: Output code without markdown or explanations
|
@@ -267,6 +279,9 @@ You can configure the client using the following options:
|
|
267
279
|
| `--max_tokens` | Set maximum response length in tokens |
|
268
280
|
| `--preprompt` | Set custom system prompt to control AI behavior |
|
269
281
|
| `--log` | Set filepath to log conversation to (for interactive modes) |
|
282
|
+
| `--prettify` | Render markdown responses and code with syntax highlighting |
|
283
|
+
| `--renderer` | Select which markdown renderer to use with --prettify (auto, rich, or glow) |
|
284
|
+
| `--list-renderers` | Show available markdown renderers for use with --prettify |
|
270
285
|
| `--config` | Path to a custom configuration file or, when used without a value, enters interactive configuration mode |
|
271
286
|
| `--config-index` | Index of the configuration to use (default: 0) |
|
272
287
|
| `--provider` | Provider name to identify the configuration to use (alternative to --config-index) |
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
|
2
|
+
ngpt/cli.py,sha256=IiBVelrzhrRDu75B5wbf5GlCbBqgQXMh7tJ3Nk_WDsQ,60095
|
3
|
+
ngpt/client.py,sha256=QyPw93oJrMnStOzRqK6AldVqHATH1QgdbJ3vfkFjUsQ,14152
|
4
|
+
ngpt/config.py,sha256=WYOk_b1eiYjo6hpV3pfXr2RjqhOnmKqwZwKid1T41I4,10363
|
5
|
+
ngpt-2.5.1.dist-info/METADATA,sha256=wdJY5g_7LG2hvj5U3I_uY9Zho02lrqfolgj0G2Gjr0A,14657
|
6
|
+
ngpt-2.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
ngpt-2.5.1.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
|
8
|
+
ngpt-2.5.1.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
|
9
|
+
ngpt-2.5.1.dist-info/RECORD,,
|
ngpt-2.4.0.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
|
2
|
-
ngpt/cli.py,sha256=iIlsdKGnSUbdnzKRL6Vmk067KXDEtIZmLqRm8ZKH7XE,49101
|
3
|
-
ngpt/client.py,sha256=lJfyLONeBU7YqMVJJys6zPay7gcJTq108_rJ4wvOtok,13067
|
4
|
-
ngpt/config.py,sha256=WYOk_b1eiYjo6hpV3pfXr2RjqhOnmKqwZwKid1T41I4,10363
|
5
|
-
ngpt-2.4.0.dist-info/METADATA,sha256=Zcfa9uWB3PwwGgFz4fIhmu9XfLu_ZzQxIq7HF8CH-ew,13910
|
6
|
-
ngpt-2.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
ngpt-2.4.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
|
8
|
-
ngpt-2.4.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
|
9
|
-
ngpt-2.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|