fixed lots of things that pull requests broke
This commit is contained in:
parent
3ec5058f8d
commit
e6ff430610
@ -564,37 +564,34 @@ class Setup:
|
|||||||
model (str): The model to be set.
|
model (str): The model to be set.
|
||||||
"""
|
"""
|
||||||
model = model.strip()
|
model = model.strip()
|
||||||
if model:
|
|
||||||
# Write or update the DEFAULT_MODEL in env_file
|
|
||||||
allModels = self.claudeList + self.fullOllamaList + self.gptlist
|
|
||||||
if model not in allModels:
|
|
||||||
print(
|
|
||||||
f"Error: {model} is not a valid model. Please run fabric --listmodels to see the available models.")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# Compile regular expressions outside of the loop for efficiency
|
|
||||||
|
|
||||||
# Check for shell configuration files
|
|
||||||
if os.path.exists(os.path.expanduser("~/.config/fabric/.env")):
|
|
||||||
env = os.path.expanduser("~/.config/fabric/.env")
|
env = os.path.expanduser("~/.config/fabric/.env")
|
||||||
|
|
||||||
|
# Only proceed if the model is not empty
|
||||||
|
if model:
|
||||||
|
if os.path.exists(env):
|
||||||
|
# Initialize a flag to track the presence of DEFAULT_MODEL
|
||||||
there = False
|
there = False
|
||||||
with open(env, "r") as f:
|
with open(env, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
if "DEFAULT_MODEL" in lines:
|
|
||||||
there = True
|
# Open the file again to write the changes
|
||||||
if there:
|
|
||||||
with open(env, "w") as f:
|
with open(env, "w") as f:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
modified_line = line
|
# Check each line to see if it contains DEFAULT_MODEL
|
||||||
# Update existing fabric commands
|
if "DEFAULT_MODEL=" in line:
|
||||||
if "DEFAULT_MODEL" in line:
|
# Update the flag and the line with the new model
|
||||||
modified_line = f'DEFAULT_MODEL={model}\n'
|
there = True
|
||||||
f.write(modified_line)
|
|
||||||
else:
|
|
||||||
with open(env, "a") as f:
|
|
||||||
f.write(f'DEFAULT_MODEL={model}\n')
|
f.write(f'DEFAULT_MODEL={model}\n')
|
||||||
print(f"""Default model changed to {
|
else:
|
||||||
model}. Please restart your terminal to use it.""")
|
# If the line does not contain DEFAULT_MODEL, write it unchanged
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
# If DEFAULT_MODEL was not found in the file, add it
|
||||||
|
if not there:
|
||||||
|
f.write(f'DEFAULT_MODEL={model}\n')
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Default model changed to {model}. Please restart your terminal to use it.")
|
||||||
else:
|
else:
|
||||||
print("No shell configuration file found.")
|
print("No shell configuration file found.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user