From 6021f35ff11d0182faac6290015d8f7bef0d82b0 Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:21:27 +0000 Subject: [PATCH 1/5] feat: added new llm llm_providers Signed-off-by: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> --- .env.example | 24 +++++++++++++++++++++++- main.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index ab3da74..2015d34 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,31 @@ +# Current Azure OpenAI Config AZURE_OPENAI_API_KEY=YOURKEY AZURE_OPENAI_ENDPOINT=https://YOURENDPOINT.openai.azure.com AZURE_OPENAI_API_VERSION=2024-02-01 + +# Default Model Configuration MODEL=gpt-4o-mini EMBEDDING=text-embedding-3-small EMBEDDING_MODEL_MAX_TOKENS=8192 + +# GitHub Integration GITHUB_TOKEN=YOURTOKEN + +# Supabase Config SUPABASE_URL=https://YOURLINK.supabase.co -SUPABASE_KEY=your_supabase_key \ No newline at end of file +SUPABASE_KEY=your_supabase_key + +# New Environment Variables for Multi-Provider Support +LLM_PROVIDER=AzureOpenAI + +# OpenAI API +OPENAI_API_KEY=your_openai_api_key + +# Anthropic API +ANTHROPIC_API_KEY=your_anthropic_api_key + +# Google Generative AI +GOOGLE_API_KEY=your_google_api_key + +# Groq API +GROQ_API_KEY=your_groq_api_key diff --git a/main.py b/main.py index 2e6410d..3851cdc 100644 --- a/main.py +++ b/main.py @@ -30,12 +30,48 @@ def check_env_vars(): "SUPABASE_URL", "SUPABASE_KEY", ] + + # Add provider-specific checks + provider = os.getenv("LLM_PROVIDER", "") + if provider == "AzureOpenAI": + required_vars.extend(["AZURE_OPENAI_ENDPOINT", "AZURE_OPENAI_API_KEY", "AZURE_OPENAI_API_VERSION"]) + elif provider == "OpenAI": + required_vars.append("OPENAI_API_KEY") + elif provider == "Anthropic": + required_vars.append("ANTHROPIC_API_KEY") + elif provider == "Google": + required_vars.append("GOOGLE_API_KEY") + elif provider == "Groq": + required_vars.append("GROQ_API_KEY") + missing_vars = [var for var in required_vars if not os.environ.get(var)] if missing_vars: print(f"Missing environment variables: {', '.join(missing_vars)}. Please configure the env vars file properly.") return False return True +def initialize_llm_client(): + provider = os.getenv("LLM_PROVIDER", "AzureOpenAI") # Default to AzureOpenAI + + if provider == "AzureOpenAI": + from helpers.openai_helpers import setup_azure_openai + return setup_azure_openai() + elif provider == "OpenAI": + from openai import OpenAI + return OpenAI(api_key=os.getenv("OPENAI_API_KEY")) + elif provider == "Anthropic": + from anthropic import Anthropic + return Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY")) + elif provider == "Google": + from google.generativeai import GoogleAI + return GoogleAI(api_key=os.getenv("GOOGLE_API_KEY")) + elif provider == "Groq": + from groq.client import GroqClient + return GroqClient(api_key=os.getenv("GROQ_API_KEY")) + else: + raise ValueError(f"Unsupported LLM provider: {provider}") + + hdrs = [ Script(src="https://www.googletagmanager.com/gtag/js?id=G-Q22LCTCW8Y", aync=True), Script(""" @@ -202,7 +238,8 @@ async def get(fname:str, ext:str): # Initialize clients if check_env_vars(): - openai_client = setup_azure_openai() + logging.info("Initializing LLM client...") + openai_client = initialize_llm_client() instructor_client = setup_instructor(openai_client) if __name__ == "__main__": From f81f8dda2aa566e0dff45df184f0eaafeccb4cf1 Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:17:59 +0000 Subject: [PATCH 2/5] added some checks for the provider Signed-off-by: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 3851cdc..6974d33 100644 --- a/main.py +++ b/main.py @@ -22,17 +22,20 @@ def check_env_vars(): required_vars = [ - "AZURE_OPENAI_ENDPOINT", - "AZURE_OPENAI_API_KEY", - "AZURE_OPENAI_API_VERSION", + "LLM_PROVIDER", "MODEL", "GITHUB_TOKEN", "SUPABASE_URL", "SUPABASE_KEY", ] - # Add provider-specific checks + # Check if required environment variables are set provider = os.getenv("LLM_PROVIDER", "") + if not provider: + print("Error: LLM_PROVIDER is not specified. Please set LLM_PROVIDER in your environment variables.") + return False + + # Add provider-specific checks if provider == "AzureOpenAI": required_vars.extend(["AZURE_OPENAI_ENDPOINT", "AZURE_OPENAI_API_KEY", "AZURE_OPENAI_API_VERSION"]) elif provider == "OpenAI": @@ -43,6 +46,9 @@ def check_env_vars(): required_vars.append("GOOGLE_API_KEY") elif provider == "Groq": required_vars.append("GROQ_API_KEY") + else: + print(f"Error: Unsupported LLM_PROVIDER '{provider}'. Supported providers are: AzureOpenAI, OpenAI, Anthropic, Google, Groq.") + return False missing_vars = [var for var in required_vars if not os.environ.get(var)] if missing_vars: From 5c7c82e650af0aaf84604928531219f308613b2a Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:43:39 +0000 Subject: [PATCH 3/5] updated requirements but still unsure about the versions Signed-off-by: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> --- requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requirements.txt b/requirements.txt index 0810241..8a335f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -122,3 +122,7 @@ websockets==12.0 wheel==0.44.0 yarl==1.9.4 psycopg2-binary==2.9.10 +openai==1.40.2 +anthropic==0.6.2 +google-api-python-client==2.94.0 +groq==0.0.2 From 91822e0016ea4548127221b6d71e1cce85883dad Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:46:56 +0000 Subject: [PATCH 4/5] updated the package and the versions --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8a335f1..4a308a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -124,5 +124,5 @@ yarl==1.9.4 psycopg2-binary==2.9.10 openai==1.40.2 anthropic==0.6.2 -google-api-python-client==2.94.0 -groq==0.0.2 +google-generativeai==0.4.0 +groq-client==0.0.1 From 70a2f105a516ffd8526e67733c03a52040f16dfd Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:38:05 +0000 Subject: [PATCH 5/5] fixed version mismatching Signed-off-by: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4a308a3..4640cb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -123,6 +123,6 @@ wheel==0.44.0 yarl==1.9.4 psycopg2-binary==2.9.10 openai==1.40.2 -anthropic==0.6.2 +anthropic==0.42.0 google-generativeai==0.4.0 -groq-client==0.0.1 +groq