fabric/client/fabric

81 lines
2.5 KiB
Plaintext
Raw Normal View History

2024-02-03 14:09:16 -08:00
#!/usr/bin/env python3
2024-02-02 10:11:56 -05:00
2024-02-03 10:37:19 -05:00
from utils import Standalone, Update, Setup
2024-02-02 10:11:56 -05:00
import argparse
import sys
import os
script_directory = os.path.dirname(os.path.realpath(__file__))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
2024-02-03 02:03:05 -08:00
description="An open source framework for augmenting humans using AI."
)
parser.add_argument("--text", "-t", help="Text to extract summary from")
2024-02-02 10:11:56 -05:00
parser.add_argument(
2024-02-03 02:03:05 -08:00
"--copy", "-c", help="Copy the response to the clipboard", action="store_true"
)
2024-02-02 10:11:56 -05:00
parser.add_argument(
2024-02-03 02:03:05 -08:00
"--output",
"-o",
help="Save the response to a file",
nargs="?",
const="analyzepaper.txt",
default=None,
)
2024-02-02 10:11:56 -05:00
parser.add_argument(
2024-02-03 02:03:05 -08:00
"--stream",
"-s",
help="Use this option if you are piping output to another app. The output will not be streamed",
action="store_true",
)
2024-02-02 10:19:12 -05:00
parser.add_argument(
2024-02-03 02:03:05 -08:00
"--list", "-l", help="List available patterns", action="store_true"
)
2024-02-03 14:09:16 -08:00
parser.add_argument("--update", "-u", help="Update patterns", action="store_true")
2024-02-03 02:03:05 -08:00
parser.add_argument("--pattern", "-p", help="The pattern (prompt) to use")
2024-02-03 10:37:19 -05:00
parser.add_argument(
2024-02-03 14:09:16 -08:00
"--setup", help="Set up your fabric instance", action="store_true"
)
2024-02-02 10:11:56 -05:00
args = parser.parse_args()
2024-02-03 02:03:05 -08:00
home_holder = os.path.expanduser("~")
config = os.path.join(home_holder, ".config", "fabric")
config_patterns_directory = os.path.join(config, "patterns")
env_file = os.path.join(config, ".env")
2024-02-02 10:11:56 -05:00
if not os.path.exists(config):
os.makedirs(config)
2024-02-03 10:37:19 -05:00
if args.setup:
Setup().run()
2024-02-02 10:41:27 -05:00
sys.exit()
2024-02-03 10:37:19 -05:00
if not os.path.exists(env_file) or not os.path.exists(config_patterns_directory):
print("Please run --setup to set up your API key and download patterns.")
2024-02-02 10:11:56 -05:00
sys.exit()
if not os.path.exists(config_patterns_directory):
Update()
sys.exit()
if args.update:
Update()
2024-02-03 14:11:50 -08:00
print("Your Patterns have been updated.")
2024-02-02 10:11:56 -05:00
sys.exit()
standalone = Standalone(args, args.pattern)
if args.list:
try:
direct = os.listdir(config_patterns_directory)
for d in direct:
print(d)
sys.exit()
except FileNotFoundError:
2024-02-03 02:03:05 -08:00
print("No patterns found")
2024-02-02 10:11:56 -05:00
sys.exit()
if args.text is not None:
text = args.text
else:
text = sys.stdin.read()
if args.stream:
standalone.streamMessage(text)
else:
standalone.sendMessage(text)