fixed something

This commit is contained in:
jad2121 2024-03-07 19:28:10 -05:00
parent b64b1cdef2
commit caca2b728e
3 changed files with 38 additions and 38 deletions

View File

@ -50,10 +50,6 @@ class Standalone:
self.model = args.model
self.claude = False
sorted_gpt_models, ollamaList, claudeList = self.fetch_available_models()
try:
self.model = os.environ["DEFAULT_MODEL"]
except:
pass
self.local = self.model.strip() in ollamaList
self.claude = self.model.strip() in claudeList
@ -536,6 +532,28 @@ class Setup:
else:
return line # Return the line unmodified if no match is found.
def update_fabric_alias(self, line, model):
fabric_alias_regex = re.compile(
r"(alias fabric='[^']+?)( --model.*)?'")
match = fabric_alias_regex.search(line)
if match:
base_command, current_flag = match.groups()
new_flag = f" --model {model}"
# Update the alias if the new flag is different or to remove an existing flag.
return f"{base_command}{new_flag}'\n"
else:
return line # Return the line unmodified if no match is found.
def clear_alias(self, line):
fabric_command_regex = re.compile(
r"(alias fabric='[^']+?)( --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 clear_env_line(self, line):
fabric_command_regex = re.compile(
r"(alias.*fabric --pattern\s+\S+.*?)( --model.*)?'")
@ -546,6 +564,16 @@ class Setup:
else:
return line # Return the line unmodified if no match is found.
def pattern(self, line):
fabric_command_regex = re.compile(
r"(alias fabric='[^']+?)( --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.
@ -572,24 +600,12 @@ class Setup:
modified_line = self.clear_env_line(
modified_line)
elif "fabric=" in line:
modified_line = self.clear_env_line(
modified_line = self.clear_alias(
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.*)?'")
match = fabric_alias_regex.search(line)
if match:
base_command, current_flag = match.groups()
new_flag = f" --model {model}"
# Update the alias if the new flag is different or to remove an existing flag.
return f"{base_command}{new_flag}'\n"
else:
return line # Return the line unmodified if no match is found.
def default_model(self, model):
"""Set the default model in the environment file.
@ -604,22 +620,6 @@ class Setup:
print(
f"Error: {model} is not a valid model. Please run fabric --listmodels to see the available models.")
sys.exit()
if os.path.exists(self.env_file):
with open(self.env_file, "r") as f:
lines = f.readlines()
with open(self.env_file, "w") as f:
found = False
for line in lines:
if line.startswith("DEFAULT_MODEL"):
f.write(f"DEFAULT_MODEL={model}\n")
found = True
else:
f.write(line)
if not found:
f.write(f"DEFAULT_MODEL={model}\n")
else:
with open(self.env_file, "w") as f:
f.write(f"DEFAULT_MODEL={model}\n")
# Compile regular expressions outside of the loop for efficiency

View File

@ -17,7 +17,7 @@
},
"devDependencies": {
"dotenv": "^16.4.1",
"electron": "^28.2.2",
"electron": "^28.2.6",
"openai": "^4.27.0"
}
},
@ -522,9 +522,9 @@
}
},
"node_modules/electron": {
"version": "28.2.2",
"resolved": "https://registry.npmjs.org/electron/-/electron-28.2.2.tgz",
"integrity": "sha512-8UcvIGFcjplHdjPFNAHVFg5bS0atDyT3Zx21WwuE4iLfxcAMsyMEOgrQX3im5LibA8srwsUZs7Cx0JAUfcQRpw==",
"version": "28.2.6",
"resolved": "https://registry.npmjs.org/electron/-/electron-28.2.6.tgz",
"integrity": "sha512-RuhbW+ifvh3DqnVlHCcCKhKIFOxTktq1GN1gkIkEZ8y5LEZfcjOkxB2s6Fd1S6MzsMZbiJti+ZJG5hXS4SDVLQ==",
"dev": true,
"hasInstallScript": true,
"dependencies": {

View File

@ -10,7 +10,7 @@
"license": "ISC",
"devDependencies": {
"dotenv": "^16.4.1",
"electron": "^28.2.2",
"electron": "^28.2.6",
"openai": "^4.27.0"
},
"dependencies": {