Browse Source

fixed local

pull/185/head
jad2121 12 months ago
parent
commit
d1463e9cc7
  1. 47
      installer/client/cli/utils.py

47
installer/client/cli/utils.py

@ -40,9 +40,8 @@ class Standalone:
apikey = os.environ["OPENAI_API_KEY"] apikey = os.environ["OPENAI_API_KEY"]
self.client = OpenAI() self.client = OpenAI()
self.client.api_key = apikey self.client.api_key = apikey
except FileNotFoundError: except:
print("No API key found. Use the --apikey option to set the key") print("No API key found. Use the --apikey option to set the key")
sys.exit()
self.local = False self.local = False
self.config_pattern_directory = config_directory self.config_pattern_directory = config_directory
self.pattern = pattern self.pattern = pattern
@ -253,27 +252,29 @@ class Standalone:
gptlist = [] gptlist = []
fullOllamaList = [] fullOllamaList = []
claudeList = ['claude-3-opus-20240229'] claudeList = ['claude-3-opus-20240229']
headers = { try:
"Authorization": f"Bearer {self.client.api_key}" headers = {
} "Authorization": f"Bearer {self.client.api_key}"
}
response = requests.get( response = requests.get(
"https://api.openai.com/v1/models", headers=headers) "https://api.openai.com/v1/models", headers=headers)
if response.status_code == 200: if response.status_code == 200:
models = response.json().get("data", []) models = response.json().get("data", [])
# Filter only gpt models # Filter only gpt models
gpt_models = [model for model in models if model.get( gpt_models = [model for model in models if model.get(
"id", "").startswith(("gpt"))] "id", "").startswith(("gpt"))]
# Sort the models alphabetically by their ID # Sort the models alphabetically by their ID
sorted_gpt_models = sorted( sorted_gpt_models = sorted(
gpt_models, key=lambda x: x.get("id")) gpt_models, key=lambda x: x.get("id"))
for model in sorted_gpt_models: for model in sorted_gpt_models:
gptlist.append(model.get("id")) gptlist.append(model.get("id"))
else: else:
print(f"Failed to fetch models: HTTP {response.status_code}") print(f"Failed to fetch models: HTTP {response.status_code}")
sys.exit() sys.exit()
except:
print('No OpenAI API key found. Please run fabric --setup and add the key if you wish to interact with openai')
import ollama import ollama
try: try:
default_modelollamaList = ollama.list()['models'] default_modelollamaList = ollama.list()['models']

Loading…
Cancel
Save