aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-05-05 01:50:56 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-05-05 01:50:56 -0500
commit439e935ec583eb7641152c32798898024859e939 (patch)
tree90850537f254c2d5c23a04ff2ec7ce12790eb79e
parent69654841fd272a66403031cd6e9311423f9f117b (diff)
downloadgpt-chat-cli-439e935ec583eb7641152c32798898024859e939.tar.xz
gpt-chat-cli-439e935ec583eb7641152c32798898024859e939.zip
Add stdin as a input source for the inital prompt
-rw-r--r--src/gpt_chat_cli/argparsing.py31
-rw-r--r--src/gpt_chat_cli/gcli.py27
-rw-r--r--src/gpt_chat_cli/version.py1
3 files changed, 42 insertions, 17 deletions
diff --git a/src/gpt_chat_cli/argparsing.py b/src/gpt_chat_cli/argparsing.py
index 7d1d305..81a9b47 100644
--- a/src/gpt_chat_cli/argparsing.py
+++ b/src/gpt_chat_cli/argparsing.py
@@ -64,9 +64,10 @@ class DebugArguments:
class Arguments:
completion_args: CompletionArguments
display_args: DisplayArguments
+ version: bool
debug_args: Optional[DebugArguments] = None
-def split_arguments(args: argparse.Namespace, debug=False) -> Arguments:
+def split_arguments(args: argparse.Namespace) -> Arguments:
completion_args = CompletionArguments(
model=args.model,
n_completions=args.n_completions,
@@ -83,15 +84,17 @@ def split_arguments(args: argparse.Namespace, debug=False) -> Arguments:
color=(args.color == AutoDetectedOption.ON),
)
- if debug:
- debug_args = DebugArguments(
- save_response_to_file=args.save_response_to_file,
- load_response_from_file=args.load_response_from_file,
- )
- else:
- debug_args = None
+ debug_args = DebugArguments(
+ save_response_to_file=args.save_response_to_file,
+ load_response_from_file=args.load_response_from_file,
+ )
- return Arguments( completion_args, display_args, debug_args )
+ return Arguments(
+ completion_args=completion_args,
+ display_args=display_args,
+ debug_args=debug_args,
+ version=args.version
+ )
def parse_args() -> Arguments:
@@ -199,8 +202,16 @@ def parse_args() -> Arguments:
)
parser.add_argument(
+ "--version",
+ # type=bool,
+ action="store_true",
+ help="Print version and exit"
+ )
+
+ parser.add_argument(
"message",
type=str,
+ nargs='?',
help=(
"The contents of the message. When used in chat mode, this is the initial "
"message if provided."
@@ -255,4 +266,4 @@ def parse_args() -> Arguments:
validate_args(args)
- return split_arguments(args, debug=debug)
+ return split_arguments(args)
diff --git a/src/gpt_chat_cli/gcli.py b/src/gpt_chat_cli/gcli.py
index dcd7c8b..f0b754e 100644
--- a/src/gpt_chat_cli/gcli.py
+++ b/src/gpt_chat_cli/gcli.py
@@ -20,8 +20,10 @@ from .argparsing import (
Arguments,
DisplayArguments,
CompletionArguments,
+ DebugArguments,
)
+from .version import VERSION
from .color import get_color_codes
###########################
@@ -132,17 +134,28 @@ def print_streamed_response(
def main():
args = parse_args()
+ if args.version:
+ print(f'version {VERSION}')
+ sys.exit(0)
+
completion_args = args.completion_args
+ COLOR_CODE = get_color_codes(no_color = not args.display_args.color)
- if args.debug_args:
- debug_args : DebugArguments = args.debug_args
+ debug_args : DebugArguments = args.debug_args
- if debug_args.save_response_to_file:
- save_response_and_arguments(args)
- return
- elif debug_args.load_response_from_file:
- completion_args, completion = load_response_and_arguments(args)
+ if debug_args.save_response_to_file:
+ save_response_and_arguments(args)
+ return
+ elif debug_args.load_response_from_file:
+ completion_args, completion = load_response_and_arguments(args)
else:
+ if args.completion_args.message is None:
+ if sys.stdin.isatty():
+ print(f'GPT Chat CLI {VERSION}')
+ print(f'[{COLOR_CODE.WHITE}#{COLOR_CODE.RESET}]', end=' ', flush=True)
+
+ completion_args.message = sys.stdin.read()
+
completion = create_chat_completion_from_args(completion_args)
print_streamed_response(
diff --git a/src/gpt_chat_cli/version.py b/src/gpt_chat_cli/version.py
new file mode 100644
index 0000000..bc784a3
--- /dev/null
+++ b/src/gpt_chat_cli/version.py
@@ -0,0 +1 @@
+VERSION = '0.0.2'