Browse Source

Merge 9f52c94fb7 into 74a7960af8

pull/440/merge
Gauransh Soni 10 months ago committed by GitHub
parent
commit
7d669a71c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      installer/client/cli/fabric.py
  2. 57
      installer/client/cli/utils.py
  3. 2
      pyproject.toml

5
installer/client/cli/fabric.py

@ -158,7 +158,7 @@ def main():
print("No patterns found") print("No patterns found")
sys.exit() sys.exit()
if args.listmodels: if args.listmodels:
gptmodels, localmodels, claudemodels, googlemodels = standalone.fetch_available_models() gptmodels, localmodels, claudemodels, googlemodels, groqmodels = standalone.fetch_available_models()
print("GPT Models:") print("GPT Models:")
for model in gptmodels: for model in gptmodels:
print(model) print(model)
@ -171,6 +171,9 @@ def main():
print("\nGoogle Models:") print("\nGoogle Models:")
for model in googlemodels: for model in googlemodels:
print(model) print(model)
print("\nGroq Models")
for model in groqmodels:
print(model)
sys.exit() sys.exit()
if args.text is not None: if args.text is not None:
text = args.text text = args.text

57
installer/client/cli/utils.py

@ -1,6 +1,7 @@
import requests import requests
import os import os
from openai import OpenAI, APIConnectionError from openai import OpenAI, APIConnectionError
from groq import Groq
import asyncio import asyncio
import pyperclip import pyperclip
import sys import sys
@ -39,10 +40,16 @@ class Standalone:
args = type('Args', (), {})() args = type('Args', (), {})()
env_file = os.path.expanduser(env_file) env_file = os.path.expanduser(env_file)
self.client = None self.client = None
self.client_name = None
load_dotenv(env_file) load_dotenv(env_file)
if "OPENAI_API_KEY" in os.environ: if "OPENAI_API_KEY" in os.environ:
api_key = os.environ['OPENAI_API_KEY'] api_key = os.environ['OPENAI_API_KEY']
self.client = OpenAI(api_key=api_key) self.client = OpenAI(api_key=api_key)
self.client_name = "OPENAI"
elif "GROQ_API_KEY" in os.environ:
api_key = os.environ['GROQ_API_KEY']
self.client = Groq(api_key=api_key)
self.client_name = "GROQ"
self.local = False self.local = False
self.config_pattern_directory = config_directory self.config_pattern_directory = config_directory
self.pattern = pattern self.pattern = pattern
@ -53,14 +60,16 @@ class Standalone:
if not self.model: if not self.model:
self.model = 'gpt-4-turbo-preview' self.model = 'gpt-4-turbo-preview'
self.claude = False self.claude = False
sorted_gpt_models, ollamaList, claudeList, googleList = self.fetch_available_models() sorted_gpt_models, ollamaList, claudeList, googleList, groqList = self.fetch_available_models()
self.sorted_gpt_models = sorted_gpt_models self.sorted_gpt_models = sorted_gpt_models
self.ollamaList = ollamaList self.ollamaList = ollamaList
self.claudeList = claudeList self.claudeList = claudeList
self.googleList = googleList self.googleList = googleList
self.groqList = groqList
self.local = self.model in ollamaList self.local = self.model in ollamaList
self.claude = self.model in claudeList self.claude = self.model in claudeList
self.google = self.model in googleList self.google = self.model in googleList
self.groq = self.model in groqList
async def localChat(self, messages, host=''): async def localChat(self, messages, host=''):
from ollama import AsyncClient from ollama import AsyncClient
@ -403,6 +412,7 @@ class Standalone:
print(e) print(e)
def fetch_available_models(self): def fetch_available_models(self):
groqList = []
gptlist = [] gptlist = []
fullOllamaList = [] fullOllamaList = []
googleList = [] googleList = []
@ -414,14 +424,15 @@ class Standalone:
try: try:
if self.client: if self.client:
models = [model.id.strip() models = [model.id.strip() for model in self.client.models.list().data]
for model in self.client.models.list().data]
if "/" in models[0] or "\\" in models[0]: if "/" in models[0] or "\\" in models[0]:
gptlist = [item[item.rfind( gptlist = [item[item.rfind(
"/") + 1:] if "/" in item else item[item.rfind("\\") + 1:] for item in models] "/") + 1:] if "/" in item else item[item.rfind("\\") + 1:] for item in models]
else: elif self.client_name=="OPENAI":
gptlist = [item.strip() gptlist = [item.strip()
for item in models if item.startswith("gpt")] for item in models if item.startswith("gpt")]
elif self.client_name=="GROQ":
groqList = models
gptlist.sort() gptlist.sort()
except APIConnectionError as e: except APIConnectionError as e:
pass pass
@ -450,7 +461,7 @@ class Standalone:
except: except:
googleList = [] googleList = []
return gptlist, fullOllamaList, claudeList, googleList return gptlist, fullOllamaList, claudeList, googleList, groqList
def get_cli_input(self): def get_cli_input(self):
""" aided by ChatGPT; uses platform library """ aided by ChatGPT; uses platform library
@ -621,6 +632,33 @@ class Setup:
f.write(line) f.write(line)
f.write(sourceLine) f.write(sourceLine)
def groq_api_key(self, api_key):
""" Set the GROQ API key in the environment file.
Args:
api_key (str): The API key to be set.
Returns:
None
Raises:
OSError: If the environment file does not exist or cannot be accessed.
"""
api_key = api_key.strip()
if not os.path.exists(self.env_file) and api_key:
with open(self.env_file, "w") as f:
f.write(f"GROQ_API_KEY={api_key}\n")
print(f"GROQ API key set to {api_key}")
elif api_key:
# erase the line OPENAI_API_KEY=key and write the new key
with open(self.env_file, "r") as f:
lines = f.readlines()
with open(self.env_file, "w") as f:
for line in lines:
if "GROQ_API_KEY" not in line:
f.write(line)
f.write(f"GROQ_API_KEY={api_key}\n")
def api_key(self, api_key): def api_key(self, api_key):
""" Set the OpenAI API key in the environment file. """ Set the OpenAI API key in the environment file.
@ -647,7 +685,7 @@ class Setup:
if "OPENAI_API_KEY" not in line: if "OPENAI_API_KEY" not in line:
f.write(line) f.write(line)
f.write(f"OPENAI_API_KEY={api_key}\n") f.write(f"OPENAI_API_KEY={api_key}\n")
def claude_key(self, claude_key): def claude_key(self, claude_key):
""" Set the Claude API key in the environment file. """ Set the Claude API key in the environment file.
@ -732,8 +770,8 @@ class Setup:
model = model.strip() model = model.strip()
env = os.path.expanduser("~/.config/fabric/.env") env = os.path.expanduser("~/.config/fabric/.env")
standalone = Standalone(args=[], pattern="") standalone = Standalone(args=[], pattern="")
gpt, ollama, claude, google = standalone.fetch_available_models() gpt, ollama, claude, google, groq = standalone.fetch_available_models()
allmodels = gpt + ollama + claude + google allmodels = gpt + ollama + claude + google +groq
if model not in allmodels: if model not in allmodels:
print( print(
f"Error: {model} is not a valid model. Please run fabric --listmodels to see the available models.") f"Error: {model} is not a valid model. Please run fabric --listmodels to see the available models.")
@ -796,6 +834,9 @@ class Setup:
print("Please enter your Google API key. If you do not have one, or if you have already entered it, press enter.\n") print("Please enter your Google API key. If you do not have one, or if you have already entered it, press enter.\n")
googlekey = input() googlekey = input()
self.google_key(googlekey) self.google_key(googlekey)
print("Please enter your Groq API key. If you do not have one, or if you have already entered it, press enter.\n")
groqkey = input()
self.groq_api_key(groqkey)
print("Please enter your YouTube API key. If you do not have one, or if you have already entered it, press enter.\n") print("Please enter your YouTube API key. If you do not have one, or if you have already entered it, press enter.\n")
youtubekey = input() youtubekey = input()
self.youtube_key(youtubekey) self.youtube_key(youtubekey)

2
pyproject.toml

@ -43,6 +43,7 @@ flask-login = "^0.6.3"
flask-jwt-extended = "^4.6.0" flask-jwt-extended = "^4.6.0"
python-dotenv = "1.0.0" python-dotenv = "1.0.0"
openai = "^1.11.0" openai = "^1.11.0"
groq ="^0.8.0"
flask-socketio = "^5.3.6" flask-socketio = "^5.3.6"
flask-sock = "^0.7.0" flask-sock = "^0.7.0"
gunicorn = "^22.0.0" gunicorn = "^22.0.0"
@ -53,6 +54,7 @@ tqdm = "^4.66.3"
[tool.poetry.group.server.dependencies] [tool.poetry.group.server.dependencies]
requests = "^2.32.0" requests = "^2.32.0"
openai = "^1.12.0" openai = "^1.12.0"
groq ="^0.8.0"
flask = "^3.0.2" flask = "^3.0.2"
python-dotenv = "1.0.0" python-dotenv = "1.0.0"
jwt = "^1.3.1" jwt = "^1.3.1"

Loading…
Cancel
Save