Browse Source

fixed something

pull/174/head
jad2121 8 months ago
parent
commit
caca2b728e
  1. 66
      installer/client/cli/utils.py
  2. 8
      installer/client/gui/package-lock.json
  3. 2
      installer/client/gui/package.json

66
installer/client/cli/utils.py

@ -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

8
installer/client/gui/package-lock.json generated

@ -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": {

2
installer/client/gui/package.json

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

Loading…
Cancel
Save