2024-03-05 10:42:02 +00:00
from . utils import Standalone , Update , Setup , Alias
2024-02-08 20:54:42 +00:00
import argparse
import sys
import os
script_directory = os . path . dirname ( os . path . realpath ( __file__ ) )
2024-02-18 18:25:07 +00:00
2024-02-08 20:54:42 +00:00
2024-02-09 12:52:07 +00:00
def main ( ) :
2024-02-08 20:54:42 +00:00
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 (
2024-02-18 21:34:47 +00:00
" --copy " , " -C " , help = " Copy the response to the clipboard " , action = " store_true "
2024-02-08 20:54:42 +00:00
)
2024-03-04 22:09:25 +00:00
parser . add_argument (
' --agents ' , ' -a ' , choices = [ ' trip_planner ' , ' ApiKeys ' ] ,
help = " Use an AI agent to help you with a task. Acceptable values are ' trip_planner ' or ' ApiKeys ' . This option cannot be used with any other flag. "
)
2024-02-08 20:54:42 +00:00
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 want to see the results in realtime. NOTE: You will not be able to pipe the output into another command. " ,
action = " store_true " ,
)
parser . add_argument (
" --list " , " -l " , help = " List available patterns " , action = " store_true "
)
2024-03-12 08:37:14 +00:00
parser . add_argument ( ' --clear ' , help = " Clears your persistent model choice so that you can once again use the --model flag " ,
2024-03-06 22:55:10 +00:00
action = " store_true " )
2024-02-18 18:25:07 +00:00
parser . add_argument (
2024-03-07 01:20:21 +00:00
" --update " , " -u " , help = " Update patterns. NOTE: This will revert the default model to gpt4-turbo. please run --changeDefaultModel to once again set default model " , action = " store_true " )
2024-02-08 20:54:42 +00:00
parser . add_argument ( " --pattern " , " -p " , help = " The pattern (prompt) to use " )
parser . add_argument (
" --setup " , help = " Set up your fabric instance " , action = " store_true "
)
2024-03-06 03:37:07 +00:00
parser . add_argument ( ' --changeDefaultModel ' ,
2024-03-07 14:37:25 +00:00
help = " Change the default model. For a list of available models, use the --listmodels flag. " )
2024-03-06 01:10:35 +00:00
2024-02-08 20:54:42 +00:00
parser . add_argument (
2024-03-13 18:59:24 +00:00
" --model " , " -m " , help = " Select the model to use. NOTE: Will not work if you have set a default model. please use --clear to clear persistence before using this flag "
2024-02-08 20:54:42 +00:00
)
parser . add_argument (
" --listmodels " , help = " List all available models " , action = " store_true "
)
2024-03-12 16:59:57 +00:00
parser . add_argument ( ' --remoteOllamaServer ' ,
help = ' The URL of the remote ollamaserver to use. ONLY USE THIS if you are using a local ollama server in an non-deault location or port ' )
2024-02-18 21:34:47 +00:00
parser . add_argument ( ' --context ' , ' -c ' ,
2024-02-18 18:25:07 +00:00
help = " Use Context file (context.md) to add context to your pattern " , action = " store_true " )
2024-02-08 20:54:42 +00:00
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 " )
2024-02-18 21:48:47 +00:00
config_context = os . path . join ( config , " context.md " )
2024-02-08 20:54:42 +00:00
env_file = os . path . join ( config , " .env " )
if not os . path . exists ( config ) :
os . makedirs ( config )
if args . setup :
Setup ( ) . run ( )
2024-03-13 18:59:24 +00:00
Alias ( ) . execute ( )
2024-02-08 20:54:42 +00:00
sys . exit ( )
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. " )
sys . exit ( )
if not os . path . exists ( config_patterns_directory ) :
Update ( )
2024-02-21 11:19:54 +00:00
Alias ( )
2024-02-08 20:54:42 +00:00
sys . exit ( )
2024-03-06 03:37:07 +00:00
if args . changeDefaultModel :
Setup ( ) . default_model ( args . changeDefaultModel )
sys . exit ( )
2024-03-04 22:09:25 +00:00
if args . agents :
# Handle the agents logic
if args . agents == ' trip_planner ' :
2024-03-05 10:42:02 +00:00
from . agents . trip_planner . main import planner_cli
2024-02-28 15:17:57 +00:00
tripcrew = planner_cli ( )
tripcrew . ask ( )
2024-03-03 20:19:10 +00:00
sys . exit ( )
2024-03-04 22:09:25 +00:00
elif args . agents == ' ApiKeys ' :
2024-03-05 10:42:02 +00:00
from . utils import AgentSetup
2024-03-03 20:19:10 +00:00
AgentSetup ( ) . run ( )
sys . exit ( )
2024-02-08 20:54:42 +00:00
if args . update :
Update ( )
2024-02-21 11:19:54 +00:00
Alias ( )
2024-02-08 20:54:42 +00:00
sys . exit ( )
2024-02-18 21:48:47 +00:00
if args . context :
if not os . path . exists ( os . path . join ( config , " context.md " ) ) :
print ( " Please create a context.md file in ~/.config/fabric " )
sys . exit ( )
2024-03-06 22:55:10 +00:00
if args . clear :
Setup ( ) . clean_env ( )
print ( " Model choice cleared. please restart your session to use the --model flag. " )
sys . exit ( )
2024-03-06 22:35:46 +00:00
standalone = Standalone ( args , args . pattern )
2024-02-08 20:54:42 +00:00
if args . list :
try :
2024-02-22 03:01:22 +00:00
direct = sorted ( os . listdir ( config_patterns_directory ) )
2024-02-08 20:54:42 +00:00
for d in direct :
print ( d )
sys . exit ( )
except FileNotFoundError :
print ( " No patterns found " )
sys . exit ( )
if args . listmodels :
2024-03-06 22:35:46 +00:00
gptmodels , localmodels , claudemodels = standalone . fetch_available_models ( )
print ( " GPT Models: " )
for model in gptmodels :
print ( model )
print ( " \n Local Models: " )
for model in localmodels :
print ( model )
print ( " \n Claude Models: " )
for model in claudemodels :
2024-03-06 15:10:30 +00:00
print ( model )
2024-02-08 20:54:42 +00:00
sys . exit ( )
if args . text is not None :
text = args . text
else :
2024-02-10 13:08:55 +00:00
text = standalone . get_cli_input ( )
2024-02-18 18:25:07 +00:00
if args . stream and not args . context :
2024-03-12 16:59:57 +00:00
if args . remoteOllamaServer :
standalone . streamMessage ( text , host = args . remoteOllamaServer )
else :
standalone . streamMessage ( text )
2024-02-24 21:39:48 +00:00
sys . exit ( )
2024-02-18 18:25:07 +00:00
if args . stream and args . context :
2024-02-18 21:48:47 +00:00
with open ( config_context , " r " ) as f :
2024-02-18 18:25:07 +00:00
context = f . read ( )
2024-03-12 16:59:57 +00:00
if args . remoteOllamaServer :
standalone . streamMessage (
text , context = context , host = args . remoteOllamaServer )
else :
standalone . streamMessage ( text , context = context )
2024-02-24 21:39:48 +00:00
sys . exit ( )
2024-02-18 18:25:07 +00:00
elif args . context :
2024-02-18 21:48:47 +00:00
with open ( config_context , " r " ) as f :
2024-02-18 18:25:07 +00:00
context = f . read ( )
2024-03-12 16:59:57 +00:00
if args . remoteOllamaServer :
standalone . sendMessage (
text , context = context , host = args . remoteOllamaServer )
else :
standalone . sendMessage ( text , context = context )
2024-02-24 21:39:48 +00:00
sys . exit ( )
2024-02-08 20:54:42 +00:00
else :
2024-03-12 16:59:57 +00:00
if args . remoteOllamaServer :
standalone . sendMessage ( text , host = args . remoteOllamaServer )
else :
standalone . sendMessage ( text )
2024-02-24 21:39:48 +00:00
sys . exit ( )
2024-02-09 12:52:07 +00:00
2024-02-18 18:25:07 +00:00
2024-02-09 12:52:07 +00:00
if __name__ == " __main__ " :
main ( )