diff --git a/.env.example b/.env.example index 1036c89..1c73eaa 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,32 @@ +# 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 -SUPABASE_DB_URL=your_supabase_db_url # use transaction pooler, example: postgresql://postgres.pnewjmyiuazlkssdmhsc:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require \ No newline at end of file +SUPABASE_DB_URL=your_supabase_db_url # use transaction pooler, example: postgresql://postgres.pnewjmyiuazlkssdmhsc:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require + +# 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..6974d33 100644 --- a/main.py +++ b/main.py @@ -22,20 +22,62 @@ 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", ] + + # 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": + 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") + 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: 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 +244,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__": diff --git a/requirements.txt b/requirements.txt index 0810241..4640cb4 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.42.0 +google-generativeai==0.4.0 +groq