fixed some stuff

This commit is contained in:
jad2121
2024-03-06 17:55:10 -05:00
parent d7fb8fe92d
commit 341c358260
3 changed files with 55 additions and 4 deletions

View File

@@ -37,6 +37,8 @@ def main():
parser.add_argument(
"--list", "-l", help="List available patterns", action="store_true"
)
parser.add_argument('--clear', help="Clears your persistant model choice so that you can once again use the --model flag",
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")
@@ -47,7 +49,7 @@ def main():
help="Change the default model. Your choice will be saved in ~/.config/fabric/.env). For a list of available models, use the --listmodels flag.")
parser.add_argument(
"--model", "-m", help="Select the model to use (GPT-4 by default for chatGPT and llama2 for Ollama)", default="gpt-4-turbo-preview"
"--model", "-m", help="Select the model to use. NOTE: Will not work if you have set a default model. please use --clear to clear persistance before using this flag", default="gpt-4-turbo-preview"
)
parser.add_argument(
"--listmodels", help="List all available models", action="store_true"
@@ -97,6 +99,10 @@ def main():
if not os.path.exists(os.path.join(config, "context.md")):
print("Please create a context.md file in ~/.config/fabric")
sys.exit()
if args.clear:
Setup().clean_env()
print("Model choice cleared. please restart your session to use the --model flag.")
sys.exit()
standalone = Standalone(args, args.pattern)
if args.list:
try:

View File

@@ -537,6 +537,48 @@ class Setup:
else:
return line # Return the line unmodified if no match is found.
def clear_env_line(self, line):
fabric_command_regex = re.compile(
r"(alias.*fabric --pattern\s+\S+.*?)( --model.*)?'")
match = fabric_command_regex.search(line)
if match:
base_command = match.group(1)
return f"{base_command}'\n"
else:
return line # Return the line unmodified if no match is found.
def clean_env(self):
"""Clear the DEFAULT_MODEL from the environment file.
Returns:
None
"""
user_home = os.path.expanduser("~")
sh_config = None
# Check for shell configuration files
if os.path.exists(os.path.join(user_home, ".bashrc")):
sh_config = os.path.join(user_home, ".bashrc")
elif os.path.exists(os.path.join(user_home, ".zshrc")):
sh_config = os.path.join(user_home, ".zshrc")
else:
print("No environment file found.")
if sh_config:
with open(sh_config, "r") as f:
lines = f.readlines()
with open(sh_config, "w") as f:
for line in lines:
modified_line = line
# Update existing fabric commands
if "fabric --pattern" in line:
modified_line = self.clear_env_line(
modified_line)
elif "fabric=" in line:
modified_line = self.clear_env_line(
modified_line)
f.write(modified_line)
else:
print("No shell configuration file found.")
def update_fabric_alias(self, line, model):
fabric_alias_regex = re.compile(
r"(alias fabric='[^']+?)( --model.*)?'")