ngpt 2.1.0__py3-none-any.whl → 2.2.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 +34 -3
- {ngpt-2.1.0.dist-info → ngpt-2.2.0.dist-info}/METADATA +1 -1
- ngpt-2.2.0.dist-info/RECORD +9 -0
- ngpt-2.1.0.dist-info/RECORD +0 -9
- {ngpt-2.1.0.dist-info → ngpt-2.2.0.dist-info}/WHEEL +0 -0
- {ngpt-2.1.0.dist-info → ngpt-2.2.0.dist-info}/entry_points.txt +0 -0
- {ngpt-2.1.0.dist-info → ngpt-2.2.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):
|
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):
|
89
89
|
"""Run an interactive chat session with conversation history."""
|
90
90
|
# Define ANSI color codes for terminal output
|
91
91
|
COLORS = {
|
@@ -127,6 +127,20 @@ 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")
|
@@ -228,6 +242,11 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
228
242
|
user_message = {"role": "user", "content": user_input}
|
229
243
|
conversation.append(user_message)
|
230
244
|
|
245
|
+
# Log user message if logging is enabled
|
246
|
+
if log_handle:
|
247
|
+
log_handle.write(f"User: {user_input}\n")
|
248
|
+
log_handle.flush()
|
249
|
+
|
231
250
|
# Print assistant indicator with formatting
|
232
251
|
if not no_stream:
|
233
252
|
print(f"\n{ngpt_header()}: {COLORS['reset']}", end="", flush=True)
|
@@ -253,6 +272,11 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
253
272
|
# Print response if not streamed
|
254
273
|
if no_stream:
|
255
274
|
print(response)
|
275
|
+
|
276
|
+
# Log assistant response if logging is enabled
|
277
|
+
if log_handle:
|
278
|
+
log_handle.write(f"Assistant: {response}\n\n")
|
279
|
+
log_handle.flush()
|
256
280
|
|
257
281
|
# Print separator between exchanges
|
258
282
|
print_separator()
|
@@ -264,9 +288,14 @@ def interactive_chat_session(client, web_search=False, no_stream=False, temperat
|
|
264
288
|
# Print traceback for debugging if it's a serious error
|
265
289
|
import traceback
|
266
290
|
traceback.print_exc()
|
291
|
+
finally:
|
292
|
+
# Close log file if it was opened
|
293
|
+
if log_handle:
|
294
|
+
log_handle.write(f"\n--- End of Session ---\n")
|
295
|
+
log_handle.close()
|
267
296
|
|
268
297
|
def main():
|
269
|
-
parser = argparse.ArgumentParser(description="nGPT - A CLI tool for interacting with
|
298
|
+
parser = argparse.ArgumentParser(description="nGPT - A CLI tool for interacting with OpenAI-compatible APIs, supporting both official and self-hosted LLM endpoints")
|
270
299
|
|
271
300
|
# Version flag
|
272
301
|
parser.add_argument('-v', '--version', action='version', version=f'nGPT {__version__}', help='Show version information and exit')
|
@@ -295,6 +324,8 @@ def main():
|
|
295
324
|
help='Set top_p (controls diversity, default: 1.0)')
|
296
325
|
global_group.add_argument('--max_length', type=int,
|
297
326
|
help='Set max response length in tokens')
|
327
|
+
global_group.add_argument('--log', metavar='FILE',
|
328
|
+
help='Set filepath to log conversation to (For interactive modes)')
|
298
329
|
|
299
330
|
# Mode flags (mutually exclusive)
|
300
331
|
mode_group = parser.add_argument_group('Modes (mutually exclusive)')
|
@@ -455,7 +486,7 @@ def main():
|
|
455
486
|
# Interactive chat mode
|
456
487
|
interactive_chat_session(client, web_search=args.web_search, no_stream=args.no_stream,
|
457
488
|
temperature=args.temperature, top_p=args.top_p,
|
458
|
-
max_length=args.max_length)
|
489
|
+
max_length=args.max_length, log_file=args.log)
|
459
490
|
elif args.shell:
|
460
491
|
if args.prompt is None:
|
461
492
|
try:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ngpt
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.2.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
|
@@ -0,0 +1,9 @@
|
|
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,,
|
ngpt-2.1.0.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
ngpt/__init__.py,sha256=ehInP9w0MZlS1vZ1g6Cm4YE1ftmgF72CnEddQ3Le9n4,368
|
2
|
-
ngpt/cli.py,sha256=wNjY-qUuvzODdzffbYqyydJiLfhIsEXXUs9qalqcpvs,30082
|
3
|
-
ngpt/client.py,sha256=75xmzO7e9wQ7y_LzZCacg3mkZdheewcBxB6moPftqYw,13067
|
4
|
-
ngpt/config.py,sha256=BF0G3QeiPma8l7EQyc37bR7LWZog7FHJQNe7uj9cr4w,6896
|
5
|
-
ngpt-2.1.0.dist-info/METADATA,sha256=47qdylepQUHyR-TsJTtB8ezMnRLnZie0uSI1WVbHUNg,11278
|
6
|
-
ngpt-2.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
ngpt-2.1.0.dist-info/entry_points.txt,sha256=1cnAMujyy34DlOahrJg19lePSnb08bLbkUs_kVerqdk,39
|
8
|
-
ngpt-2.1.0.dist-info/licenses/LICENSE,sha256=mQkpWoADxbHqE0HRefYLJdm7OpdrXBr3vNv5bZ8w72M,1065
|
9
|
-
ngpt-2.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|