You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.4 KiB
68 lines
2.4 KiB
#!/usr/bin/env python3 |
|
|
|
from utils import Standalone, Update |
|
import argparse |
|
import sys |
|
import os |
|
|
|
|
|
script_directory = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
if __name__ == "__main__": |
|
parser = argparse.ArgumentParser( |
|
description='An open source framework for augmenting humans using AI.') |
|
parser.add_argument('--text', '-t', help='Text to extract summary from') |
|
parser.add_argument( |
|
'--copy', '-c', help='Copy the response to the clipboard', action='store_true') |
|
parser.add_argument('--output', '-o', help='Save the response to a file', |
|
nargs='?', const='analyzepaper.txt', default=None) |
|
parser.add_argument( |
|
'--stream', '-s', help='Use this option if you are piping output to another app. The output will not be streamed', action='store_true') |
|
parser.add_argument( |
|
'--list', '-l', help='List available patterns', action='store_true') |
|
parser.add_argument( |
|
'--update', '-u', help='Update patterns', action='store_true') |
|
parser.add_argument('--pattern', '-p', help='The pattern (prompt) to use') |
|
parser.add_argument('--apikey', '-a', help='Add an OpenAI key') |
|
|
|
args = parser.parse_args() |
|
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') |
|
if not os.path.exists(config): |
|
os.makedirs(config) |
|
if args.apikey: |
|
with open(env_file, 'w') as f: |
|
f.write(f'OPENAI_API_KEY={args.apikey}') |
|
print(f'OpenAI API key set to {args.apikey}') |
|
sys.exit() |
|
if not os.path.exists(env_file): |
|
print('No API key found. Use the --apikey option to set the key') |
|
sys.exit() |
|
if not os.path.exists(config_patterns_directory): |
|
Update() |
|
sys.exit() |
|
if args.update: |
|
Update() |
|
print('patterns updated:') |
|
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: |
|
print('No patterns found') |
|
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)
|
|
|