From 086cfbc239bb472abc3f0c00bb7b66b5d841333c Mon Sep 17 00:00:00 2001 From: Gilgamesh555 Date: Tue, 6 Feb 2024 09:09:39 -0400 Subject: [PATCH 1/2] add model and list-model to args --- client/fabric | 9 +++++++++ client/utils.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/client/fabric b/client/fabric index b1fe682..1c0ff2e 100755 --- a/client/fabric +++ b/client/fabric @@ -39,6 +39,12 @@ if __name__ == "__main__": parser.add_argument( "--setup", help="Set up your fabric instance", action="store_true" ) + parser.add_argument( + "--model", "-m", help="Select the model to use (GPT-4 by default)", default="gpt-4" + ) + parser.add_argument( + "--listmodels", help="List all available models", action="store_true" + ) args = parser.parse_args() home_holder = os.path.expanduser("~") @@ -70,6 +76,9 @@ if __name__ == "__main__": except FileNotFoundError: print("No patterns found") sys.exit() + if args.listmodels: + Update.list_models() + sys.exit() if args.text is not None: text = args.text else: diff --git a/client/utils.py b/client/utils.py index c2d3db5..c9ab83d 100644 --- a/client/utils.py +++ b/client/utils.py @@ -12,6 +12,7 @@ config_directory = os.path.expanduser("~/.config/fabric") env_file = os.path.join(config_directory, ".env") + class Standalone: def __init__(self, args, pattern="", env_file="~/.config/fabric/.env"): # Expand the tilde to the full path @@ -30,6 +31,7 @@ class Standalone: self.config_pattern_directory = config_directory self.pattern = pattern self.args = args + self.model = args.model def streamMessage(self, input_data: str): wisdomFilePath = os.path.join( @@ -51,7 +53,7 @@ class Standalone: messages = [user_message] try: stream = self.client.chat.completions.create( - model="gpt-4", + model=self.model, messages=messages, temperature=0.0, top_p=1, @@ -98,7 +100,7 @@ class Standalone: messages = [user_message] try: response = self.client.chat.completions.create( - model="gpt-4", + model=self.model, messages=messages, temperature=0.0, top_p=1, @@ -181,6 +183,28 @@ class Update: self.progress_bar.close() # Ensure the progress bar is cleaned up properly else: print(f"Failed to fetch directory contents due to an HTTP error: {e}") + def list_models(): + AVAILABLE_MODELS = [ + "gpt-4-0125-preview", + "gpt-4-turbo-preview", + "gpt-4-1106-preview", + "gpt-4-vision-preview", + "gpt-4", + "gpt-4-0613", + "gpt-4-32k", + "gpt-4-32k-0613", + "gpt-3.5-turbo-0125", + "gpt-3.5-turbo", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-instruct", + "gpt-3.5-turbo-16k", + "gpt-3.5-turbo-0613", + "gpt-3.5-turbo-16k-0613" + ] + + print("Available models:") + for model in AVAILABLE_MODELS: + print(model) class Setup: From 5657eb4bf295e7f3c20e05bbd41721b207d0d5fc Mon Sep 17 00:00:00 2001 From: Gilgamesh555 Date: Tue, 6 Feb 2024 14:37:15 -0400 Subject: [PATCH 2/2] update model list to api dynamic response based on user key --- client/fabric | 2 +- client/utils.py | 42 +++++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/client/fabric b/client/fabric index afa1c40..82d6719 100755 --- a/client/fabric +++ b/client/fabric @@ -77,7 +77,7 @@ if __name__ == "__main__": print("No patterns found") sys.exit() if args.listmodels: - Update.list_models() + standalone.fetch_available_models() sys.exit() if args.text is not None: text = args.text diff --git a/client/utils.py b/client/utils.py index c9ab83d..5cd7031 100644 --- a/client/utils.py +++ b/client/utils.py @@ -118,6 +118,25 @@ class Standalone: with open(self.args.output, "w") as f: f.write(response.choices[0].message.content) + def fetch_available_models(self): + headers = { + "Authorization": f"Bearer { self.client.api_key }" + } + + response = requests.get("https://api.openai.com/v1/models", headers=headers) + + if response.status_code == 200: + models = response.json().get("data", []) + # Filter only gpt models + gpt_models = [model for model in models if model.get("id", "").startswith(("gpt"))] + # Sort the models alphabetically by their ID + sorted_gpt_models = sorted(gpt_models, key=lambda x: x.get("id")) + + for model in sorted_gpt_models: + print(model.get("id")) + else: + print(f"Failed to fetch models: HTTP {response.status_code}") + class Update: def __init__(self): @@ -183,29 +202,6 @@ class Update: self.progress_bar.close() # Ensure the progress bar is cleaned up properly else: print(f"Failed to fetch directory contents due to an HTTP error: {e}") - def list_models(): - AVAILABLE_MODELS = [ - "gpt-4-0125-preview", - "gpt-4-turbo-preview", - "gpt-4-1106-preview", - "gpt-4-vision-preview", - "gpt-4", - "gpt-4-0613", - "gpt-4-32k", - "gpt-4-32k-0613", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-instruct", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0613", - "gpt-3.5-turbo-16k-0613" - ] - - print("Available models:") - for model in AVAILABLE_MODELS: - print(model) - class Setup: def __init__(self):